Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upInconsistency in %ArrayIteratorPrototype%.next for TypedArrays #713
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
caitp
Oct 24, 2016
Contributor
fwiw: the behaviour that was in v8 before the CL in which Benedikt found this is basically what people would end up with if they polyfilled %ArrayIteratorPrototype%.next, and I believe some discussion in the jslang channel on irc.mozilla.org suggested that SpiderMonkey behaves the same way, so maybe there's some weight behind fixing this inconsistency.
|
fwiw: the behaviour that was in v8 before the CL in which Benedikt found this is basically what people would end up with if they polyfilled %ArrayIteratorPrototype%.next, and I believe some discussion in the jslang channel on irc.mozilla.org suggested that SpiderMonkey behaves the same way, so maybe there's some weight behind fixing this inconsistency. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bmeurer
Oct 24, 2016
I agree with @caitp, it makes sense to match the polyfill(able) behavior. So +1 for a spec fix.
bmeurer
commented
Oct 24, 2016
|
I agree with @caitp, it makes sense to match the polyfill(able) behavior. So +1 for a spec fix. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Oct 24, 2016
Member
In general, the iterative methods of %TypedArrayPrototype% are specified to throw when applied to a typed array instances whose buffer is detached. This throw occurs, because of the detached check in IntegerIndexedElementGet and IntegerIndexedElementSet combined with that fact that the iterative methods directly access [[ArrayLength]] rather than self invoking their length method.
%ArrayIteratorPrototype%.next, as current specified, is consistent with the behavior of the iterative methods. Changing the specification as suggest above would create a new inconsistency.
|
In general, the iterative methods of %TypedArrayPrototype% are specified to throw when applied to a typed array instances whose buffer is detached. This throw occurs, because of the detached check in IntegerIndexedElementGet and IntegerIndexedElementSet combined with that fact that the iterative methods directly access [[ArrayLength]] rather than self invoking their %ArrayIteratorPrototype%.next, as current specified, is consistent with the behavior of the iterative methods. Changing the specification as suggest above would create a new inconsistency. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
caitp
Oct 24, 2016
Contributor
I think that soec-side inconsistency is less weird for users than the current one
|
I think that soec-side inconsistency is less weird for users than the current one |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
s/soec/spec (mobile github, sorry!) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Oct 24, 2016
Member
Also, there was a reason why we explicitly make the %ArrayPrototype% methods use [[ArrayLength]] rather than self invoking length. I wish I could remember the exact reasoning, maybe it's somewhere in the meeting notes. But, I think it was a legacy compat issue and/or concerns about fact that length property can be redefined.
|
Also, there was a reason why we explicitly make the %ArrayPrototype% methods use [[ArrayLength]] rather than self invoking |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
caitp
Oct 24, 2016
Contributor
it's not clear why "length" is configurable, but you have a point. I'm still in favor of treating length as 0 in the detached case, though.
|
it's not clear why "length" is configurable, but you have a point. I'm still in favor of treating |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Oct 24, 2016
Member
length is configurable because (unlike regular arrays) it is just an accessor property on %TypedArrayPrototype%. Even if it was non-configurable, it could still be over-ridden at the instance level.
More generally, this bug and the meeting note it references is probably relevant to this thread.
|
More generally, this bug and the meeting note it references is probably relevant to this thread. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
caitp
Oct 24, 2016
Contributor
I'm not arguing with any of that, but I am saying it's unexpected for
var array = new Uint8Array([1, 2, 3]);
DetachArrayBuffer(array.buffer);
[...A.p.keys.call(array)] // [0, 1, 2]
array.length // 0
[...A.p.entries.call(array)] // TypeErrorThis is just weird, IMO
// edited for clarity
|
I'm not arguing with any of that, but I am saying it's unexpected for var array = new Uint8Array([1, 2, 3]);
DetachArrayBuffer(array.buffer);
[...A.p.keys.call(array)] // [0, 1, 2]
array.length // 0
[...A.p.entries.call(array)] // TypeErrorThis is just weird, IMO // edited for clarity |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Oct 24, 2016
Member
@caitp I agree the keys example is weird.
How about throwing in 8.a if buffer is detatched? Then keys and values would behave the same.
|
@caitp I agree the How about throwing in 8.a if buffer is detatched? Then |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
caitp
Oct 24, 2016
Contributor
I'd vouch for either of the following:
8. If a has a [[TypedArrayName]] internal slot, then
a. Perform ? ValidateTypedArray(a).
b. Let len be a.[[ArrayLength]].
9. Else,
a. Let len be ? ToLength(? Get(a, "length")).
OR
8. If a has a [[TypedArrayName]] internal slot, then
a. Let buffer be a.[[ViewedArrayBuffer]]
b. If IsDetachedBuffer(buffer), let len be 0.
c. Else, let len be a.[[ArrayLength]].
9. Else,
a. Let len be ? ToLength(? Get(a, "length")).
The latter is what's been implemented for a long time, but it's possible that this isn't observable anywhere so it probably wouldn't break anything to change it. I'm okay with either one.
|
I'd vouch for either of the following:
OR
The latter is what's been implemented for a long time, but it's possible that this isn't observable anywhere so it probably wouldn't break anything to change it. I'm okay with either one. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Oct 25, 2016
Member
Well, I vote for a. ValidateTypedArray does some tests that are redundant in this situation, but I assume that implementations will be smart enough to skip those.
Whether or not this is a safe change: what does Safari and Edge do for this case. If any of them follow the current spec. this won't be a change to web interoperable behavior.
|
Well, I vote for a. ValidateTypedArray does some tests that are redundant in this situation, but I assume that implementations will be smart enough to skip those. Whether or not this is a safe change: what does Safari and Edge do for this case. If any of them follow the current spec. this won't be a change to web interoperable behavior. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
caitp
Oct 25, 2016
Contributor
Whether or not this is a safe change: what does Safari and Edge do for this case. If any of them follow the current spec. this won't be a change to web interoperable behavior.
I doubt it's a web breaking change whether they follow the current spec or not, it seems incredibly unlikely that anyone is actually reaching this branch of spec text in code on the web today
I doubt it's a web breaking change whether they follow the current spec or not, it seems incredibly unlikely that anyone is actually reaching this branch of spec text in code on the web today |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
leobalter
Oct 25, 2016
Member
Well, I vote for a. ValidateTypedArray does some tests that are redundant in this situation, but I assume that implementations will be smart enough to skip those.
I'm +1 to it.
I'm also not against the other option if proven necessary.
I'm +1 to it. I'm also not against the other option if proven necessary. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
+1 on ValidateTypedArray. I also highly doubt this will break anyone. |
added a commit
to littledan/ecma262
that referenced
this issue
Oct 28, 2016
This was referenced Oct 28, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Oct 28, 2016
Member
OK, ValidateTypedArray sounds good to me. I wrote a spec change and a test262 test (which fails on current V8). Thoughts?
|
OK, ValidateTypedArray sounds good to me. I wrote a spec change and a test262 test (which fails on current V8). Thoughts? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Works for me. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jswalden
Nov 2, 2016
Contributor
Throwing for during-iteration detaching seems fine to me. I'd just write out the single step of checking for detachment rather than reuse the ill-fitting ValidateTypedArray (and commented to that effect on the PR), but semantically they're the same.
|
Throwing for during-iteration detaching seems fine to me. I'd just write out the single step of checking for detachment rather than reuse the ill-fitting |
added a commit
to littledan/ecma262
that referenced
this issue
Nov 2, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
This pull request gained consensus at the November 2016 TC39 meeting. |
littledan commentedOct 18, 2016
•
edited
In %ArrayIteratorPrototype%.next, step 8.a., if the Array being iterated over is a TypedArray, the length used is the TypedArray's [[ArrayLength]]. However, if the TypedArray's ArrayBuffer is detached, then the
lengthaccessor would've returned zero (see spec). For consistency, should we do the same here?One fix would be to make step 8.a check for a detached ArrayBuffer and use 0 for the length in that case. I'd like this one, as it leaves in the special allowance to make TypedArrays a bit more implementation-friendly by using the underlying length. Another possibility would be to always use the
lengthaccessor.Thanks to @caitp and @bmeurer for raising this issue to me and discussing possible fixes.