Skip to content

Commit cf4a379

Browse files
committed
Fold init and realm into a single option type, no need for NAME to be passed through
1 parent 7b4069a commit cf4a379

File tree

4 files changed

+163
-197
lines changed

4 files changed

+163
-197
lines changed

core/engine/src/builtins/function/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl BuiltInFunctionObject {
834834
};
835835

836836
let object_borrow = object.borrow();
837-
if object_borrow.is::<NativeFunctionObject>() {
837+
if object_borrow.is::<NativeFunctionObject>() || object_borrow.is::<LazyBuiltIn>() {
838838
let name = {
839839
// Is there a case here where if there is no name field on a value
840840
// name should default to None? Do all functions have names set?
@@ -850,13 +850,6 @@ impl BuiltInFunctionObject {
850850
);
851851
} else if object_borrow.is::<Proxy>() || object_borrow.is::<BoundFunction>() {
852852
return Ok(js_string!("function () { [native code] }").into());
853-
} else if object_borrow.is::<LazyBuiltIn>() {
854-
let name = object_borrow
855-
.downcast_ref::<LazyBuiltIn>()
856-
.map_or_else(|| js_string!(), |built_in| built_in.name.clone());
857-
return Ok(
858-
js_string!(js_str!("function "), &name, js_str!("() { [native code] }")).into(),
859-
);
860853
}
861854

862855
let function = object_borrow

core/engine/src/context/intrinsics.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
33
use boa_gc::{Finalize, Trace, WeakGc};
44
use boa_macros::js_str;
5-
use boa_string::JsString;
65

76
use crate::{
87
builtins::{
9-
iterable::IteratorPrototypes, uri::UriFunctions, Array, BuiltInObject, Date,
10-
IntrinsicObject, OrdinaryObject,
8+
iterable::IteratorPrototypes, uri::UriFunctions, Array, Date, IntrinsicObject,
9+
OrdinaryObject,
1110
},
1211
js_string,
1312
object::{
@@ -101,9 +100,9 @@ impl StandardConstructor {
101100
}
102101

103102
/// Similar to `with_prototype`, but the prototype is lazily initialized.
104-
fn lazy(init: fn(&Realm) -> (), name: JsString, realm_inner: WeakGc<RealmInner>) -> Self {
103+
fn lazy(init: fn(&Realm) -> (), realm_inner: WeakGc<RealmInner>) -> Self {
105104
Self {
106-
constructor: JsFunction::lazy_intrinsic_function(true, init, name, realm_inner),
105+
constructor: JsFunction::lazy_intrinsic_function(true, init, realm_inner),
107106
prototype: JsObject::default(),
108107
}
109108
}
@@ -225,14 +224,14 @@ impl StandardConstructors {
225224
)),
226225
async_generator_function: StandardConstructor::default(),
227226
proxy: StandardConstructor::default(),
228-
date: StandardConstructor::lazy(Date::init, Date::NAME, realm_inner.clone()),
227+
date: StandardConstructor::lazy(Date::init, realm_inner.clone()),
229228
function: StandardConstructor {
230229
constructor: JsFunction::empty_intrinsic_function(true),
231230
prototype: JsFunction::empty_intrinsic_function(false).into(),
232231
},
233232
async_function: StandardConstructor::default(),
234233
generator_function: StandardConstructor::default(),
235-
array: StandardConstructor::lazy(Array::init, Array::NAME, realm_inner.clone()),
234+
array: StandardConstructor::lazy(Array::init, realm_inner.clone()),
236235
bigint: StandardConstructor::default(),
237236
number: StandardConstructor::with_prototype(JsObject::from_proto_and_data(None, 0.0)),
238237
boolean: StandardConstructor::with_prototype(JsObject::from_proto_and_data(

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use crate::{
55
value::TryFromJs, Context, JsNativeError, JsResult, JsValue, NativeFunction, TryIntoJsResult,
66
};
77
use boa_gc::{Finalize, Trace, WeakGc};
8-
use boa_string::JsString;
9-
use std::cell::Cell;
108
use std::marker::PhantomData;
119
use std::ops::Deref;
1210

@@ -109,7 +107,6 @@ impl JsFunction {
109107
pub(crate) fn lazy_intrinsic_function(
110108
constructor: bool,
111109
init: fn(&Realm),
112-
name: JsString,
113110
realm_inner: WeakGc<RealmInner>,
114111
) -> Self {
115112
let kind = if constructor {
@@ -122,11 +119,8 @@ impl JsFunction {
122119
inner: JsObject::from_proto_and_data(
123120
None,
124121
LazyBuiltIn {
125-
init,
126-
is_initialized: Cell::new(false),
122+
init_and_realm: Some((init, realm_inner)),
127123
kind,
128-
name,
129-
realm_inner: Some(realm_inner),
130124
},
131125
),
132126
}

0 commit comments

Comments
 (0)