encoding
encoding copied to clipboard
Need to define global used to create the ArrayBuffer and Uint8Array in TextEncoder's encode()
Firefox and Chrome seem to use the current global. Safari seems to use the relevant global. Edge doesn't implement this API.
For what it's worth, the TextEncoderStream test expects the Uint8Array to be created in the realm of the constructor: https://github.com/GoogleChromeLabs/text-encode-transform-prollyfill/blob/master/tests/realms.html#L190
For the algorithm for TextEncoderStream I've just copied the equivalent text from TextEncoder.
For the algorithm for TextEncoderStream I've just copied the equivalent text from TextEncoder.
Can you link to that, please?
It's not landed yet: https://github.com/whatwg/encoding/pull/149/files#diff-ad08a062fe2c5f5084f74638410187daR1664
The TextEncoder step I copied it from: https://encoding.spec.whatwg.org/#ref-for-finished%E2%91%A1
OK, that wording assumes there is a current Realm. It's not clear to me whether that's true in the streams case, esp. because the algorithm in question is being called async (unlike encode, which is an ES Function and so clearly has a current Realm).
This may be an unintended side-effect of supplying the CreateTransformStream() operation for specs to use rather than expecting them to create a transformer object and pass it to the TransformStream constructor.
I'd like the realm used to be the realm of the constructor, because that's what the polyfill does, and I've convinced myself that behaviour is correct. Can you propose some wording that would make it unambiguous?
I'm not sure what the state of the art is right now for wording for this sort of thing in a non-ecmaspeak context when creating an ES object. @domenic do you know where things stand with that?
If I had to make up something, I would just say to create an ArrayBuffer using the constructor from global X and then create a Uint8Array using the constructor from global X or something, since those constructors have no side-effects, this is more or less ok.
I think we've been even a bit less precise, saying "create an ArrayBuffer in realm X". The hope is to eventually formalize object creation in https://github.com/heycam/webidl/issues/135. (However that thread says "relevant", which I have an incoming comment on...)