Skip to content

Commit dbed7be

Browse files
authored
Handle TypedArray detach during iteration (#201)
Per spec: detaching the TA mid-iteration is allowed and should not not throw an exception. In the case of TypedArray.prototype.set, because iteration over the source array is observable, we cannot bail out early when the TA is first detached.
1 parent f7f1906 commit dbed7be

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

quickjs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48337,8 +48337,14 @@ static JSValue js_typed_array_set_internal(JSContext *ctx,
4833748337
val = JS_GetPropertyUint32(ctx, src_obj, i);
4833848338
if (JS_IsException(val))
4833948339
goto fail;
48340-
if (JS_SetPropertyUint32(ctx, dst, offset + i, val) < 0)
48340+
// Per spec: detaching the TA mid-iteration is allowed and should
48341+
// not throw an exception. Because iteration over the source array is
48342+
// observable, we cannot bail out early when the TA is first detached.
48343+
if (typed_array_is_detached(ctx, p)) {
48344+
JS_FreeValue(ctx, val);
48345+
} else if (JS_SetPropertyUint32(ctx, dst, offset + i, val) < 0) {
4834148346
goto fail;
48347+
}
4834248348
}
4834348349
done:
4834448350
JS_FreeValue(ctx, src_obj);

test262_errors.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-brok
33
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js:39: strict mode: TypeError: $DONE() not called
44
test262/test/built-ins/RegExp/lookahead-quantifier-match-groups.js:27: Test262Error: Expected [a, abc] and [a, undefined] to have the same contents. ? quantifier
55
test262/test/built-ins/RegExp/lookahead-quantifier-match-groups.js:27: strict mode: Test262Error: Expected [a, abc] and [a, undefined] to have the same contents. ? quantifier
6-
test262/test/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js:30: TypeError: out-of-bound numeric index (Testing with Float64Array.)
7-
test262/test/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js:30: strict mode: TypeError: out-of-bound numeric index (Testing with Float64Array.)
86
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
97
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: strict mode: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
108
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: Test262Error: (Testing with BigInt64Array.)

0 commit comments

Comments
 (0)