The (hookable) eval
/Function
function objects, the global object, and the realm all have to be in 1:1 correspondence.
(a) same realm ==> same Function
Since Function
is reachable by function literals, it is tied to a realm.
(b) same realm ==> same eval
Since the semantics of the direct eval
syntax checks the object identity of the original eval
function object, it is tied to a realm.
(c) same realm ==> same global object
Since Function
and indirect eval
are implicitly "closed over" a global object (i.e., they evaluate code in the scope of a fixed global object), it shouldn't be possible for two loaders to share a realm but have different globals, as the Function
constructor would use the wrong global in one of them.
(d) same global ==> same realm
It's pretty hard to imagine writing sensible code where new Array
and []
or new Object
and {}
have distinct prototypes. While technically we could imagine breaking this invariant, real-world JS depends on basic built-in classes like Array being there and behaving predictably.