Skip to content

Commit 05f00a8

Browse files
authored
Implement TypedArray.prototype.toReversed (#198)
1 parent baf50f9 commit 05f00a8

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

quickjs.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,10 @@ static JSValue js_typed_array_constructor(JSContext *ctx,
11461146
JSValue this_val,
11471147
int argc, JSValue *argv,
11481148
int classid);
1149+
static JSValue js_typed_array_constructor_ta(JSContext *ctx,
1150+
JSValue new_target,
1151+
JSValue src_obj,
1152+
int classid);
11491153
static BOOL typed_array_is_detached(JSContext *ctx, JSObject *p);
11501154
static uint32_t typed_array_get_length(JSContext *ctx, JSObject *p);
11511155
static JSValue JS_ThrowTypeErrorDetachedArrayBuffer(JSContext *ctx);
@@ -49144,6 +49148,24 @@ static JSValue js_typed_array_reverse(JSContext *ctx, JSValue this_val,
4914449148
return js_dup(this_val);
4914549149
}
4914649150

49151+
static JSValue js_typed_array_toReversed(JSContext *ctx, JSValue this_val,
49152+
int argc, JSValue *argv)
49153+
{
49154+
JSValue arr, ret;
49155+
JSObject *p;
49156+
49157+
p = get_typed_array(ctx, this_val, /*is_dataview*/0);
49158+
if (!p)
49159+
return JS_EXCEPTION;
49160+
arr = js_typed_array_constructor_ta(ctx, JS_UNDEFINED, this_val,
49161+
p->class_id);
49162+
if (JS_IsException(arr))
49163+
return JS_EXCEPTION;
49164+
ret = js_typed_array_reverse(ctx, arr, argc, argv);
49165+
JS_FreeValue(ctx, arr);
49166+
return ret;
49167+
}
49168+
4914749169
static JSValue js_typed_array_slice(JSContext *ctx, JSValue this_val,
4914849170
int argc, JSValue *argv)
4914949171
{
@@ -49572,6 +49594,7 @@ static const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {
4957249594
JS_CFUNC_MAGIC_DEF("findLast", 1, js_typed_array_find, ArrayFindLast ),
4957349595
JS_CFUNC_MAGIC_DEF("findLastIndex", 1, js_typed_array_find, ArrayFindLastIndex ),
4957449596
JS_CFUNC_DEF("reverse", 0, js_typed_array_reverse ),
49597+
JS_CFUNC_DEF("toReversed", 0, js_typed_array_toReversed ),
4957549598
JS_CFUNC_DEF("slice", 2, js_typed_array_slice ),
4957649599
JS_CFUNC_DEF("subarray", 2, js_typed_array_subarray ),
4957749600
JS_CFUNC_DEF("sort", 1, js_typed_array_sort ),

test262_errors.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +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/toReversed/ignores-species.js:26: TypeError: not a function (Testing with Float64Array.)
11-
test262/test/built-ins/TypedArray/prototype/toReversed/ignores-species.js:26: strict mode: TypeError: not a function (Testing with Float64Array.)
12-
test262/test/built-ins/TypedArray/prototype/toReversed/immutable.js:14: TypeError: not a function (Testing with Float64Array.)
13-
test262/test/built-ins/TypedArray/prototype/toReversed/immutable.js:14: strict mode: TypeError: not a function (Testing with Float64Array.)
14-
test262/test/built-ins/TypedArray/prototype/toReversed/length-property-ignored.js:21: TypeError: not a function (Testing with Float64Array.)
15-
test262/test/built-ins/TypedArray/prototype/toReversed/length-property-ignored.js:21: strict mode: TypeError: not a function (Testing with Float64Array.)
16-
test262/test/built-ins/TypedArray/prototype/toReversed/metadata/length.js:30: TypeError: cannot convert to object
17-
test262/test/built-ins/TypedArray/prototype/toReversed/metadata/length.js:30: strict mode: TypeError: cannot convert to object
18-
test262/test/built-ins/TypedArray/prototype/toReversed/metadata/name.js:28: TypeError: cannot convert to object
19-
test262/test/built-ins/TypedArray/prototype/toReversed/metadata/name.js:28: strict mode: TypeError: cannot convert to object
20-
test262/test/built-ins/TypedArray/prototype/toReversed/metadata/property-descriptor.js:18: Test262Error: typeof Expected SameValue(«undefined», «function») to be true
21-
test262/test/built-ins/TypedArray/prototype/toReversed/metadata/property-descriptor.js:18: strict mode: Test262Error: typeof Expected SameValue(«undefined», «function») to be true
22-
test262/test/built-ins/TypedArray/prototype/toReversed/not-a-constructor.js:25: Test262Error: isConstructor invoked with a non-function value
23-
test262/test/built-ins/TypedArray/prototype/toReversed/not-a-constructor.js:25: strict mode: Test262Error: isConstructor invoked with a non-function value
2410
test262/test/built-ins/TypedArray/prototype/toSorted/ignores-species.js:26: TypeError: not a function (Testing with Float64Array.)
2511
test262/test/built-ins/TypedArray/prototype/toSorted/ignores-species.js:26: strict mode: TypeError: not a function (Testing with Float64Array.)
2612
test262/test/built-ins/TypedArray/prototype/toSorted/immutable.js:14: TypeError: not a function (Testing with Float64Array.)

0 commit comments

Comments
 (0)