From 500fb2f612bc323d176072ae506f4d6b73326d6c Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Mon, 30 Oct 2023 13:06:28 +0200 Subject: [PATCH] fix(ecmascript/array): Use OrdinaryObject for internal handler fallbacks --- nova_vm/src/ecmascript/builtins/array.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/nova_vm/src/ecmascript/builtins/array.rs b/nova_vm/src/ecmascript/builtins/array.rs index af158ab9c..8aa0a4e2a 100644 --- a/nova_vm/src/ecmascript/builtins/array.rs +++ b/nova_vm/src/ecmascript/builtins/array.rs @@ -6,15 +6,12 @@ mod data; use std::ops::Deref; -use super::{ - create_builtin_function, ordinary::ordinary_is_extensible, ArgumentsList, Behaviour, Builtin, - BuiltinFunctionArgs, -}; +use super::{create_builtin_function, ArgumentsList, Behaviour, Builtin, BuiltinFunctionArgs}; use crate::{ ecmascript::{ abstract_operations::testing_and_comparison::same_value_non_number, execution::{Agent, JsResult}, - types::{InternalMethods, Object, OrdinaryObjectInternalSlots, Value}, + types::{InternalMethods, Object, OrdinaryObject, OrdinaryObjectInternalSlots, Value}, }, heap::{indexes::ArrayIndex, GetHeapData}, }; @@ -71,7 +68,7 @@ impl ArrayConstructor { impl OrdinaryObjectInternalSlots for Array { fn extensible(self, agent: &Agent) -> bool { if let Some(object_index) = agent.heap.get(*self).object_index { - Object::from(object_index).extensible(agent) + OrdinaryObject::from(object_index).extensible(agent) } else { true } @@ -79,7 +76,7 @@ impl OrdinaryObjectInternalSlots for Array { fn set_extensible(self, agent: &mut Agent, value: bool) { if let Some(object_index) = agent.heap.get(*self).object_index { - Object::from(object_index).set_extensible(agent, value) + OrdinaryObject::from(object_index).set_extensible(agent, value) } else if !value { // Create array base object and set inextensible todo!() @@ -88,7 +85,7 @@ impl OrdinaryObjectInternalSlots for Array { fn prototype(self, agent: &Agent) -> Option { if let Some(object_index) = agent.heap.get(*self).object_index { - Object::from(object_index).prototype(agent) + OrdinaryObject::from(object_index).prototype(agent) } else { Some(agent.current_realm().intrinsics().array_prototype()) } @@ -96,7 +93,7 @@ impl OrdinaryObjectInternalSlots for Array { fn set_prototype(self, agent: &mut Agent, prototype: Option) { if let Some(object_index) = agent.heap.get(*self).object_index { - Object::from(object_index).set_prototype(agent, prototype) + OrdinaryObject::from(object_index).set_prototype(agent, prototype) } else if prototype != Some(agent.current_realm().intrinsics().array_prototype()) { // Create array base object with custom prototype todo!() @@ -107,7 +104,7 @@ impl OrdinaryObjectInternalSlots for Array { impl InternalMethods for Array { fn get_prototype_of(self, agent: &mut Agent) -> JsResult> { if let Some(object_index) = agent.heap.get(*self).object_index { - Object::Object(object_index).get_prototype_of(agent) + OrdinaryObject::from(object_index).get_prototype_of(agent) } else { Ok(Some(agent.current_realm().intrinsics().array_prototype())) } @@ -115,7 +112,7 @@ impl InternalMethods for Array { fn set_prototype_of(self, agent: &mut Agent, prototype: Option) -> JsResult { if let Some(object_index) = agent.heap.get(*self).object_index { - Object::Object(object_index).set_prototype_of(agent, prototype) + OrdinaryObject::from(object_index).set_prototype_of(agent, prototype) } else { // 1. Let current be O.[[Prototype]]. let current = agent.current_realm().intrinsics().array_prototype(); @@ -136,7 +133,7 @@ impl InternalMethods for Array { fn is_extensible(self, agent: &mut Agent) -> JsResult { if let Some(object_index) = agent.heap.get(*self).object_index { - Ok(ordinary_is_extensible(agent, Object::Object(object_index))) + OrdinaryObject::from(object_index).is_extensible(agent) } else { Ok(true) } @@ -144,8 +141,9 @@ impl InternalMethods for Array { fn prevent_extensions(self, agent: &mut Agent) -> JsResult { if let Some(object_index) = agent.heap.get(*self).object_index { - Ok(ordinary_is_extensible(agent, Object::Object(object_index))) + OrdinaryObject::from(object_index).prevent_extensions(agent) } else { + // TODO: Create base array object and call prevent extensions on it. Ok(true) } }