Skip to content

Commit

Permalink
fix(ecmascript): construct internal method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Oct 30, 2023
1 parent e02049a commit b0736d1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
21 changes: 11 additions & 10 deletions nova_vm/src/ecmascript/types/language/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,7 @@ impl OrdinaryObjectInternalSlots for Function {
fn set_prototype(self, agent: &mut Agent, prototype: Option<Object>) {
if let Some(object_index) = agent.heap.get(*self).object_index {
Object::from(object_index).set_prototype(agent, prototype)
} else if prototype
!= Some(
agent
.current_realm()
.intrinsics()
.function_prototype(),
)
{
} else if prototype != Some(agent.current_realm().intrinsics().function_prototype()) {
// Create function base object with custom prototype
todo!()
}
Expand All @@ -145,7 +138,10 @@ impl InternalMethods for Function {
todo!()
}

fn prevent_extensions(self, _agent: &mut Agent) -> crate::ecmascript::execution::JsResult<bool> {
fn prevent_extensions(
self,
_agent: &mut Agent,
) -> crate::ecmascript::execution::JsResult<bool> {
todo!()
}

Expand Down Expand Up @@ -218,7 +214,12 @@ impl InternalMethods for Function {
todo!()
}

fn construct(self, _agent: &mut Agent, _arguments_list: &[Value]) -> JsResult<Object> {
fn construct(
self,
_agent: &mut Agent,
_arguments_list: &[Value],
new_target: Function,
) -> JsResult<Object> {
todo!()
}
}
11 changes: 9 additions & 2 deletions nova_vm/src/ecmascript/types/language/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,16 @@ impl InternalMethods for Object {
}
}

fn construct(self, agent: &mut Agent, arguments_list: &[Value]) -> JsResult<Object> {
fn construct(
self,
agent: &mut Agent,
arguments_list: &[Value],
new_target: Function,
) -> JsResult<Object> {
match self {
Object::Function(idx) => Function::from(idx).construct(agent, arguments_list),
Object::Function(idx) => {
Function::from(idx).construct(agent, arguments_list, new_target)
}
_ => unreachable!(),
}
}
Expand Down
18 changes: 7 additions & 11 deletions nova_vm/src/ecmascript/types/language/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ use super::{Object, PropertyKey};
use crate::ecmascript::{
builtins::ArgumentsList,
execution::{Agent, JsResult},
types::{PropertyDescriptor, Value},
types::{Function, PropertyDescriptor, Value},
};

pub type Call<T> = fn(
agent: &mut Agent,
object: T,
this_value: Value,
arguments_list: ArgumentsList,
) -> JsResult<Value>;
pub type Construct<T> =
fn(agent: &mut Agent, object: T, arguments_list: ArgumentsList) -> JsResult<T>;

/// 6.1.7.2 Object Internal Methods and Internal Slots
/// https://tc39.es/ecma262/#sec-object-internal-methods-and-internal-slots
pub trait InternalMethods<T = Object>
Expand Down Expand Up @@ -79,7 +70,12 @@ where
}

/// \[\[Construct\]\]
fn construct(self, _agent: &mut Agent, _arguments_list: &[Value]) -> JsResult<T> {
fn construct(
self,
_agent: &mut Agent,
_arguments_list: &[Value],
new_target: Function,
) -> JsResult<T> {
unreachable!()
}
}
4 changes: 1 addition & 3 deletions nova_vm/src/ecmascript/types/language/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use std::mem::size_of;

use crate::{
ecmascript::{
abstract_operations::{
type_conversion::{to_int32, to_number, to_numeric, to_uint32},
},
abstract_operations::type_conversion::{to_int32, to_number, to_numeric, to_uint32},
execution::{Agent, JsResult},
},
heap::indexes::{
Expand Down

0 comments on commit b0736d1

Please sign in to comment.