Skip to content

Commit

Permalink
feat(array): Implement from_slice to array (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 authored Sep 11, 2024
1 parent 21313ea commit b69b5fd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion nova_vm/src/ecmascript/builtins/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use super::{array_set_length, ordinary::ordinary_define_own_property};
use crate::{
ecmascript::{
abstract_operations::{
operations_on_objects::call_function, testing_and_comparison::same_value,
operations_on_objects::{call_function, create_array_from_list},
testing_and_comparison::same_value,
},
execution::{Agent, JsResult, ProtoIntrinsics},
types::{
Expand Down Expand Up @@ -44,6 +45,15 @@ impl Array {
Self(ArrayIndex::from_u32_index(0))
}

/// Creates a new array with the given elements.
///
/// This is equal to the [CreateArrayFromList](https://tc39.es/ecma262/#sec-createarrayfromlist)
/// abstract operation.
#[inline]
pub fn from_slice(agent: &mut Agent, elements: &[Value]) -> Self {
create_array_from_list(agent, elements)
}

pub(crate) fn get_index(self) -> usize {
self.0.into_index()
}
Expand Down

0 comments on commit b69b5fd

Please sign in to comment.