-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
refactor: use primordials in extensions/web #11273
Conversation
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
08_text_encoding.js - line 389 TypedArrayPrototypeSlice
.slice() if you forgot :) |
Thanks, fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update Uint8Array.from
on line 65 of base64.js
@@ -373,14 +388,16 @@ | |||
if (BOMEncoding === "UTF-8") start = 3; | |||
else start = 2; | |||
} | |||
return new TextDecoder(encoding).decode(bytes.slice(start)); | |||
return new TextDecoder(encoding).decode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use TextEncoderPrototypeDecode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto in text_encoding:
deno/extensions/web/08_text_encoding.js
Line 391 in 8bab7d4
return new TextDecoder(encoding).decode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextEncoderPrototypeDecode
does not exist. Primordials are only for JS builtins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextEncoderPrototypeDecode
does not exist. Primordials are only for JS builtins
It's prone to prototype manipulation, and that is the purpose of the existance of the primordials in general. Or are they more narrow in their scope/goal?
I see these as things that should be created, because, although I haven't checked the relevant spec for this algorithm, I doubt it specifies performing an ECMAScript Get
operation on a TextDecoder
instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Primordials are limited to JS builtins not external APIs (analogous to its name). Node.js doesn't do TextEncoderPrototypeDecode
either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is so, then all of my comments here besides the ones about DataView and TypedArray can be discarded/ignored.
Although, why should Deno aim to only do as little as Node.js had?
These property accesses should directly use prototype getters: ArrayBufferPrototypeGetByteLength, DataViewPrototypeGetByteLength, TypedArrayPrototypeGetLength. I'm iffy about this line because it accesses a dynamic prototype get accessor, I'd suggest maybe doing something more like let getByteOffset;
if (value instanceof DataView) {
length = DataViewPrototypeGetByteLength(value);
getByteOffset = DataViewPrototypeGetByteOffset;
} else {
length = TypedArrayPrototypeGetLength(value)
getByteOffset = TypedArrayPrototypeGetByteOffset;
}
return new (value.constructor)(
clonedBuffer,
getByteOffset(value),
length,
); also iffy about line 56's buffer access. You'll need an extra branch to get the correct get accessor for the buffer. This u8 array construction requires an extra branch and usage of primordial accessors. |
Apologies for being as pedantic as I already was, but lastly, the location file needs to use |
@crimsoncodes0 get accessors of internal primordial objects (eg |
Can you explain what you mean by that, and how it pertains to the code in question?
in particular? If not, can you specify which part of my comment you were replying to? |
@crimsoncodes0 The code you are referring to ( a. value is passed from userland i.e. b. value is created internally i.e. |
In situation "a," we obviously need to have the primordials in use to ensure correctness. As for situation "b"... I don't think I understand the primordial code; how does one have both, a prototype copy, yet also retain correct semantics for comparing the user-provided object against the primordial prototype object via the |
@crimsoncodes0 You are correct we will need primordials for these too eventually. These primordials do not yet exist however, so there is nothing to change for this PR. |
From my read of the code, a deep primordial copy is made of both, ArrayBuffer, and TypedArray, so those changes are very possible already, unless I've misunderstood the setup there? |
Ref #11224