diff --git a/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/typed_array_intrinsic_object.rs b/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/typed_array_intrinsic_object.rs index 8b96d7caf..a38a60922 100644 --- a/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/typed_array_intrinsic_object.rs +++ b/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/typed_array_intrinsic_object.rs @@ -828,13 +828,50 @@ impl TypedArrayPrototype { Ok(find_rec.1) } + // ### 23.2.3.14 %TypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] )(https://tc39.es/ecma262/multipage/indexed-collections.html#sec-%typedarray%.prototype.findlastindex) + // The interpretation and use of the arguments of this method are the same as for Array.prototype.findLastIndex as defined in 23.1.3.12. fn find_last_index<'gc>( - _agent: &mut Agent, - _this_value: Value, - _: ArgumentsList, - _gc: GcScope<'gc, '_>, + agent: &mut Agent, + this_value: Value, + arguments: ArgumentsList, + gc: GcScope<'gc, '_>, ) -> JsResult> { - todo!() + let this_value = this_value.bind(gc.nogc()); + let predicate = arguments.get(0).scope(agent, gc.nogc()); + let this_arg = arguments.get(1).scope(agent, gc.nogc()); + // 1. Let O be the this value. + let o = this_value; + // 2. Let taRecord be ? ValidateTypedArray(O, seq-cst). + let ta_record = validate_typed_array(agent, o, Ordering::SeqCst, gc.nogc())?; + let o = ta_record.object; + // 3. Let len be TypedArrayLength(taRecord). + let len = match o { + TypedArray::Int8Array(_) + | TypedArray::Uint8Array(_) + | TypedArray::Uint8ClampedArray(_) => { + typed_array_length::(agent, &ta_record, gc.nogc()) + } + TypedArray::Int16Array(_) | TypedArray::Uint16Array(_) => { + typed_array_length::(agent, &ta_record, gc.nogc()) + } + #[cfg(feature = "proposal-float16array")] + TypedArray::Float16Array(_) => typed_array_length::(agent, &ta_record, gc.nogc()), + TypedArray::Int32Array(_) + | TypedArray::Uint32Array(_) + | TypedArray::Float32Array(_) => { + typed_array_length::(agent, &ta_record, gc.nogc()) + } + TypedArray::BigInt64Array(_) + | TypedArray::BigUint64Array(_) + | TypedArray::Float64Array(_) => { + typed_array_length::(agent, &ta_record, gc.nogc()) + } + } as i64; + let o = o.into_object().scope(agent, gc.nogc()); + // 4. Let findRec be ? FindViaPredicate(O, len, descending, predicate, thisArg). + let find_rec = find_via_predicate(agent, o, len, false, predicate, this_arg, gc)?; + // 5. Return findRec.[[Index]]. + Ok(Number::try_from(find_rec.0).unwrap().into_value()) } // ### [ 23.2.3.15 %TypedArray%.prototype.forEach ( callback [ , thisArg ] )](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-%typedarray%.prototype.foreach) diff --git a/tests/expectations.json b/tests/expectations.json index 024266f5e..744cda4da 100644 --- a/tests/expectations.json +++ b/tests/expectations.json @@ -9570,40 +9570,6 @@ "built-ins/TypedArray/prototype/filter/this-is-not-typedarray-instance.js": "CRASH", "built-ins/TypedArray/prototype/filter/values-are-not-cached.js": "CRASH", "built-ins/TypedArray/prototype/filter/values-are-set.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/detached-buffer.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/get-length-ignores-length-prop.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-changes-value.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-parameters.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-non-strict.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-strict.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-is-not-callable-throws.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-may-detach-buffer.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-not-called-on-empty-array.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-predicate-call.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-this-out-of-bounds.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/return-index-predicate-result-is-true.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/callbackfn-resize.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/detached-buffer.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/get-length-ignores-length-prop.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/invoked-as-func.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/invoked-as-method.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/predicate-call-changes-value.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/predicate-call-parameters.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/predicate-call-this-non-strict.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/predicate-call-this-strict.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/predicate-is-not-callable-throws.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/predicate-may-detach-buffer.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/predicate-not-called-on-empty-array.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/resizable-buffer.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/return-abrupt-from-predicate-call.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/return-abrupt-from-this-out-of-bounds.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/this-is-not-object.js": "CRASH", - "built-ins/TypedArray/prototype/findLastIndex/this-is-not-typedarray-instance.js": "CRASH", "built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js": "CRASH", "built-ins/TypedArray/prototype/join/coerced-separator-shrink.js": "CRASH", "built-ins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js": "CRASH", diff --git a/tests/metrics.json b/tests/metrics.json index 3d8263353..078a41698 100644 --- a/tests/metrics.json +++ b/tests/metrics.json @@ -1,8 +1,8 @@ { "results": { - "crash": 13036, - "fail": 7714, - "pass": 25986, + "crash": 13000, + "fail": 7716, + "pass": 26020, "skip": 65, "timeout": 0, "unresolved": 0