tc39 / proposal-arraybuffer-base64

TC39 proposal for Uint8Array<->base64/hex
https://tc39.github.io/proposal-arraybuffer-base64/
MIT License
248 stars 8 forks source link

Is `GetOptionsObject` really required? #30

Closed zloirock closed 7 months ago

zloirock commented 10 months ago

Sure, it's an unobservable operation and can be avoided in implementations, but it makes the spec more difficult and can be replaced with 1 undefined check in one method and 2 in another.

bakkot commented 10 months ago

It's a method used in a number of other specs, including 402 and Temporal. It could be removed throughout, but I'm prioritizing consistency for the moment.

Incidentally if you're implementing this you may want to hold off. It's only stage 2 and the API is likely to change before stage 3.

zloirock commented 10 months ago

Incidentally if you're implementing this you may want to hold off. It's only stage 2 and the API is likely to change before stage 3.

Yes, I'm implementing it and understand that it's on stage 2 and most likely will be changed, but it's a polyfill for familiarization and experiments with this future API, not for production. Now early stage APIs are significantly fenced off from stable in core-js and they will be fenced off even more in the future to prevent possible errors associated with this.

ljharb commented 10 months ago

Consistency and avoiding future behavior drift is much more important than spec complexity imo.

zloirock commented 10 months ago

Consistency

So, it's inconsistent with current ES spec cases - for example, Error options (with cause) case.

ljharb commented 10 months ago

cause is a uniquely special case that is intentionally different from everything else, because you can have a nullish cause of an exception.

zloirock commented 10 months ago

It is about options argument case and definitely not about cause.

Anyway, I don't care - GetOptionsObject looks like a good internal abstraction, but it seems similar spec cases should be refactored for consistency -)

ljharb commented 10 months ago

I'm sure they will once the AO first lands in 262, but it's not there yet.

bakkot commented 10 months ago

it seems similar spec cases should be refactored for consistency

Yeah, things are in a kind of strange state right now because 402, Temporal, and lots of other proposals use options bags, and have mostly copy-pasted that AO around, but the only thing in 262 which uses an options bag is Error, and Error is weird for other reasons. The trouble with Error, if I recall correctly, is that some engines have a non-standard extension which allows specifying a line number or file name or something in the same position as the spec now uses for the options argument, so it would probably not be web-compatible to throw an error when the user passes a number or string in that position. So Error needs to silently ignore non-object values passed in that position.

But new things (e.g. this API) don't have that legacy constraint, so they can throw if you pass a non-object value instead of silently ignoring it, and so all new things use (or at least should use) GetOptionsObject.

bakkot commented 7 months ago

This can be further refined when landing in 262, but I think we're going to want something like this across many proposals. Closing as answered.