tc39 / proposal-ses

Draft proposal for SES (Secure EcmaScript)
222 stars 20 forks source link

Relationship between spawned realm objects and their parent realm object #26

Open caridy opened 8 years ago

caridy commented 8 years ago

Based on the new realm API, these are some of the questions:

Question 1: getPrototypeOf

Object.getPrototypeOf(spawnedRealmObj) === parentRealmObj; // true or false?

answer: true

Question 2: constructor

Can spawned realms be created in user-land using an API other than parentRealm.spawn()?

Question 3: hooks

Can spawned realms define custom hooks for indirect eval and direct eval?

Question 4: init

Should init() method attempt to set intrinsics (from parent realm) into fresh global? or should it attempt to set intrinsics in the parent realm's global object? e.g.:

spawnedRealmObj.init();

Question 5: eval method

spawnedRealmObj.eval === parentRealmObj.eval; // based on the current realm spec, this can be true.

answer: yes, this is plausible.

caridy commented 8 years ago

update1: this was updated to reflect some of the consensus from yesterday's meeting. We still need answer for q2, q3, and q4.

erights commented 8 years ago

q4 is clearest. The init method on the spawned realm should definitely not attempt to side effect any state in the parent. In any case, when the parent is transitively immutable, any such attempt must fail anyway.

erights commented 8 years ago

q3 yes. In general spawned realms should be full fledged realms that differ in how they are constructed, and therefore in what initial state they start with. Once initialized, ideally, they function just as any other realm object would.

Unless there's a reason not to of course. Does such uniformity create any problems?

erights commented 8 years ago

q2 not currently AFAIK. The frozen realm proposal does not itself need to provide any such means. If the realm API evolves into something that is sufficiently expressive that the answer to q2 is yes, that would probably be good. But I don't think it affects the frozen realm proposal.

caridy commented 8 years ago

q2 is sound good to me, we can eventually introduce an API to create spawn realms. The only issue is that this is related to q3 in the sense that the hooks are extracted from the this during construction, and allocated into the Realm Record, this will make impossible for the current spec to provide custom hooks for spawned realms because they have a very peculiar construction process.

caridy commented 8 years ago

As for q4, if you have access to the spawned realm, you can always do:

let parentGlobal = Object.getPrototypeOf(spawnRealm.global);
Object.defineProperties(parentGlobal, spawnRealm.stdlibs);

which is equivalent to calling spawnRealm.init(), whether that fails or not depends on the state of the global object.