Implement TypedArray.prototype.findLast{Index} (#73)

This commit is contained in:
Ben Noordhuis 2023-11-17 11:56:22 +01:00 committed by GitHub
parent 7e955f6f4c
commit d88e9df9de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 103 deletions

View file

@ -48254,12 +48254,13 @@ static JSValue js_typed_array_fill(JSContext *ctx, JSValueConst this_val,
}
static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv, int findIndex)
int argc, JSValueConst *argv, int mode)
{
JSValueConst func, this_arg;
JSValueConst args[3];
JSValue val, index_val, res;
int len, k;
int len, k, end;
int dir;
val = JS_UNDEFINED;
len = js_typed_array_get_length_internal(ctx, this_val);
@ -48274,7 +48275,16 @@ static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val,
if (argc > 1)
this_arg = argv[1];
for(k = 0; k < len; k++) {
k = 0;
dir = 1;
end = len;
if (mode == ArrayFindLast || mode == ArrayFindLastIndex) {
k = len - 1;
dir = -1;
end = -1;
}
for(; k != end; k += dir) {
index_val = JS_NewInt32(ctx, k);
val = JS_GetPropertyValue(ctx, this_val, index_val);
if (JS_IsException(val))
@ -48286,7 +48296,7 @@ static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val,
if (JS_IsException(res))
goto exception;
if (JS_ToBoolFree(ctx, res)) {
if (findIndex) {
if (mode == ArrayFindIndex || mode == ArrayFindLastIndex) {
JS_FreeValue(ctx, val);
return index_val;
} else {
@ -48295,7 +48305,7 @@ static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val,
}
JS_FreeValue(ctx, val);
}
if (findIndex)
if (mode == ArrayFindIndex || mode == ArrayFindLastIndex)
return JS_NewInt32(ctx, -1);
else
return JS_UNDEFINED;
@ -49091,8 +49101,10 @@ static const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {
JS_CFUNC_MAGIC_DEF("reduce", 1, js_array_reduce, special_reduce | special_TA ),
JS_CFUNC_MAGIC_DEF("reduceRight", 1, js_array_reduce, special_reduceRight | special_TA ),
JS_CFUNC_DEF("fill", 1, js_typed_array_fill ),
JS_CFUNC_MAGIC_DEF("find", 1, js_typed_array_find, 0 ),
JS_CFUNC_MAGIC_DEF("findIndex", 1, js_typed_array_find, 1 ),
JS_CFUNC_MAGIC_DEF("find", 1, js_typed_array_find, ArrayFind ),
JS_CFUNC_MAGIC_DEF("findIndex", 1, js_typed_array_find, ArrayFindIndex ),
JS_CFUNC_MAGIC_DEF("findLast", 1, js_typed_array_find, ArrayFindLast ),
JS_CFUNC_MAGIC_DEF("findLastIndex", 1, js_typed_array_find, ArrayFindLastIndex ),
JS_CFUNC_DEF("reverse", 0, js_typed_array_reverse ),
JS_CFUNC_DEF("slice", 2, js_typed_array_slice ),
JS_CFUNC_DEF("subarray", 2, js_typed_array_subarray ),

View file

@ -187,102 +187,6 @@ test262/test/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js:26:
test262/test/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js:26: strict mode: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all
test262/test/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js:62: Test262Error: String.prototype.localeCompare considers ö (\u006f\u0308) ≠ ö (\u00f6).
test262/test/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js:62: strict mode: Test262Error: String.prototype.localeCompare considers ö (\u006f\u0308) ≠ ö (\u00f6).
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/get-length-ignores-length-prop.js:40: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/get-length-ignores-length-prop.js:40: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-changes-value.js:30: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-changes-value.js:30: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-parameters.js:28: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-parameters.js:28: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-this-non-strict.js:27: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-this-strict.js:25: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-may-detach-buffer.js:36: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-may-detach-buffer.js:36: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-not-called-on-empty-array.js:25: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-not-called-on-empty-array.js:25: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-predicate-call.js:22: Test262Error: Expected a Test262Error but got a TypeError (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-predicate-call.js:22: strict mode: Test262Error: Expected a Test262Error but got a TypeError (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/return-found-value-predicate-result-is-true.js:27: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/return-found-value-predicate-result-is-true.js:27: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/return-undefined-if-predicate-returns-false-value.js:27: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/BigInt/return-undefined-if-predicate-returns-false-value.js:27: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/get-length-ignores-length-prop.js:39: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/get-length-ignores-length-prop.js:39: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/invoked-as-func.js:21: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLast/invoked-as-func.js:21: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLast/invoked-as-method.js:21: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLast/invoked-as-method.js:21: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLast/length.js:26: TypeError: cannot read property 'length' of undefined
test262/test/built-ins/TypedArray/prototype/findLast/length.js:26: strict mode: TypeError: cannot read property 'length' of undefined
test262/test/built-ins/TypedArray/prototype/findLast/name.js:23: TypeError: cannot read property 'name' of undefined
test262/test/built-ins/TypedArray/prototype/findLast/name.js:23: strict mode: TypeError: cannot read property 'name' of undefined
test262/test/built-ins/TypedArray/prototype/findLast/not-a-constructor.js:25: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/TypedArray/prototype/findLast/not-a-constructor.js:25: strict mode: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/TypedArray/prototype/findLast/predicate-call-changes-value.js:30: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-call-changes-value.js:30: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-call-parameters.js:28: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-call-parameters.js:28: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-call-this-non-strict.js:27: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-call-this-strict.js:25: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-may-detach-buffer.js:36: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-may-detach-buffer.js:36: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-not-called-on-empty-array.js:25: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/predicate-not-called-on-empty-array.js:25: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/prop-desc.js:15: Test262Error: obj should have an own property findLast
test262/test/built-ins/TypedArray/prototype/findLast/prop-desc.js:15: strict mode: Test262Error: obj should have an own property findLast
test262/test/built-ins/TypedArray/prototype/findLast/return-abrupt-from-predicate-call.js:22: Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/return-abrupt-from-predicate-call.js:22: strict mode: Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js:27: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js:27: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/return-undefined-if-predicate-returns-false-value.js:27: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLast/return-undefined-if-predicate-returns-false-value.js:27: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/get-length-ignores-length-prop.js:40: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/get-length-ignores-length-prop.js:40: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-changes-value.js:29: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-changes-value.js:29: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-parameters.js:29: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-parameters.js:29: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-non-strict.js:29: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-strict.js:27: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-may-detach-buffer.js:35: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-may-detach-buffer.js:35: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-not-called-on-empty-array.js:29: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-not-called-on-empty-array.js:29: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-predicate-call.js:21: Test262Error: Expected a Test262Error but got a TypeError (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-predicate-call.js:21: strict mode: Test262Error: Expected a Test262Error but got a TypeError (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/return-index-predicate-result-is-true.js:28: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/return-index-predicate-result-is-true.js:28: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js:28: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js:28: strict mode: TypeError: not a function (Testing with BigInt64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/get-length-ignores-length-prop.js:40: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/get-length-ignores-length-prop.js:40: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/invoked-as-func.js:23: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLastIndex/invoked-as-func.js:23: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLastIndex/invoked-as-method.js:23: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLastIndex/invoked-as-method.js:23: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/findLastIndex/length.js:26: TypeError: cannot read property 'length' of undefined
test262/test/built-ins/TypedArray/prototype/findLastIndex/length.js:26: strict mode: TypeError: cannot read property 'length' of undefined
test262/test/built-ins/TypedArray/prototype/findLastIndex/name.js:23: TypeError: cannot read property 'name' of undefined
test262/test/built-ins/TypedArray/prototype/findLastIndex/name.js:23: strict mode: TypeError: cannot read property 'name' of undefined
test262/test/built-ins/TypedArray/prototype/findLastIndex/not-a-constructor.js:25: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/TypedArray/prototype/findLastIndex/not-a-constructor.js:25: strict mode: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-call-changes-value.js:29: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-call-changes-value.js:29: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-call-parameters.js:29: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-call-parameters.js:29: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-call-this-non-strict.js:29: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-call-this-strict.js:27: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-may-detach-buffer.js:35: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-may-detach-buffer.js:35: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-not-called-on-empty-array.js:29: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/predicate-not-called-on-empty-array.js:29: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/prop-desc.js:15: Test262Error: obj should have an own property findLastIndex
test262/test/built-ins/TypedArray/prototype/findLastIndex/prop-desc.js:15: strict mode: Test262Error: obj should have an own property findLastIndex
test262/test/built-ins/TypedArray/prototype/findLastIndex/return-abrupt-from-predicate-call.js:21: Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/return-abrupt-from-predicate-call.js:21: strict mode: Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js:28: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js:28: strict mode: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js:28: TypeError: not a function (Testing with Float64Array.)
test262/test/built-ins/TypedArray/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js:28: strict mode: TypeError: not a function (Testing with Float64Array.)
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.)
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.)