55use super :: {
66 internal_methods:: { InternalMethodContext , InternalObjectMethods , ORDINARY_INTERNAL_METHODS } ,
77 shape:: RootShape ,
8- JsPrototype , LazyBuiltIn , LazyPrototype , NativeObject , Object , PrivateName , PropertyMap ,
8+ BuiltinKind , JsPrototype , LazyBuiltIn , LazyPrototype , NativeObject , Object , PrivateName ,
9+ PropertyMap ,
910} ;
1011use crate :: {
1112 builtins:: {
@@ -17,10 +18,11 @@ use crate::{
1718 error:: JsNativeError ,
1819 js_string,
1920 property:: { PropertyDescriptor , PropertyKey } ,
21+ realm:: { Realm , RealmInner } ,
2022 value:: PreferredType ,
2123 Context , JsResult , JsString , JsValue ,
2224} ;
23- use boa_gc:: { self , Finalize , Gc , GcBox , GcRefCell , Trace } ;
25+ use boa_gc:: { self , Finalize , Gc , GcBox , GcRefCell , Trace , WeakGc } ;
2426use boa_macros:: js_str;
2527use std:: {
2628 cell:: RefCell ,
@@ -92,8 +94,20 @@ impl JsObject {
9294 inner : coerce_gc ( gc) ,
9395 }
9496 }
97+
98+ /// Creates a new lazy `JsObject` from its inner object and its vtable.
99+ /// This object will call init([realm]) when it's first accessed
100+ pub ( crate ) fn lazy ( init : fn ( & Realm ) -> ( ) , realm_inner : & WeakGc < RealmInner > ) -> Self {
101+ let data = LazyBuiltIn {
102+ init_and_realm : Some ( ( init, realm_inner. clone ( ) ) ) ,
103+ kind : BuiltinKind :: Ordinary ,
104+ } ;
105+
106+ Self :: from_proto_and_data ( None , data)
107+ }
108+
95109 /// Creates a new lazy `JsObject` from its inner object and its vtable.
96- /// This is used for built-in objects that are lazily initialized .
110+ /// This is used for built-in objects that are prototypes of Constructors .
97111 pub ( crate ) fn lazy_prototype ( constructor : JsObject < LazyBuiltIn > ) -> Self {
98112 Self :: from_proto_and_data ( None , LazyPrototype { constructor } )
99113 }
0 commit comments