You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the strawman (from @dherman), this method was so that:
a) there could be a default init() method that _does_ populate the global object with the standard library
b) it's trivial to override to have an empty global object
In other words, it allows whitelisting, but it still has nice default behavior, e.g.:
when you say
constrealm=newRealm();
you get a realm where e.g. realm.global.Array === realm.intrinsics.ArrayConstructor
when you say
classEmptyRealmextendsRealm{init(){/* do nothing */}};constrealm=newEmptyRealm();
you get a realm where e.g. !('Array' in realm.global)
Other notes
This method is not suppose to be called of the realm object. Can this be implemented via inheritance? or should this be a symbol or something?
The text was updated successfully, but these errors were encountered:
Using a symbol: this, although viable, seems to be overkilled, doesn't buy us much in terms of restricting access to the method, and will probably be confusing compared to the other hooks.
Using a configuration during construction: this is not viable because we will loose the inheritance aspect, which seems to be important.
Resolution
We have settle on using init as the method name that can be redefined when subclassing Realm. The default implementation will set up all default intrinsics by calling SetDefaultGlobalBindings abstract operation on the realm.
As a side effect, if you have access to the realm object, you should be able to call init() method at any given time, as a result, it should attempt to re-add the standard library to the realm's global object, but there is not guarantee that the operation will work since the global object might have been mutated to prevent such redefinitions.
Rationale
From the strawman (from @dherman), this method was so that:
a) there could be a default
init()
method that _does_ populate the global object with the standard libraryb) it's trivial to override to have an empty global object
In other words, it allows whitelisting, but it still has nice default behavior, e.g.:
you get a realm where e.g.
realm.global.Array === realm.intrinsics.ArrayConstructor
when you say
you get a realm where e.g.
!('Array' in realm.global)
Other notes
This method is not suppose to be called of the realm object. Can this be implemented via inheritance? or should this be a symbol or something?
The text was updated successfully, but these errors were encountered: