Skip to content

Commit 6117e70

Browse files
tetsuharuohzekisosukesuzuki
authored andcommitted
[JSC] Fix test262 failure: test/staging/sm/TypedArray/iterator-next-with-detached.js
https://bugs.webkit.org/show_bug.cgi?id=310802 Reviewed by Sosuke Suzuki. If source is detached TypedArray and the iterator has been completed, `%ArrayIteratorPrototype%.next()` should return `{ done: true }` rather than throwing `TypeError` with describes the source TypedArray is detached. This complies _step 5_ of _23.1.5.2.1 %ArrayIteratorPrototype%.next()_ in the spec. https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js: Canonical link: https://commits.webkit.org/310292@main
1 parent 4c59b7a commit 6117e70

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

‎JSTests/test262/expectations.yaml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,6 @@ test/staging/sm/String/string-upper-lower-mapping.js:
935935
test/staging/sm/TypedArray/constructor-buffer-sequence.js:
936936
default: 'Test262Error: Expected a ExpectedError but got a Error'
937937
strict mode: 'Test262Error: Expected a ExpectedError but got a Error'
938-
test/staging/sm/TypedArray/iterator-next-with-detached.js:
939-
default: 'TypeError: Underlying ArrayBuffer has been detached from the view or out-of-bounds'
940-
strict mode: 'TypeError: Underlying ArrayBuffer has been detached from the view or out-of-bounds'
941938
test/staging/sm/TypedArray/slice-memcpy.js:
942939
default: 'Test262Error: Actual [1, 2, 1, 2, 3, 4] and expected [1, 2, 1, 2, 1, 2] should have the same contents. '
943940
strict mode: 'Test262Error: Actual [1, 2, 1, 2, 3, 4] and expected [1, 2, 1, 2, 1, 2] should have the same contents. '

‎Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,40 @@ function next()
3131
if (!@isArrayIterator(this))
3232
@throwTypeError("%ArrayIteratorPrototype%.next requires that |this| be an Array Iterator instance");
3333

34+
var index = @getArrayIteratorInternalField(this, @arrayIteratorFieldIndex);
35+
if (index === -1)
36+
return { value: @undefined, done: true };
37+
3438
var array = @getArrayIteratorInternalField(this, @arrayIteratorFieldIteratedObject);
3539
if (@isTypedArrayView(array) && @isDetached(array))
3640
@throwTypeError("Underlying ArrayBuffer has been detached from the view or out-of-bounds");
3741

3842
var kind = @getArrayIteratorInternalField(this, @arrayIteratorFieldKind);
39-
return @arrayIteratorNextHelper.@call(this, array, kind);
43+
return @arrayIteratorNextHelper.@call(this, array, kind, index);
4044
}
4145

4246
// FIXME: We have to have this because we can't implement this all as one function and meet our inlining heuristics.
4347
// Collectively, next and this have ~130 bytes of bytecodes but our limit is 120.
4448
@linkTimeConstant
45-
function arrayIteratorNextHelper(array, kind)
49+
function arrayIteratorNextHelper(array, kind, index)
4650
{
4751
"use strict";
4852
var done = true;
4953
var value;
5054

51-
var index = @getArrayIteratorInternalField(this, @arrayIteratorFieldIndex);
52-
if (index !== -1) {
53-
var length = @isTypedArrayView(array) ? @typedArrayLength(array) : @toLength(array.length);
54-
if (index < length) {
55-
@putArrayIteratorInternalField(this, @arrayIteratorFieldIndex, index + 1);
56-
done = false;
57-
if (kind === @iterationKindKey)
58-
value = index;
59-
else {
60-
value = array[index];
61-
if (kind === @iterationKindEntries)
62-
value = [index, value];
63-
}
64-
} else
65-
@putArrayIteratorInternalField(this, @arrayIteratorFieldIndex, -1);
66-
}
55+
var length = @isTypedArrayView(array) ? @typedArrayLength(array) : @toLength(array.length);
56+
if (index < length) {
57+
@putArrayIteratorInternalField(this, @arrayIteratorFieldIndex, index + 1);
58+
done = false;
59+
if (kind === @iterationKindKey)
60+
value = index;
61+
else {
62+
value = array[index];
63+
if (kind === @iterationKindEntries)
64+
value = [index, value];
65+
}
66+
} else
67+
@putArrayIteratorInternalField(this, @arrayIteratorFieldIndex, -1);
6768

6869
return { value, done };
6970
}

0 commit comments

Comments
 (0)