Skip to content

Commit 48ea659

Browse files
authored
feat(ecmascript): %TypedArray%.prototype.findLastIndex (#590)
1 parent 75be0d5 commit 48ea659

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/typed_array_intrinsic_object.rs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,13 +828,50 @@ impl TypedArrayPrototype {
828828
Ok(find_rec.1)
829829
}
830830

831+
// ### 23.2.3.14 %TypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] )(https://tc39.es/ecma262/multipage/indexed-collections.html#sec-%typedarray%.prototype.findlastindex)
832+
// 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.
831833
fn find_last_index<'gc>(
832-
_agent: &mut Agent,
833-
_this_value: Value,
834-
_: ArgumentsList,
835-
_gc: GcScope<'gc, '_>,
834+
agent: &mut Agent,
835+
this_value: Value,
836+
arguments: ArgumentsList,
837+
gc: GcScope<'gc, '_>,
836838
) -> JsResult<Value<'gc>> {
837-
todo!()
839+
let this_value = this_value.bind(gc.nogc());
840+
let predicate = arguments.get(0).scope(agent, gc.nogc());
841+
let this_arg = arguments.get(1).scope(agent, gc.nogc());
842+
// 1. Let O be the this value.
843+
let o = this_value;
844+
// 2. Let taRecord be ? ValidateTypedArray(O, seq-cst).
845+
let ta_record = validate_typed_array(agent, o, Ordering::SeqCst, gc.nogc())?;
846+
let o = ta_record.object;
847+
// 3. Let len be TypedArrayLength(taRecord).
848+
let len = match o {
849+
TypedArray::Int8Array(_)
850+
| TypedArray::Uint8Array(_)
851+
| TypedArray::Uint8ClampedArray(_) => {
852+
typed_array_length::<u8>(agent, &ta_record, gc.nogc())
853+
}
854+
TypedArray::Int16Array(_) | TypedArray::Uint16Array(_) => {
855+
typed_array_length::<u16>(agent, &ta_record, gc.nogc())
856+
}
857+
#[cfg(feature = "proposal-float16array")]
858+
TypedArray::Float16Array(_) => typed_array_length::<f16>(agent, &ta_record, gc.nogc()),
859+
TypedArray::Int32Array(_)
860+
| TypedArray::Uint32Array(_)
861+
| TypedArray::Float32Array(_) => {
862+
typed_array_length::<u32>(agent, &ta_record, gc.nogc())
863+
}
864+
TypedArray::BigInt64Array(_)
865+
| TypedArray::BigUint64Array(_)
866+
| TypedArray::Float64Array(_) => {
867+
typed_array_length::<u64>(agent, &ta_record, gc.nogc())
868+
}
869+
} as i64;
870+
let o = o.into_object().scope(agent, gc.nogc());
871+
// 4. Let findRec be ? FindViaPredicate(O, len, descending, predicate, thisArg).
872+
let find_rec = find_via_predicate(agent, o, len, false, predicate, this_arg, gc)?;
873+
// 5. Return findRec.[[Index]].
874+
Ok(Number::try_from(find_rec.0).unwrap().into_value())
838875
}
839876

840877
// ### [ 23.2.3.15 %TypedArray%.prototype.forEach ( callback [ , thisArg ] )](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-%typedarray%.prototype.foreach)

tests/expectations.json

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9570,40 +9570,6 @@
95709570
"built-ins/TypedArray/prototype/filter/this-is-not-typedarray-instance.js": "CRASH",
95719571
"built-ins/TypedArray/prototype/filter/values-are-not-cached.js": "CRASH",
95729572
"built-ins/TypedArray/prototype/filter/values-are-set.js": "CRASH",
9573-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/detached-buffer.js": "CRASH",
9574-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/get-length-ignores-length-prop.js": "CRASH",
9575-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-changes-value.js": "CRASH",
9576-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-parameters.js": "CRASH",
9577-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-non-strict.js": "CRASH",
9578-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-strict.js": "CRASH",
9579-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-is-not-callable-throws.js": "CRASH",
9580-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-may-detach-buffer.js": "CRASH",
9581-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/predicate-not-called-on-empty-array.js": "CRASH",
9582-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-predicate-call.js": "CRASH",
9583-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-this-out-of-bounds.js": "CRASH",
9584-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/return-index-predicate-result-is-true.js": "CRASH",
9585-
"built-ins/TypedArray/prototype/findLastIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js": "CRASH",
9586-
"built-ins/TypedArray/prototype/findLastIndex/callbackfn-resize.js": "CRASH",
9587-
"built-ins/TypedArray/prototype/findLastIndex/detached-buffer.js": "CRASH",
9588-
"built-ins/TypedArray/prototype/findLastIndex/get-length-ignores-length-prop.js": "CRASH",
9589-
"built-ins/TypedArray/prototype/findLastIndex/invoked-as-func.js": "CRASH",
9590-
"built-ins/TypedArray/prototype/findLastIndex/invoked-as-method.js": "CRASH",
9591-
"built-ins/TypedArray/prototype/findLastIndex/predicate-call-changes-value.js": "CRASH",
9592-
"built-ins/TypedArray/prototype/findLastIndex/predicate-call-parameters.js": "CRASH",
9593-
"built-ins/TypedArray/prototype/findLastIndex/predicate-call-this-non-strict.js": "CRASH",
9594-
"built-ins/TypedArray/prototype/findLastIndex/predicate-call-this-strict.js": "CRASH",
9595-
"built-ins/TypedArray/prototype/findLastIndex/predicate-is-not-callable-throws.js": "CRASH",
9596-
"built-ins/TypedArray/prototype/findLastIndex/predicate-may-detach-buffer.js": "CRASH",
9597-
"built-ins/TypedArray/prototype/findLastIndex/predicate-not-called-on-empty-array.js": "CRASH",
9598-
"built-ins/TypedArray/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js": "CRASH",
9599-
"built-ins/TypedArray/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js": "CRASH",
9600-
"built-ins/TypedArray/prototype/findLastIndex/resizable-buffer.js": "CRASH",
9601-
"built-ins/TypedArray/prototype/findLastIndex/return-abrupt-from-predicate-call.js": "CRASH",
9602-
"built-ins/TypedArray/prototype/findLastIndex/return-abrupt-from-this-out-of-bounds.js": "CRASH",
9603-
"built-ins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js": "CRASH",
9604-
"built-ins/TypedArray/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js": "CRASH",
9605-
"built-ins/TypedArray/prototype/findLastIndex/this-is-not-object.js": "CRASH",
9606-
"built-ins/TypedArray/prototype/findLastIndex/this-is-not-typedarray-instance.js": "CRASH",
96079573
"built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js": "CRASH",
96089574
"built-ins/TypedArray/prototype/join/coerced-separator-shrink.js": "CRASH",
96099575
"built-ins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js": "CRASH",

tests/metrics.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"results": {
3-
"crash": 13036,
4-
"fail": 7714,
5-
"pass": 25986,
3+
"crash": 13000,
4+
"fail": 7716,
5+
"pass": 26020,
66
"skip": 65,
77
"timeout": 0,
88
"unresolved": 0

0 commit comments

Comments
 (0)