Skip to content

Commit

Permalink
use inner for now
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwilliams committed Nov 9, 2024
1 parent 4d63273 commit 9c5fb9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
22 changes: 17 additions & 5 deletions core/engine/src/native_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,32 @@ fn native_function_construct(
obj: &JsObject,
argument_count: usize,
context: &mut Context,
) -> JsResult<CallValue> {
native_function_construct_inner(
&obj.downcast_ref::<NativeFunctionObject>()
.expect("the object should be a native function object")
.clone(),
obj.clone(),
argument_count,
context,
)
}

pub(crate) fn native_function_construct_inner(
native_function: &NativeFunctionObject,
this_function_object: JsObject,
argument_count: usize,
context: &mut Context,
) -> JsResult<CallValue> {
// We technically don't need this since native functions don't push any new frames to the
// vm, but we'll eventually have to combine the native stack with the vm stack.
context.check_runtime_limits()?;
let this_function_object = obj.clone();

let NativeFunctionObject {
f: function,
constructor,
realm,
} = obj
.downcast_ref::<NativeFunctionObject>()
.expect("the object should be a native function object")
.clone();
} = native_function.clone();

let mut realm = realm.unwrap_or_else(|| context.realm().clone());

Expand Down
7 changes: 3 additions & 4 deletions core/engine/src/object/builtins/lazy_builtin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
builtins::function::ConstructorKind,
gc::custom_trace,
native_function::NativeFunctionObject,
native_function::{native_function_construct_inner, NativeFunctionObject},
object::{
internal_methods::{
non_existant_call, non_existant_construct, ordinary_define_own_property,
Expand Down Expand Up @@ -226,11 +226,10 @@ pub(crate) fn lazy_construct(
.with_message("not a constructor")
.with_realm(context.realm().clone())
.into()),
BuiltinKind::Function(constructor) => {
let construct = constructor.internal_methods().__construct__;
BuiltinKind::Function(cons) => {
// builtin needs to be dropped before calling the constructor to avoid a double borrow
drop(builtin);
Ok(construct(obj, argument_count, context)?)
native_function_construct_inner(cons, obj.clone(), argument_count, context)
}
}
}
Expand Down

0 comments on commit 9c5fb9f

Please sign in to comment.