-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
TypedArray exotic objects need [[PreventExtensions]] #3385
Comments
Good catch. I agree with your suggested solution, that TAs need a [[PreventExtensions]] override that returns false, similar to how you can't freeze TAs today. |
Only those backed by resizable buffers, or all TAs? If the former, do the become non-extensible when the backing buffer is detached? |
It's technically only needed for those backed by resizable buffers, since those backed by fixed-length TAs never get new properties in practice even when
I don't think so, by analogy with TAs backed by fixed-length buffers returning true for |
Thinking through this some more, I think the most "feels correct" solution is that the [[PreventExtensions]] override needs to change the value of a TypedArray's [[ArrayLength]] from I think this is implementable without performance penalty, but that's an open question. |
Sorry, I meant for those which had let ta = new Uint8Array(new ArrayBuffer(8, { maxByteLength: 16 }))
ta.buffer.transfer();
Object.preventExtensions(ta);
Object.isExtensible(ta); // ?? |
Going by my current thinking in #3385 (comment), I think your example should return |
Ah crap, I'm wrong about the performance penalty here. This is doable for TAs backed by growable SABs, but resizable ABs pose a problem: ab = new ArrayBuffer(2, { maxByteLength: 4 });
ta = new Int8Array(ab, 0, 2);
ta.length; // 2
Object.seal(ta);
ab.resize(1);
ta.length; // 0 (because it's now out of bounds);
ab.resize(4);
// If this wasn't sealed, the following should be 2 again.
// But for sealed TAs, once you go OOB you must never go back.
// Tracking this state is expensive.
ta.length; Edit: It's still doable, but the implementation cost of "OOBs are one-way for sealed resizable AB-backed TAs" probably doesn't pay for the use case. |
TypedArray exotic objects need a [[PreventExtensions]] internal method to handle resizable TypedArrays:
CC @syg
The text was updated successfully, but these errors were encountered: