So the current proposal copies whatever the prototype of the parent global is, but this doesn't seem particularly useful in practice given that global objects like window/self also need associated internal slots for their prototype methods to even work.
e.g. All this does is result in an error due to missing the relevant EventTarget internal slots:
const o = Object.assign({ __proto__: Object.getPrototypeOf(window) }, globalThis);
// TypeError, addEventListener called on incompatible receiver
o.addEventListener("message", console.log);
It could be an option to allow hosts to actually add the internal slots to new Global() objects such that things like the above would work, but this leads to further unclear situations as to what various such methods do. Like should browsers fire "message" events on every global object in the root realm? If not then the addition of these methods effectively just does nothing and it would be better if whoever called new Global() simply defined a new prototype that correctly delegated to the original global.
So the current proposal copies whatever the prototype of the parent global is, but this doesn't seem particularly useful in practice given that global objects like
window/selfalso need associated internal slots for their prototype methods to even work.e.g. All this does is result in an error due to missing the relevant
EventTargetinternal slots:It could be an option to allow hosts to actually add the internal slots to
new Global()objects such that things like the above would work, but this leads to further unclear situations as to what various such methods do. Like should browsers fire"message"events on every global object in the root realm? If not then the addition of these methods effectively just does nothing and it would be better if whoever callednew Global()simply defined a new prototype that correctly delegated to the original global.