Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init() method #10

Closed
caridy opened this issue May 3, 2016 · 1 comment
Closed

init() method #10

caridy opened this issue May 3, 2016 · 1 comment
Labels

Comments

@caridy
Copy link
Collaborator

caridy commented May 3, 2016

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 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
const realm = new Realm();

you get a realm where e.g. realm.global.Array === realm.intrinsics.ArrayConstructor

when you say

class EmptyRealm extends Realm { init() { /* do nothing */ } };
const realm = new EmptyRealm();

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?

@caridy caridy added the question label May 3, 2016
@caridy
Copy link
Collaborator Author

caridy commented May 10, 2016

Other options

  • 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.

All this is spec'd already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant