Implement TypedArray.prototype.with (#200)
This commit is contained in:
parent
83dfc635f1
commit
315096461b
2 changed files with 38 additions and 26 deletions
38
quickjs.c
38
quickjs.c
|
@ -48401,6 +48401,43 @@ static JSValue js_typed_array_at(JSContext *ctx, JSValue this_val,
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_typed_array_with(JSContext *ctx, JSValue this_val,
|
||||||
|
int argc, JSValue *argv)
|
||||||
|
{
|
||||||
|
JSValue arr, val, ret;
|
||||||
|
JSObject *p;
|
||||||
|
int64_t idx, len;
|
||||||
|
|
||||||
|
p = get_typed_array(ctx, this_val, /*is_dataview*/0);
|
||||||
|
if (!p)
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
|
||||||
|
if (JS_ToInt64Sat(ctx, &idx, argv[0]))
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
|
||||||
|
len = p->u.array.count;
|
||||||
|
if (idx < 0)
|
||||||
|
idx = len + idx;
|
||||||
|
if (idx < 0 || idx >= len)
|
||||||
|
return JS_ThrowRangeError(ctx, "invalid array index");
|
||||||
|
|
||||||
|
val = JS_ToPrimitive(ctx, argv[1], HINT_NUMBER);
|
||||||
|
if (JS_IsException(val))
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
|
||||||
|
arr = js_typed_array_constructor_ta(ctx, JS_UNDEFINED, this_val,
|
||||||
|
p->class_id);
|
||||||
|
if (JS_IsException(arr)) {
|
||||||
|
JS_FreeValue(ctx, val);
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
if (JS_SetPropertyInt64(ctx, arr, idx, val) < 0) {
|
||||||
|
JS_FreeValue(ctx, arr);
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_typed_array_set(JSContext *ctx,
|
static JSValue js_typed_array_set(JSContext *ctx,
|
||||||
JSValue this_val,
|
JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
|
@ -49589,6 +49626,7 @@ static const JSCFunctionListEntry js_typed_array_base_funcs[] = {
|
||||||
static const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {
|
static const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("length", js_typed_array_get_length, NULL ),
|
JS_CGETSET_DEF("length", js_typed_array_get_length, NULL ),
|
||||||
JS_CFUNC_DEF("at", 1, js_typed_array_at ),
|
JS_CFUNC_DEF("at", 1, js_typed_array_at ),
|
||||||
|
JS_CFUNC_DEF("with", 2, js_typed_array_with ),
|
||||||
JS_CGETSET_MAGIC_DEF("buffer", js_typed_array_get_buffer, NULL, 0 ),
|
JS_CGETSET_MAGIC_DEF("buffer", js_typed_array_get_buffer, NULL, 0 ),
|
||||||
JS_CGETSET_MAGIC_DEF("byteLength", js_typed_array_get_byteLength, NULL, 0 ),
|
JS_CGETSET_MAGIC_DEF("byteLength", js_typed_array_get_byteLength, NULL, 0 ),
|
||||||
JS_CGETSET_MAGIC_DEF("byteOffset", js_typed_array_get_byteOffset, NULL, 0 ),
|
JS_CGETSET_MAGIC_DEF("byteOffset", js_typed_array_get_byteOffset, NULL, 0 ),
|
||||||
|
|
|
@ -7,32 +7,6 @@ test262/test/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-
|
||||||
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.)
|
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.)
|
||||||
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
|
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
|
||||||
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: strict mode: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
|
test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:30: strict mode: TypeError: ArrayBuffer is detached (Testing with Float64Array.)
|
||||||
test262/test/built-ins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js:29: TypeError: not a function (Testing with BigInt64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js:29: strict mode: TypeError: not a function (Testing with BigInt64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/early-type-coercion.js:29: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/early-type-coercion.js:29: strict mode: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/ignores-species.js:26: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/ignores-species.js:26: strict mode: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/immutable.js:14: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/immutable.js:14: strict mode: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
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.)
|
|
||||||
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.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/index-casted-to-number.js:24: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/index-casted-to-number.js:24: strict mode: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/index-negative.js:24: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/index-negative.js:24: strict mode: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
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.)
|
|
||||||
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.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/length-property-ignored.js:21: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/length-property-ignored.js:21: strict mode: TypeError: not a function (Testing with Float64Array.)
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/metadata/length.js:30: TypeError: cannot convert to object
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/metadata/length.js:30: strict mode: TypeError: cannot convert to object
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/metadata/name.js:28: TypeError: cannot convert to object
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/metadata/name.js:28: strict mode: TypeError: cannot convert to object
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js:18: Test262Error: typeof Expected SameValue(«undefined», «function») to be true
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js:18: strict mode: Test262Error: typeof Expected SameValue(«undefined», «function») to be true
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/not-a-constructor.js:25: Test262Error: isConstructor invoked with a non-function value
|
|
||||||
test262/test/built-ins/TypedArray/prototype/with/not-a-constructor.js:25: strict mode: Test262Error: isConstructor invoked with a non-function value
|
|
||||||
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: Test262Error: (Testing with BigInt64Array.)
|
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: Test262Error: (Testing with BigInt64Array.)
|
||||||
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: strict mode: Test262Error: (Testing with BigInt64Array.)
|
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: strict mode: Test262Error: (Testing with BigInt64Array.)
|
||||||
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.)
|
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.)
|
||||||
|
|
Loading…
Reference in a new issue