Skip to content

Commit 1c4cc00

Browse files
committed
Feeding realm through into the build function
1 parent ac4c15b commit 1c4cc00

File tree

5 files changed

+246
-102
lines changed

5 files changed

+246
-102
lines changed

core/engine/src/builtins/builder.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,6 @@ impl BuiltInConstructorWithPrototype<'_> {
387387
}
388388

389389
let mut object = self.object.borrow_mut();
390-
let built_in = object
391-
.downcast_mut::<BuiltIn>()
392-
.expect("Builtin must be a function object");
393-
built_in.realm = Some(self.realm.clone());
394390
object
395391
.properties_mut()
396392
.shape

core/engine/src/context/intrinsics.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Data structures that contain intrinsic objects and constructors.
22
3-
use boa_gc::{Finalize, Trace};
3+
use boa_gc::{Finalize, Trace, WeakGc};
44
use boa_macros::js_str;
55

66
use crate::{
@@ -14,7 +14,7 @@ use crate::{
1414
JsFunction, JsObject, Object, CONSTRUCTOR, PROTOTYPE,
1515
},
1616
property::{Attribute, PropertyKey},
17-
realm::Realm,
17+
realm::{Realm, RealmInner},
1818
JsSymbol,
1919
};
2020

@@ -43,8 +43,8 @@ impl Intrinsics {
4343
/// To initialize all the intrinsics with their spec properties, see [`Realm::initialize`].
4444
///
4545
/// [`Realm::initialize`]: crate::realm::Realm::initialize
46-
pub(crate) fn uninit(root_shape: &RootShape) -> Option<Self> {
47-
let constructors = StandardConstructors::default();
46+
pub(crate) fn uninit(root_shape: &RootShape, realm_inner: WeakGc<RealmInner>) -> Option<Self> {
47+
let constructors = StandardConstructors::new(realm_inner);
4848
let templates = ObjectTemplates::new(root_shape, &constructors);
4949

5050
Some(Self {
@@ -99,9 +99,9 @@ impl StandardConstructor {
9999
}
100100

101101
/// Similar to `with_prototype`, but the prototype is lazily initialized.
102-
fn with_lazy(init: fn(&Realm) -> ()) -> Self {
102+
fn with_lazy(init: fn(&Realm) -> (), realm_inner: WeakGc<RealmInner>) -> Self {
103103
Self {
104-
constructor: JsFunction::lazy_intrinsic_function(true, init),
104+
constructor: JsFunction::lazy_intrinsic_function(true, init, realm_inner),
105105
prototype: JsObject::default(),
106106
}
107107
}
@@ -214,8 +214,8 @@ pub struct StandardConstructors {
214214
calendar: StandardConstructor,
215215
}
216216

217-
impl Default for StandardConstructors {
218-
fn default() -> Self {
217+
impl StandardConstructors {
218+
fn new(realm_inner: WeakGc<RealmInner>) -> Self {
219219
Self {
220220
object: StandardConstructor::with_prototype(JsObject::from_object_and_vtable(
221221
Object::<OrdinaryObject>::default(),
@@ -230,7 +230,7 @@ impl Default for StandardConstructors {
230230
},
231231
async_function: StandardConstructor::default(),
232232
generator_function: StandardConstructor::default(),
233-
array: StandardConstructor::with_lazy(Array::init),
233+
array: StandardConstructor::with_lazy(Array::init, realm_inner),
234234
bigint: StandardConstructor::default(),
235235
number: StandardConstructor::with_prototype(JsObject::from_proto_and_data(None, 0.0)),
236236
boolean: StandardConstructor::with_prototype(JsObject::from_proto_and_data(

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! A Rust API wrapper for Boa's `Function` Builtin ECMAScript Object
2-
use crate::realm::Realm;
2+
use crate::realm::{Realm, RealmInner};
33
use crate::{
44
builtins::function::ConstructorKind, native_function::NativeFunctionObject, object::JsObject,
55
value::TryFromJs, Context, JsNativeError, JsResult, JsValue, NativeFunction, TryIntoJsResult,
66
};
7-
use boa_gc::{Finalize, Trace};
7+
use boa_gc::{Finalize, Trace, WeakGc};
88
use std::cell::Cell;
99
use std::marker::PhantomData;
1010
use std::ops::Deref;
@@ -105,15 +105,19 @@ impl JsFunction {
105105

106106
/// Creates a new, lazy intrinsic functionobject with only its function internal methods set.
107107
/// When the function is accessed it will call init from the procided init function
108-
pub(crate) fn lazy_intrinsic_function(constructor: bool, init: fn(&Realm)) -> Self {
108+
pub(crate) fn lazy_intrinsic_function(
109+
constructor: bool,
110+
init: fn(&Realm),
111+
realm_inner: WeakGc<RealmInner>,
112+
) -> Self {
109113
Self {
110114
inner: JsObject::from_proto_and_data(
111115
None,
112116
BuiltIn {
113117
init,
114118
is_initialized: Cell::new(false),
115119
kind: BuiltinKind::Constructor(Self::empty_intrinsic_function(constructor)),
116-
realm: None,
120+
realm_inner: Some(realm_inner),
117121
},
118122
),
119123
}

0 commit comments

Comments
 (0)