How can the global window object be created before there is a realm in existance?

169 views Asked by At

Background

When a browser opens a new window or tab, a new browsing context is created.

As we can see from the HTML spec, the operation that creates a new browsing context calls another operation that creates a new realm, which in turn calls the operation InitializeHostDefinedRealm defined in the ECMAScript spec.

The HTML spec operation that creates the browsing context states that when a new realm is created it should be done with a new Window object as the global object, and a WindowProxy object as the global this value.

Within InitializeHostDefinedRealm, we see that a new realm is created in step 1. In step 7, the global object is created in a host-defined manner.

If we take a look at the Web IDL spec, we can see how platform objects (instances of interface objects) are created.

For it to be possible for a platform object (like the global object window) to be created, the corresponding interface object (which is a function object) must have been created previously via the operation for creating interface objects. This is because the latter operation creates the interface prototype object for the interface.

Taking it back to the global object, creating the interface object Window will create Window.prototype, which will be used when the platform object window (an instance of interface object Window) is created.

Lastly, we also know from the operation that creates platform objects that the operation requires realm.[[GlobalObject]] to be present, for instance to check if an interface member is Exposed on a realm: Create platform object (see step 10.1) > Add Regular operations that are exposed on Window (see step 1.1) > exposed definition

Questions

  1. In InitializeHostDefinedRealm, realm.[[GlobalObject]] is not set until after the host has created the new Window object (step 9 vs step 7). realm.[[GlobalObject]] cannot be set without a global object present, and the global object window cannot be created without realm.[[GlobalObject]] present. How is this apparent deadlock solved?

  2. Step 9 of the operation that creates a browsing context states that a new Window object should be created as the global object, without any further details on how that is accomplished. Does it imply that the browser first creates the Window interface object and then the corresponding window platform object?

0

There are 0 answers