Skip to content

Commit 3150964

Browse files
authored
Implement TypedArray.prototype.with (#200)
1 parent 83dfc63 commit 3150964

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

quickjs.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48401,6 +48401,43 @@ static JSValue js_typed_array_at(JSContext *ctx, JSValue this_val,
4840148401
return JS_UNDEFINED;
4840248402
}
4840348403

48404+
static JSValue js_typed_array_with(JSContext *ctx, JSValue this_val,
48405+
int argc, JSValue *argv)
48406+
{
48407+
JSValue arr, val, ret;
48408+
JSObject *p;
48409+
int64_t idx, len;
48410+
48411+
p = get_typed_array(ctx, this_val, /*is_dataview*/0);
48412+
if (!p)
48413+
return JS_EXCEPTION;
48414+
48415+
if (JS_ToInt64Sat(ctx, &idx, argv[0]))
48416+
return JS_EXCEPTION;
48417+
48418+
len = p->u.array.count;
48419+
if (idx < 0)
48420+
idx = len + idx;
48421+
if (idx < 0 || idx >= len)
48422+
return JS_ThrowRangeError(ctx, "invalid array index");
48423+
48424+
val = JS_ToPrimitive(ctx, argv[1], HINT_NUMBER);
48425+
if (JS_IsException(val))
48426+
return JS_EXCEPTION;
48427+
48428+
arr = js_typed_array_constructor_ta(ctx, JS_UNDEFINED, this_val,
48429+
p->class_id);
48430+
if (JS_IsException(arr)) {
48431+
JS_FreeValue(ctx, val);
48432+
return JS_EXCEPTION;
48433+
}
48434+
if (JS_SetPropertyInt64(ctx, arr, idx, val) < 0) {
48435+
JS_FreeValue(ctx, arr);
48436+
return JS_EXCEPTION;
48437+
}
48438+
return arr;
48439+
}
48440+
4840448441
static JSValue js_typed_array_set(JSContext *ctx,
4840548442
JSValue this_val,
4840648443
int argc, JSValue *argv)
@@ -49589,6 +49626,7 @@ static const JSCFunctionListEntry js_typed_array_base_funcs[] = {
4958949626
static const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {
4959049627
JS_CGETSET_DEF("length", js_typed_array_get_length, NULL ),
4959149628
JS_CFUNC_DEF("at", 1, js_typed_array_at ),
49629+
JS_CFUNC_DEF("with", 2, js_typed_array_with ),
4959249630
JS_CGETSET_MAGIC_DEF("buffer", js_typed_array_get_buffer, NULL, 0 ),
4959349631
JS_CGETSET_MAGIC_DEF("byteLength", js_typed_array_get_byteLength, NULL, 0 ),
4959449632
JS_CGETSET_MAGIC_DEF("byteOffset", js_typed_array_get_byteOffset, NULL, 0 ),

test262_errors.txt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,6 @@ test262/test/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-
77
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.)
88
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
99
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: strict mode: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
10-
test262/test/built-ins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js:29: TypeError: not a function (Testing with BigInt64Array.)
11-
test262/test/built-ins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js:29: strict mode: TypeError: not a function (Testing with BigInt64Array.)
12-
test262/test/built-ins/TypedArray/prototype/with/early-type-coercion.js:29: TypeError: not a function (Testing with Float64Array.)
13-
test262/test/built-ins/TypedArray/prototype/with/early-type-coercion.js:29: strict mode: TypeError: not a function (Testing with Float64Array.)
14-
test262/test/built-ins/TypedArray/prototype/with/ignores-species.js:26: TypeError: not a function (Testing with Float64Array.)
15-
test262/test/built-ins/TypedArray/prototype/with/ignores-species.js:26: strict mode: TypeError: not a function (Testing with Float64Array.)
16-
test262/test/built-ins/TypedArray/prototype/with/immutable.js:14: TypeError: not a function (Testing with Float64Array.)
17-
test262/test/built-ins/TypedArray/prototype/with/immutable.js:14: strict mode: TypeError: not a function (Testing with Float64Array.)
18-
test262/test/built-ins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js:22: Test262Error: Expected a RangeError but got a TypeError (Testing with Float64Array.)
19-
test262/test/built-ins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js:22: strict mode: Test262Error: Expected a RangeError but got a TypeError (Testing with Float64Array.)
20-
test262/test/built-ins/TypedArray/prototype/with/index-casted-to-number.js:24: TypeError: not a function (Testing with Float64Array.)
21-
test262/test/built-ins/TypedArray/prototype/with/index-casted-to-number.js:24: strict mode: TypeError: not a function (Testing with Float64Array.)
22-
test262/test/built-ins/TypedArray/prototype/with/index-negative.js:24: TypeError: not a function (Testing with Float64Array.)
23-
test262/test/built-ins/TypedArray/prototype/with/index-negative.js:24: strict mode: TypeError: not a function (Testing with Float64Array.)
24-
test262/test/built-ins/TypedArray/prototype/with/index-smaller-than-minus-length.js:22: Test262Error: Expected a RangeError but got a TypeError (Testing with Float64Array.)
25-
test262/test/built-ins/TypedArray/prototype/with/index-smaller-than-minus-length.js:22: strict mode: Test262Error: Expected a RangeError but got a TypeError (Testing with Float64Array.)
26-
test262/test/built-ins/TypedArray/prototype/with/length-property-ignored.js:21: TypeError: not a function (Testing with Float64Array.)
27-
test262/test/built-ins/TypedArray/prototype/with/length-property-ignored.js:21: strict mode: TypeError: not a function (Testing with Float64Array.)
28-
test262/test/built-ins/TypedArray/prototype/with/metadata/length.js:30: TypeError: cannot convert to object
29-
test262/test/built-ins/TypedArray/prototype/with/metadata/length.js:30: strict mode: TypeError: cannot convert to object
30-
test262/test/built-ins/TypedArray/prototype/with/metadata/name.js:28: TypeError: cannot convert to object
31-
test262/test/built-ins/TypedArray/prototype/with/metadata/name.js:28: strict mode: TypeError: cannot convert to object
32-
test262/test/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js:18: Test262Error: typeof Expected SameValue(«undefined», «function») to be true
33-
test262/test/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js:18: strict mode: Test262Error: typeof Expected SameValue(«undefined», «function») to be true
34-
test262/test/built-ins/TypedArray/prototype/with/not-a-constructor.js:25: Test262Error: isConstructor invoked with a non-function value
35-
test262/test/built-ins/TypedArray/prototype/with/not-a-constructor.js:25: strict mode: Test262Error: isConstructor invoked with a non-function value
3610
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: Test262Error: (Testing with BigInt64Array.)
3711
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: strict mode: Test262Error: (Testing with BigInt64Array.)
3812
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js:40: Test262Error: Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42n;}}}) must return true Expected SameValue(«false», «true») to be true (Testing with BigInt64Array.)

0 commit comments

Comments
 (0)