Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.
This repository was archived by the owner on Oct 28, 2025. It is now read-only.

Pre-Stage-3 spec review #49

@linusg

Description

@linusg
  • Use of GetOptionsObject from ECMA-402 is good but should go one step further: also borrow GetOption (like Temporal already does), which handles type/value checking and default values. This is unnecessarily verbose given we have an established abstraction:

    - 4. Let alphabet be ? Get(opts, "alphabet").
    - 5. If alphabet is undefined, set alphabet to "base64".
    - 6. If alphabet is not a String, throw a TypeError exception.
    - 7. If alphabet is neither "base64" nor "base64url", throw a TypeError exception.
    + 4. Let alphabet be ? GetOption(opts, "alphabet", "string", « "base64", "base64url" », "base64").

    The main difference here is the lack of a ToString call, which I understand is intentional (see here). Instead of spelling these steps out repeatedly I propose that GetOption is altered to support different coercion behavior instead.

  • Notably the above causes String objects to be rejected as option values. Of course no one will use { alphabet: new String("base64") }, but if provided from elsewhere this might be problematic. If intentional I'd like to see it included in how-we-work (this PR).

  • AllocateTypedArray is being used incorrectly twice, the default prototype must be passed as a string:

    - 12. Let ta be ? AllocateTypedArray("Uint8Array", %Uint8Array%, %Uint8Array.prototype%, resultLength).
    + 12. Let ta be ? AllocateTypedArray("Uint8Array", %Uint8Array%, "%Uint8Array.prototype%", resultLength).
  • ValidateUint8Array should be used consistently, Uint8Array.fromBase64Into() and Uint8Array.fromHexInto() currently perform the same steps manually:

    - 2. Perform ? RequireInternalSlot(into, [[TypedArrayName]]).
    - 3. If into.[[TypedArrayName]] is not "Uint8Array", throw a TypeError exception.
    + 2. Perform ? ValidateUint8Array(into).

    Arguably the AO could also be dropped, replacing two lines with one doesn't seem like a huge win.

  • ValidateUint8Array and GetUint8ArrayBytes are not grouped into the Helpers section, for no apparent reason.

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