Skip to content

Commit 4a83564

Browse files
Gumichocopengin8Ahmad Saleem
authored andcommitted
[JSC] Fix %TypedArray%.prototype.includes to Align with ECMA-262 Part2
https://bugs.webkit.org/show_bug.cgi?id=304569 Reviewed by Yusuke Suzuki. This patch fixes `%TypedArray%.prototype.includes` by adding range check to ensure the `index` is less than the array length, aligning the behavior with ECMA-262[1]. [1]: https://tc39.es/ecma262/#sec-%typedarray%.prototype.includes * JSTests/stress/typedarray-resize-includes.js: (throw.new.Error): * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h: (JSC::genericTypedArrayViewProtoFuncIncludes): Canonical link: https://commits.webkit.org/304940@main
1 parent 981ede3 commit 4a83564

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

JSTests/stress/typedarray-resize-includes.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ function shouldBe(actual, expected) {
44
}
55
}
66

7+
{
8+
var arraybuffer = new ArrayBuffer(4, { maxByteLength: 20 });
9+
var int8array = new Int8Array(arraybuffer);
10+
var index = {
11+
valueOf() {
12+
arraybuffer.resize(0);
13+
return 10;
14+
},
15+
};
16+
shouldBe(int8array.length, 4);
17+
var result = int8array.includes(undefined, index);
18+
shouldBe(int8array.length, 0);
19+
shouldBe(result, false);
20+
}
21+
722
{
823
var arraybuffer = new ArrayBuffer(4, { maxByteLength: 20 });
924
var byteOffset = 1; // Uses byteOffset to make typed array out-of-bounds when shrinking size to zero.

JSTests/test262/expectations.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,6 @@ test/built-ins/Temporal/PlainTime/prototype/until/order-of-operations.js:
409409
test/built-ins/Temporal/getOwnPropertyNames.js:
410410
default: 'Test262Error: ZonedDateTime'
411411
strict mode: 'Test262Error: ZonedDateTime'
412-
test/built-ins/TypedArray/prototype/includes/index-compared-against-initial-length.js:
413-
default: 'Test262Error: Expected SameValue(«true», «false») to be true'
414-
strict mode: 'Test262Error: Expected SameValue(«true», «false») to be true'
415-
test/built-ins/TypedArray/prototype/includes/search-undefined-after-shrinking-buffer-index-is-oob.js:
416-
default: 'Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.)'
417-
strict mode: 'Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.)'
418412
test/built-ins/TypedArray/prototype/set/array-arg-value-conversion-resizes-array-buffer.js:
419413
default: 'Test262Error: Actual [shrink, shrink, shrink] and expected [shrink, shrink, shrink, grow, grow] should have the same contents. '
420414
strict mode: 'Test262Error: Actual [shrink, shrink, shrink] and expected [shrink, shrink, shrink, grow, grow] should have the same contents. '

Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ ALWAYS_INLINE EncodedJSValue genericTypedArrayViewProtoFuncIncludes(VM& vm, JSGl
465465
if (!targetOption) {
466466
// Even though our TypedArray's length is updated, we iterate up to `length`.
467467
// So, if `updatedLength` is smaller than `length`, we will see undefined after that.
468-
return JSValue::encode(jsBoolean(valueToFind.isUndefined() && length > updatedLength));
468+
return JSValue::encode(jsBoolean(index < length && updatedLength < length && valueToFind.isUndefined()));
469469
}
470470

471471
scope.assertNoExceptionExceptTermination();

0 commit comments

Comments
 (0)