Skip to content

Commit 08ed246

Browse files
authored
Make TypedArray.prototype.includes conform to spec (#1068)
In the case of typed arrays backed by resizable arraybuffers, searching for `undefined` matches if the search index is in bounds with respect to the typed array's original length.
1 parent d6d0a6d commit 08ed246

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

quickjs.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54814,7 +54814,6 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val,
5481454814
double d;
5481554815
float f;
5481654816
uint16_t hf;
54817-
bool oob;
5481854817

5481954818
p = get_typed_array(ctx, this_val);
5482054819
if (!p)
@@ -54826,7 +54825,6 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val,
5482654825
if (len == 0)
5482754826
goto done;
5482854827

54829-
oob = false;
5483054828
if (special == special_lastIndexOf) {
5483154829
k = len - 1;
5483254830
if (argc > 1) {
@@ -54860,7 +54858,6 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val,
5486054858
k = 0;
5486154859
} else if (k > len) {
5486254860
k = len;
54863-
oob = true;
5486454861
}
5486554862
}
5486654863
stop = len;
@@ -54871,8 +54868,10 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val,
5487154868
exception is raised) */
5487254869
if (typed_array_is_oob(p) || len > p->u.array.count) {
5487354870
/* "includes" scans all the properties, so "undefined" can match */
54874-
if (special == special_includes && JS_IsUndefined(argv[0]) && len > 0)
54875-
res = oob ? -1 : 0;
54871+
if (special == special_includes)
54872+
if (JS_IsUndefined(argv[0]))
54873+
if (k < typed_array_get_length(ctx, p))
54874+
res = 0;
5487654875
goto done;
5487754876
}
5487854877

test262_errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js
3232
test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js:9: strict mode: Test262Error: Unicode property escapes with v flag Expected SameValue(«-1», «0») to be true
3333
test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-u-flag.js:9: Test262Error: Unicode property escapes with v flag Expected SameValue(«-1», «0») to be true
3434
test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-u-flag.js:9: strict mode: Test262Error: Unicode property escapes with v flag Expected SameValue(«-1», «0») to be true
35-
test262/test/built-ins/TypedArray/prototype/includes/search-undefined-after-shrinking-buffer-index-is-oob.js:23: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.)
36-
test262/test/built-ins/TypedArray/prototype/includes/search-undefined-after-shrinking-buffer-index-is-oob.js:23: strict mode: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.)
3735
test262/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js:35: Test262Error: value should not be coerced Expected SameValue(«22», «0») to be true
3836
test262/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js:35: strict mode: Test262Error: value should not be coerced Expected SameValue(«22», «0») to be true
3937
test262/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js:35: Test262Error: value should not be coerced Expected SameValue(«32», «0») to be true

0 commit comments

Comments
 (0)