Skip to content

Commit 9c5fb9f

Browse files
committed
use inner for now
1 parent 4d63273 commit 9c5fb9f

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

core/engine/src/native_function.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,20 +391,32 @@ fn native_function_construct(
391391
obj: &JsObject,
392392
argument_count: usize,
393393
context: &mut Context,
394+
) -> JsResult<CallValue> {
395+
native_function_construct_inner(
396+
&obj.downcast_ref::<NativeFunctionObject>()
397+
.expect("the object should be a native function object")
398+
.clone(),
399+
obj.clone(),
400+
argument_count,
401+
context,
402+
)
403+
}
404+
405+
pub(crate) fn native_function_construct_inner(
406+
native_function: &NativeFunctionObject,
407+
this_function_object: JsObject,
408+
argument_count: usize,
409+
context: &mut Context,
394410
) -> JsResult<CallValue> {
395411
// We technically don't need this since native functions don't push any new frames to the
396412
// vm, but we'll eventually have to combine the native stack with the vm stack.
397413
context.check_runtime_limits()?;
398-
let this_function_object = obj.clone();
399414

400415
let NativeFunctionObject {
401416
f: function,
402417
constructor,
403418
realm,
404-
} = obj
405-
.downcast_ref::<NativeFunctionObject>()
406-
.expect("the object should be a native function object")
407-
.clone();
419+
} = native_function.clone();
408420

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

core/engine/src/object/builtins/lazy_builtin.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
builtins::function::ConstructorKind,
33
gc::custom_trace,
4-
native_function::NativeFunctionObject,
4+
native_function::{native_function_construct_inner, NativeFunctionObject},
55
object::{
66
internal_methods::{
77
non_existant_call, non_existant_construct, ordinary_define_own_property,
@@ -226,11 +226,10 @@ pub(crate) fn lazy_construct(
226226
.with_message("not a constructor")
227227
.with_realm(context.realm().clone())
228228
.into()),
229-
BuiltinKind::Function(constructor) => {
230-
let construct = constructor.internal_methods().__construct__;
229+
BuiltinKind::Function(cons) => {
231230
// builtin needs to be dropped before calling the constructor to avoid a double borrow
232231
drop(builtin);
233-
Ok(construct(obj, argument_count, context)?)
232+
native_function_construct_inner(cons, obj.clone(), argument_count, context)
234233
}
235234
}
236235
}

0 commit comments

Comments
 (0)