Skip to content

Commit aaa4bf3

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

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
@@ -843,7 +843,7 @@ impl BuiltInFunctionObject {
843843
};
844844

845845
let object_borrow = object.borrow();
846-
if object_borrow.is::<NativeFunctionObject>() {
846+
if object_borrow.is::<NativeFunctionObject>() || object_borrow.is::<LazyBuiltIn>() {
847847
let name = {
848848
// Is there a case here where if there is no name field on a value
849849
// name should default to None? Do all functions have names set?
@@ -859,13 +859,6 @@ impl BuiltInFunctionObject {
859859
);
860860
} else if object_borrow.is::<Proxy>() || object_borrow.is::<BoundFunction>() {
861861
return Ok(js_string!("function () { [native code] }").into());
862-
} else if object_borrow.is::<LazyBuiltIn>() {
863-
let name = object_borrow
864-
.downcast_ref::<LazyBuiltIn>()
865-
.map_or_else(|| js_string!(), |built_in| built_in.name.clone());
866-
return Ok(
867-
js_string!(js_str!("function "), &name, js_str!("() { [native code] }")).into(),
868-
);
869862
}
870863

871864
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

@@ -145,7 +143,6 @@ impl JsFunction {
145143
pub(crate) fn lazy_intrinsic_function(
146144
constructor: bool,
147145
init: fn(&Realm),
148-
name: JsString,
149146
realm_inner: WeakGc<RealmInner>,
150147
) -> Self {
151148
let kind = if constructor {
@@ -158,11 +155,8 @@ impl JsFunction {
158155
inner: JsObject::from_proto_and_data(
159156
None,
160157
LazyBuiltIn {
161-
init,
162-
is_initialized: Cell::new(false),
158+
init_and_realm: Some((init, realm_inner)),
163159
kind,
164-
name,
165-
realm_inner: Some(realm_inner),
166160
},
167161
),
168162
}

0 commit comments

Comments
 (0)