-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a static decode and encode method to TextEncoder
and TextDecoder
#267
Comments
What about encodeInto()?
Why would that be confusing? |
Added - forgot it existed.
Just checked spec - wouldn't just be confusing but also against webidl spec: "The identifier of a static operation also must not be the same as the identifier of a regular operation defined on the same interface." - https://heycam.github.io/webidl/#idl-operations As to why it would be confusing: "just call TextDecoder.decode" would have two meanings now. Also what would for example the MDN link be? https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode is already taken for the prototype method. |
We can fix Web IDL. As for MDN's problem, they've had a big issue with bad documentation for prototype methods for a long time. They need to fix it. |
It's unclear what the benefit of the proposed change is. It doesn't save significant typing (just Given a time machine to redesign the API now that streams are a thing, this makes more sense for non-streaming encodes/decodes, but is it worth adding to the platform? |
If we add API surface that doesn't work in old browsers, I'd like to know if users of the potential API surface care about non-UTF-8 encodings. If not, I'd prefer adding new API surface to JavaScript
|
whatwg/webidl#1098 should technically unblock this. Are any browser vendors objected to this? If not, I'd like to start work on this. |
@hsivonen How so? In Deno we have an optimized path in our WebIDL bindings for this specific API that bypasses the slow USVString conversion completely. This should be possible in other implementations too. During encode you can convert the first argument to a DOMString (which is fast), and then just perform a lenient UTF-8 encoding on that string, which will already perform lone surrogate conversion. https://github.com/denoland/deno/blob/main/ext/web/08_text_encoding.js#L166-L175 |
Gecko doesn't actually use |
Mh, that seems very weird to me. I very much doubt that WebIDL inherently needs to be a slowdown here. Currently the overhead likely stems from most engines slowing down when calling from JS to native code. This is a performance issue that can be fixed. In V8 based runtimes, The only WebIDL conversion taking place here is the TLDR: I don't think spec decisions should be driven by current performance issues in engines, as I don't think that there are any technical reasons for why Please correct me if I missed something obvious here. |
The large majority of users of
TextEncoder
andTextDecoder
do not make use of streaming capabilities. Instead they just need to decode a single chunk, or encode a single chunk. We should consider adding a static utility method toTextEncoder
/TextDecoder
to cater to this use case.I propose the following API be added:
The exact name of the method should be something different though - the static method and prototype method would name clash in this example which is confusing.
Internally this would behave exactly like a single use non streaming encoder.
The text was updated successfully, but these errors were encountered: