Skip to content

Symbol.for throws SyntaxError when called with no argument #1706

Description

@d01c2

Build environment: macOS 26.5.2

Moddable SDK version:

  • Installed via jsvu, so there is no SDK source tree / git describe.
  • Engine reports: XS 17.9.3, slot 32 bytes, ID 4 bytes

Target device: desktop (host xs)

Description
The first step of Symbol.for is ToString(key). With no argument, key is undefined and ToString yields "undefined", so the registry is consulted for that key and a Symbol with description "undefined" is returned. XS rejects the call instead.

Steps to Reproduce

$ xst -e 'print(String(Symbol.for()));'
SyntaxError: no key (in Symbol.for)

Expected behavior
Symbol(undefined)

For comparison, V8 (15.6.20):

$ v8 -e 'print(String(Symbol.for()));'
Symbol(undefined)

Other information
Symbol.for has no step that distinguishes a missing argument from an explicit undefined, and nothing before ToString can raise a SyntaxError. JavaScriptCore, SpiderMonkey, GraalJS and QuickJS-ng all return Symbol(undefined), and all of them register it under the key "undefined", so Symbol.keyFor(Symbol.for()) is "undefined" and Symbol.for() === Symbol.for("undefined").

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions