-
Notifications
You must be signed in to change notification settings - Fork 14
Pre-Stage-3 spec review #49
Description
-
Use of
GetOptionsObjectfrom ECMA-402 is good but should go one step further: also borrowGetOption(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
ToStringcall, which I understand is intentional (see here). Instead of spelling these steps out repeatedly I propose thatGetOptionis altered to support different coercion behavior instead. -
Notably the above causes
Stringobjects 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). -
AllocateTypedArrayis 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).
-
ValidateUint8Arrayshould be used consistently,Uint8Array.fromBase64Into()andUint8Array.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. -
ValidateUint8ArrayandGetUint8ArrayBytesare not grouped into the Helpers section, for no apparent reason.