1. 7 加载 Web 页面
    1. 7.1 Browsing contexts
      1. 7.1.1 Creating browsing contexts
      2. 7.1.2 Related browsing contexts
        1. 7.1.2.1 Navigating related browsing contexts in the DOM
      3. 7.1.3 Security
      4. 7.1.4 浏览上下文分组
      5. 7.1.5 Browsing context names
    2. 7.2 Window, WindowProxy, 和 Location 对象的安全基础设施
      1. 7.2.1 Integration with IDL
      2. 7.2.2 Shared internal slot: [[CrossOriginPropertyDescriptorMap]]
      3. 7.2.3 Shared abstract operations
        1. 7.2.3.1 CrossOriginProperties ( O )
        2. 7.2.3.2 CrossOriginPropertyFallback ( P )
        3. 7.2.3.3 IsPlatformObjectSameOrigin ( O )
        4. 7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P )
        5. 7.2.3.5 CrossOriginGet ( O, P, Receiver )
        6. 7.2.3.6 CrossOriginSet ( O, P, V, Receiver )
        7. 7.2.3.7 CrossOriginOwnPropertyKeys ( O )

7 加载 Web 页面

This section describes features that apply most directly to Web browsers. Having said that, except where specified otherwise, the requirements defined in this section do apply to all user agents, whether they are Web browsers or not.

7.1 Browsing contexts

A browsing context is an environment in which Document objects are presented to the user.

A tab or window in a web browser typically contains a browsing context, as does an iframe or frames in a frameset.

A browsing context has a corresponding WindowProxy object.

A browsing context has an opener browsing context, which is null or a browsing context. It is initially null.

A browsing context has a disowned boolean. It is initially false.

A browsing context has an is closing boolean. It is initially false.

The following example illustrates the various possibilities of a browsing context. It can be disowned, is closing, neither, or both.

// Neither disowned nor is closing:
const popup1 = window.open();

// Disowned, but not is closing:
const popup2 = window.open();
popup2.opener = null;

// Not disowned, but is closing:
const popup3 = window.open();
popup3.close();

// Disowned, is closing:
const popup4 = window.open();
popup4.opener = null;
popup4.close();

A browsing context has a session history, which lists the Document objects that the browsing context has presented, is presenting, or will present. A Document's browsing context is the browsing context whose session history contains the Document, if any such browsing context exists and has not been discarded, and null otherwise.

A Document does not necessarily have a non-null browsing context. In particular, data mining tools are likely to never instantiate browsing contexts. A Document created using an API such as createDocument() never has a non-null browsing context. And the Document originally created for an iframe element, which has since been removed from the document, has no associated browsing context, since that browsing context was discarded.

A browsing context's active window is its WindowProxy object's [[Window]] internal slot value. A browsing context's active document is its active window's associated Document.

In general, there is a 1-to-1 mapping from the Window object to the Document object, as long as the Document object has a non-null browsing context. There is one exception. A Window can be reused for the presentation of a second Document in the same browsing context, such that the mapping is then 1-to-2. This occurs when a browsing context is navigated from the initial about:blank Document to another, with historyHandling set to "replace".

7.1.1 Creating browsing contexts

To set the active document of a browsing context browsingContext to a Document object document, run these steps:

  1. Let window be document's relevant global object.

    Per this standard document can be created before window, which does not make much sense. See issue #2688.

  2. Set browsingContext's active window to window.

  3. Set window's associated Document to document.

  4. Set window's relevant settings object's execution ready flag.


A browsing context has an associated creator origin (null or returns an origin), creator URL (null or returns a URL), and creator base URL (null or returns a URL). These are all initially null.

To determine the origin, given browsing context browsingContext, URL url, sandboxing flag set sandboxFlags, and two origins invocationOrigin and activeDocumentNavigationOrigin:

  1. If sandboxFlags has its sandboxed origin browsing context flag set, then return a new opaque origin.

  2. If url is null, then return a new opaque origin.

  3. If activeDocumentNavigationOrigin is not null, and url's scheme is "javascript", then return activeDocumentNavigationOrigin.

  4. If invocationOrigin is non-null and url is about:blank, then return invocationOrigin.

    The result here is that two documents end up with the same underlying origin, meaning that document.domain affects both.

  5. If url is about:srcdoc, then return the origin of browsingContext's container document.

  6. Return url's origin.

To create a new browsing context, given null or a Document object creator, null or an element embedder, and a browsing context group group, run these steps:

  1. Let browsingContext be a new browsing context.

  2. If creator is non-null, then set browsingContext's creator origin to return creator's origin, browsingContext's creator URL to return creator's URL, and browsingContext's creator base URL to return creator's base URL.

  3. Let sandboxFlags be the result of determining the creation sandboxing flags given browsingContext and embedder.

  4. Let origin be the result of determining the origin given browsingContext, about:blank, sandboxFlags, browsingContext's creator origin, and null.

  5. Let permissionsPolicy be the result of creating a permissions policy given browsingContext and origin. [PERMISSIONSPOLICY]

    This needs to use embedder.

  6. Let agent be the result of obtaining a similar-origin window agent given origin, group, and false.

  7. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:

  8. Let topLevelCreationURL be about:blank if embedder is null; otherwise embedder's relevant settings object's top-level creation URL.

  9. Let topLevelOrigin be origin if embedder is null; otherwise embedder's relevant settings object's top-level origin.

  10. Let settingsObject be the result of setting up a window environment settings object with realm execution context, null, topLevelCreationURL, and topLevelOrigin.

  11. Let coop be "unsafe-none".

  12. If creator is non-null and creator's origin is same origin with creator's relevant settings object's top-level origin, then set coop to creator's browsing context's top-level browsing context's active document's cross-origin opener policy.

  13. Let document be a new Document, marked as an HTML document in quirks mode, whose content type is "text/html", origin is origin, active sandboxing flag set is sandboxFlags, permissions policy is permissionsPolicy, cross-origin opener policy is coop, and which is ready for post-load tasks.

  14. Ensure that document has a single child html node, which itself has two empty child nodes: a head element, and a body element.

  15. Set the active document of browsingContext to document.

  16. If browsingContext's creator URL is non-null, then set document's referrer to the serialization of it.

  17. If creator is non-null, then set document's referrer policy to creator's referrer policy.

  18. If creator is non-null, then set document's embedder policy to creator's embedder policy.

  19. Add document to browsingContext's session history.

  20. Completely finish loading document.

  21. Return browsingContext.

To create a new top-level browsing context:

  1. Let group be the result of creating a new browsing context group.

  2. Return group's browsing context set[0].

This creates a top-level browsing context.

To create a new auxiliary browsing context, given a browsing context opener:

  1. Let group be opener's top-level browsing context's group

  2. Assert: group is non-null, as navigating invokes this directly.

  3. Let browsingContext be the result of creating a new browsing context with opener's active document, null, and group.

  4. Append browsingContext to group.

  5. Set browsingContext's opener browsing context to opener.

  6. Legacy-clone a browsing session storage shed with opener's browsing session and browsingContext's browsing session. [STORAGE]

  7. Return browsingContext.

This creates a top-level browsing context that is also an auxiliary browsing context.

To create a new nested browsing context, given an element element:

  1. Let group be element's node document's browsing context's top-level browsing context's group.

  2. Let browsingContext be the result of creating a new browsing context with element's node document, element, and group.

  3. Set element's nested browsing context to browsingContext.

  4. If element has a name attribute, then set browsingContext's name to the value of this attribute.

7.1.2 Related browsing contexts

Certain elements (for example, iframe elements) can instantiate further browsing contexts. These elements are called browsing context containers.

Each browsing context container has a nested browsing context, which is either a browsing context or null. It is initially null.

The container of a browsing context bc is the browsing context container whose nested browsing context is bc, or null if there is no such element.

Each browsing context bc has a container document, which is the result of running these steps:

  1. If bc's container is null, then return null.

  2. Return bc's container's node document.

    This is equal to bc's container's shadow-including root as bc's container has to be connected.

A browsing context child is said to be a child browsing context of another browsing context parent, if child's container document is non-null and child's container document's browsing context is parent.

A browsing context child is a document-tree child browsing context of parent if child is a child browsing context and child's container is in a document tree.

A browsing context child may have a parent browsing context. This is the unique browsing context that has child as a child browsing context, if any such browsing context exists. Otherwise, the browsing context has no parent browsing context.

A browsing context A is said to be an ancestor of a browsing context B if there exists a browsing context A' that is a child browsing context of A and that is itself an ancestor of B, or if the browsing context A is the parent browsing context of B.

A browsing context that has no parent browsing context is the top-level browsing context for itself and all of the browsing contexts for which it is an ancestor browsing context.

A top-level browsing context has an associated group (null or a browsing context group). It is initially null.

It is possible to create new browsing contexts that are related to a top-level browsing context while their container is null. Such browsing contexts are called auxiliary browsing contexts. Auxiliary browsing contexts are always top-level browsing contexts.

The transitive closure of parent browsing contexts for a browsing context that is a child browsing context gives the list of ancestor browsing contexts.

The list of the descendant browsing contexts of a Document d is the (ordered) list returned by the following algorithm:

  1. Let list be an empty list.

  2. For each browsing context container container, whose nested browsing context is non-null and whose shadow-including root is d, in shadow-including tree order:

    1. Let nestedBC be container's nested browsing context.

    2. Append nestedBC to list.

    3. Extend list with the list of the descendant browsing contexts of nestedBC's active document.

  3. Return list.

A Document d is said to be fully active when d's browsing context is non-null, d's browsing context's active document is d, and either d's browsing context is a top-level browsing context, or d's container document is fully active.

Because they are associated with an element, child browsing contexts are always tied to a specific Document in their parent browsing context. User agents must not allow the user to interact with child browsing contexts of elements that are in Documents that are not themselves fully active.

The following example illustrates the differences between active and fully active Document objects. Here a.html is loaded into a browser window, b-1.html starts out loaded into an iframe as shown, and b-2.html and c.html are omitted (they can simply be an empty document).

<!-- a.html -->
<!DOCTYPE html>
<html lang="en">
<title>Browsing context A</title>

<iframe src="b-1.html"></iframe>
<button onclick="frames[0].location.href = 'b-2.html'">Click me</button>

<!-- b-1.html -->
<!DOCTYPE html>
<html lang="en">
<title>Browsing context B</title>

<iframe src="c.html"></iframe>

At this point, the documents given by a.html, b-1.html, and c.html are all the active documents of their respective browsing contexts. They are also all fully active.

After clicking on the button, and thus loading a new Document from b-2.html into browsing context B, we have the following results:

For more explorations of the complexities involved here, especially as it impacts the session history, see A Model of Navigation History. [NAVMODEL]

A child browsing context can be put into a delaying load events mode. This is used when it is navigated, to delay the load event of its container before the new Document is created.

The document family of a browsing context consists of the union of all the Document objects in that browsing context's session history and the document families of all those Document objects. The document family of a Document object consists of the union of all the document families of the browsing contexts in the list of the descendant browsing contexts of the Document object.

The content document of a browsing context container container is the result of the following algorithm:

  1. If container's nested browsing context is null, then return null.

  2. Let context be container's nested browsing context.

  3. Let document be context's active document.

  4. If document's origin and container's node document's origin are not same origin-domain, then return null.

  5. Return document.

window . top

Window/top

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer4+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android12.1+

Returns the WindowProxy for the top-level browsing context.

window . opener [ = value ]

Window/opener

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android10.1+

Returns the WindowProxy for the opener browsing context.

Returns null if there isn't one or if it has been set to null.

Can be set to null.

window . parent

Window/parent

Support in all current engines.

Firefox1+Safari1.3+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android10.1+

Returns the WindowProxy for the parent browsing context.

window . frameElement

Window/frameElement

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android12.1+

Returns the Element for the browsing context container.

Returns null if there isn't one, and in cross-origin situations.

The top attribute's getter must run these steps:

  1. If this Window object's browsing context is null, then return null.

  2. Return this Window object's browsing context's top-level browsing context's WindowProxy object.

The opener attribute's getter must run these steps:

  1. Let current be this Window object's browsing context.

  2. If current is null, then return null.

  3. If current's disowned is true, then return null.

  4. If current's opener browsing context is null, then return null.

  5. Return current's opener browsing context's WindowProxy object.

The opener attribute's setter must run these steps:

  1. If the given value is null and this Window object's browsing context is non-null, then set this Window object's browsing context's disowned to true.

  2. If the given value is non-null, then return ? OrdinaryDefineOwnProperty(this Window object, "opener", { [[Value]]: the given value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }).

If a browsing context's disowned is true, its window.opener attribute is null. That prevents scripts in the browsing context from changing any properties of its opener browsing context's Window object (i.e., the Window object from which the browsing context was created).

Otherwise, if a browsing context's disowned is false, then scripts in that browsing context can use window.opener to change properties of its opener browsing context's Window object. For example, a script running in the browsing context can change the value of window.opener.location, causing the opener browsing context to navigate to a completely different document.

The parent attribute's getter must run these steps:

  1. Let current be this Window object's browsing context.

  2. If current is null, then return null.

  3. If current is a child browsing context of another browsing context parent, then return parent's WindowProxy object.

  4. Assert: current is a top-level browsing context.

  5. Return current's WindowProxy object.

The frameElement attribute's getter must run these steps:

  1. Let current be this Window object's browsing context.

  2. If current is null, then return null.

  3. Let container be current's container.

  4. If container is null, then return null.

  5. If container's node document's origin is not same origin-domain with the current settings object's origin, then return null.

  6. Return container.

An example of when these IDL attributes can return null is as follows:

<!DOCTYPE html>
<iframe></iframe>

<script>
"use strict";
const element = document.querySelector("iframe");
const iframeWindow = element.contentWindow;
element.remove();

console.assert(iframeWindow.top === null);
console.assert(iframeWindow.parent === null);
console.assert(iframeWindow.frameElement === null);
</script>

Here the browsing context corresponding to iframeWindow was discarded when element was removed from the document.

7.1.3 Security

A browsing context A is familiar with a second browsing context B if one of the following conditions is true:


A browsing context A is allowed to navigate a second browsing context B if the following algorithm returns true:

  1. If A is not the same browsing context as B, and A is not one of the ancestor browsing contexts of B, and B is not a top-level browsing context, and A's active document's active sandboxing flag set has its sandboxed navigation browsing context flag set, then return false.

  2. Otherwise, if B is a top-level browsing context, and is one of the ancestor browsing contexts of A, then:

    1. If A's active window has transient activation and A's active document's active sandboxing flag set has its sandboxed top-level navigation with user activation browsing context flag set, then return false.

    2. Otherwise, if A's active window does not have transient activation and A's active document's active sandboxing flag set has its sandboxed top-level navigation without user activation browsing context flag set, then return false.

  3. Otherwise, if B is a top-level browsing context, and is neither A nor one of the ancestor browsing contexts of A, and A's Document's active sandboxing flag set has its sandboxed navigation browsing context flag set, and A is not the one permitted sandboxed navigator of B, then return false.

  4. Return true.


An element has a browsing context scope origin if its Document's browsing context is a top-level browsing context or if all of its Document's ancestor browsing contexts all have active documents whose origin are the same origin as the element's node document's origin. If an element has a browsing context scope origin, then its value is the origin of the element's node document.

7.1.4 浏览上下文分组

用户代理持有 浏览上下文分组的集合 (一个 浏览上下文分组集合)。

浏览上下文分组 持有 浏览上下文集合 (一个 顶级浏览上下文集合)。

创建分组时顶级浏览上下文 添加到 组内。 所有后续添加到 组内顶级浏览上下文 都是 附属浏览上下文

浏览上下文组 有一个关联的 代理群映射 (一个 代理群的键代理群 的弱 映射)。 用户代理负责收集已经没有地方能访问的代理群。

浏览上下文组 有一个 跨域隔离 布尔,初始为 false。

浏览上下文组 有一个关联的 历史代理群键映射,是一个 代理群键映射。 通过记录哪些代理群键之前用于给定的源,这个映射用于确保 域隔离 特性的一致性。

历史代理群键映射 的条目只能在浏览上下文组的生命期内获得。

创建浏览上下文组 要执行以下步骤:

  1. group 为一个新的 浏览上下文组

  2. group 到用户代理的 浏览上下文组集合

  3. browsingContext 为用 null, null 和 group 创建新的浏览上下文 的结果。

  4. browsingContext group

  5. 返回 group

顶级浏览上下文 browsingContext 浏览上下文组 group 的步骤如下:

  1. browsingContext 加到 group浏览上下文集合

  2. 设置 browsingContextgroupgroup

移除 顶级浏览上下文 browsingContext 的步骤如下:

  1. 断言 browsingContextgroup 非空,因为 浏览环境 只能 丢弃 一次。

  2. groupbrowsingContextgroup

  3. 设置 browsingContextgroup 为 null。

  4. group浏览上下文集合 移除 browsingContext

  5. 如果 group浏览上下文集合 为空,就从用户代理的 浏览上下文组集合移除 group

追加移除 是定义 浏览上下文组 生命期的基本操作, 会被 创建浏览上下文组创建附属浏览上下文丢弃浏览上下文 调用。


HTML 标准层定义过 "相关浏览上下文单元" 和 "相关 similar-origin 浏览上下文单元"。 因为它们不够充分已经被移除。

7.1.5 Browsing context names

Browsing contexts can have a browsing context name. Unless stated otherwise, it is the empty string.

A valid browsing context name is any string with at least one character that does not start with a U+005F LOW LINE character. (Names starting with an underscore are reserved for special keywords.)

A valid browsing context name or keyword is any string that is either a valid browsing context name or that is an ASCII case-insensitive match for one of: _blank, _self, _parent, or _top.

These values have different meanings based on whether the page is sandboxed or not, as summarized in the following (non-normative) table. In this table, "current" means the browsing context that the link or script is in, "parent" means the parent browsing context of the one the link or script is in, "top" means the top-level browsing context of the one the link or script is in, "new" means a new top-level browsing context or auxiliary browsing context is to be created, subject to various user preferences and user agent policies, "none" means that nothing will happen, and "maybe new" means the same as "new" if the "allow-popups" keyword is also specified on the sandbox attribute (or if the user overrode the sandboxing), and the same as "none" otherwise.

Keyword Ordinary effect Effect in an iframe with...
sandbox="" sandbox="allow-top-navigation"
none specified, for links and form submissions current current current
empty string current current current
_blank new maybe new maybe new
_self current current current
_parent if there isn't a parent current current current
_parent if parent is also top parent/top none parent/top
_parent if there is one and it's not top parent none none
_top if top is current current current current
_top if top is not current top none top
name that doesn't exist new maybe new maybe new
name that exists and is a descendant specified descendant specified descendant specified descendant
name that exists and is current current current current
name that exists and is an ancestor that is top specified ancestor none specified ancestor/top
name that exists and is an ancestor that is not top specified ancestor none none
other name that exists with common top specified none none
name that exists with different top, if familiar and one permitted sandboxed navigator specified specified specified
name that exists with different top, if familiar but not one permitted sandboxed navigator specified none none
name that exists with different top, not familiar new maybe new maybe new

Most of the restrictions on sandboxed browsing contexts are applied by other algorithms, e.g. the navigation algorithm, not the rules for choosing a browsing context given below.


The rules for choosing a browsing context, given a browsing context name name, a browsing context current, and a boolean noopener are as follows:

  1. Let chosen be null.

  2. Let windowType be "existing or none".

  3. Let sandboxingFlagSet be current's active document's active sandboxing flag set.

  4. If name is the empty string or an ASCII case-insensitive match for "_self", then set chosen to current.

  5. Otherwise, if name is an ASCII case-insensitive match for "_parent", set chosen to current's parent browsing context, if any, and current otherwise.

  6. Otherwise, if name is an ASCII case-insensitive match for "_top", set chosen to current's top-level browsing context, if any, and current otherwise.

  7. Otherwise, if name is not an ASCII case-insensitive match for "_blank", there exists a browsing context whose name is the same as name, current is familiar with that browsing context, and the user agent determines that the two browsing contexts are related enough that it is ok if they reach each other, set chosen to that browsing context. If there are multiple matching browsing contexts, the user agent should set chosen to one in some arbitrary consistent manner, such as the most recently opened, most recently focused, or more closely related.

    This will be made more precise in issue #313.

  8. Otherwise, a new browsing context is being requested, and what happens depends on the user agent's configuration and abilities — it is determined by the rules given for the first applicable option from the following list:

    The user agent may inform the user that a popup has been blocked.

    If sandboxingFlagSet has the sandboxed auxiliary navigation browsing context flag set

    The user agent may report to a developer console that a popup has been blocked.

    If the user agent has been configured such that in this instance it will create a new browsing context
    1. Set windowType to "new and unrestricted".

    2. If current's top-level browsing context's active document's cross-origin opener policy is "same-origin" or "same-origin-plus-COEP", then:

      1. Let currentDocument be current's active document.

      2. If currentDocument's origin is not same origin with currentDocument's relevant settings object's top-level origin, then set noopener to true, name to "_blank", and windowType to "new with no opener".

        In the presence of a cross-origin opener policy, nested documents that are cross-origin with their top-level browsing context's active document always set noopener to true.

    3. If noopener is true, then set chosen to the result of creating a new top-level browsing context.

    4. Otherwise:

      1. Set chosen to the result of creating a new auxiliary browsing context with current.

      2. If sandboxingFlagSet's sandboxed navigation browsing context flag is set, then current must be set as chosen's one permitted sandboxed navigator.

    5. If sandboxingFlagSet's sandbox propagates to auxiliary browsing contexts flag is set, then all the flags that are set in sandboxingFlagSet must be set in chosen's popup sandboxing flag set.

    6. If name is not an ASCII case-insensitive match for "_blank", then set chosen's name to name.

    If the newly created browsing context is immediately navigated, then the navigation will be done with historyHandling set to "replace".

    If the user agent has been configured such that in this instance it will reuse current

    Set chosen to current.

    If the user agent has been configured such that in this instance it will not find a browsing context

    Do nothing.

    User agents are encouraged to provide a way for users to configure the user agent to always reuse current.

  9. Return chosen and windowType.

7.2 Window, WindowProxy, 和 Location 对象的安全基础设施

尽管通常不可以跨 访问对象, 但 Web 平台必须考虑遗留的那些例外情况。

7.2.1 Integration with IDL

When perform a security check is invoked, with a platformObject, identifier, and type, run these steps:

  1. If platformObject is not a Window or Location object, then return.

  2. For each e of ! CrossOriginProperties(platformObject):

    1. If SameValue(e.[[Property]], identifier) is true, then:

      1. If type is "method" and e has neither [[NeedsGet]] nor [[NeedsSet]], then return.

      2. Otherwise, if type is "getter" and e.[[NeedsGet]] is true, then return.

      3. Otherwise, if type is "setter" and e.[[NeedsSet]] is true, then return.

  3. If ! IsPlatformObjectSameOrigin(platformObject) is false, then throw a "SecurityError" DOMException.

7.2.2 Shared internal slot: [[CrossOriginPropertyDescriptorMap]]

Window and Location objects both have a [[CrossOriginPropertyDescriptorMap]] internal slot, whose value is initially an empty map.

The [[CrossOriginPropertyDescriptorMap]] internal slot contains a map with entries whose keys are (currentGlobal, objectGlobal, propertyKey)-tuples and values are property descriptors, as a memoization of what is visible to scripts when currentGlobal inspects a Window or Location object from objectGlobal. It is filled lazily by CrossOriginGetOwnPropertyHelper, which consults it on future lookups.

User agents should allow a value held in the map to be garbage collected along with its corresponding key when nothing holds a reference to any part of the value. That is, as long as garbage collection is not observable.

For example, with const href = Object.getOwnPropertyDescriptor(crossOriginLocation, "href").set the value and its corresponding key in the map cannot be garbage collected as that would be observable.

User agents may have an optimization whereby they remove key-value pairs from the map when document.domain is set. This is not observable as document.domain cannot revisit an earlier value.

For example, setting document.domain to "example.com" on www.example.com means user agents can remove all key-value pairs from the map where part of the key is www.example.com, as that can never be part of the origin again and therefore the corresponding value could never be retrieved from the map.

7.2.3 Shared abstract operations

7.2.3.1 CrossOriginProperties ( O )
  1. Assert: O is a Location or Window object.

  2. If O is a Location object, then return « { [[Property]]: "href", [[NeedsGet]]: false, [[NeedsSet]]: true }, { [[Property]]: "replace" } ».

  3. Return « { [[Property]]: "window", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "self", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "location", [[NeedsGet]]: true, [[NeedsSet]]: true }, { [[Property]]: "close" }, { [[Property]]: "closed", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "focus" }, { [[Property]]: "blur" }, { [[Property]]: "frames", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "length", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "top", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "opener", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "parent", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "postMessage" } ».

Indexed properties do not need to be safelisted as they are handled directly by the WindowProxy object.

7.2.3.2 CrossOriginPropertyFallback ( P )
  1. If P is "then", @@toStringTag, @@hasInstance, or @@isConcatSpreadable, then return PropertyDescriptor{ [[Value]]: undefined, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

  2. Throw a "SecurityError" DOMException.

7.2.3.3 IsPlatformObjectSameOrigin ( O )
  1. Return true if the current settings object's origin is same origin-domain with O's relevant settings object's origin, and false otherwise.

Here the current settings object roughly corresponds to the "caller", because this check occurs before the execution context for the getter/setter/method in question makes its way onto the JavaScript execution context stack. For example, in the code w.document, this step is invoked before the document getter is reached as part of the [[Get]] algorithm for the WindowProxy w.

7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P )

If this abstract operation returns undefined and there is no custom behavior, the caller needs to throw a "SecurityError" DOMException. In practice this is handled by the caller calling CrossOriginPropertyFallback.

  1. Let crossOriginKey be a tuple consisting of the current settings object, O's relevant settings object, and P.

  2. For each e of ! CrossOriginProperties(O):

    1. If SameValue(e.[[Property]], P) is true, then:

      1. If the value of the [[CrossOriginPropertyDescriptorMap]] internal slot of O contains an entry whose key is crossOriginKey, then return that entry's value.

      2. Let originalDesc be OrdinaryGetOwnProperty(O, P).

      3. Let crossOriginDesc be undefined.

      4. If e.[[NeedsGet]] and e.[[NeedsSet]] are absent, then:

        1. Let value be originalDesc.[[Value]].

        2. If ! IsCallable(value) is true, then set value to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the IDL operation P on object O.

        3. Set crossOriginDesc to PropertyDescriptor{ [[Value]]: value, [[Enumerable]]: false, [[Writable]]: false, [[Configurable]]: true }.

      5. Otherwise:

        1. Let crossOriginGet be undefined.

        2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.

        3. Let crossOriginSet be undefined.

        4. If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.

        5. Set crossOriginDesc to PropertyDescriptor{ [[Get]]: crossOriginGet, [[Set]]: crossOriginSet, [[Enumerable]]: false, [[Configurable]]: true }.

      6. Create an entry in the value of the [[CrossOriginPropertyDescriptorMap]] internal slot of O with key crossOriginKey and value crossOriginDesc.

      7. Return crossOriginDesc.

  3. Return undefined.

The reason that the property descriptors produced here are configurable is to preserve the invariants of the essential internal methods required by the JavaScript specification. In particular, since the value of the property can change as a consequence of navigation, it is required that the property be configurable. (However, see tc39/ecma262 issue #672 and references to it elsewhere in this specification for cases where we are not able to preserve these invariants, for compatibility with existing web content.) [JAVASCRIPT]

The reason the property descriptors are non-enumerable, despite this mismatching the same-origin behavior, is for compatibility with existing web content. See issue #3183 for details.

7.2.3.5 CrossOriginGet ( O, P, Receiver )
  1. Let desc be ? O.[[GetOwnProperty]](P).

  2. Assert: desc is not undefined.

  3. If ! IsDataDescriptor(desc) is true, then return desc.[[Value]].

  4. Assert: IsAccessorDescriptor(desc) is true.

  5. Let getter be desc.[[Get]].

  6. If getter is undefined, then throw a "SecurityError" DOMException.

  7. Return ? Call(getter, Receiver).

7.2.3.6 CrossOriginSet ( O, P, V, Receiver )
  1. Let desc be ? O.[[GetOwnProperty]](P).

  2. Assert: desc is not undefined.

  3. If desc.[[Set]] is present and its value is not undefined, then:

    1. Perform ? Call(setter, Receiver, «V»).

    2. Return true.

  4. Throw a "SecurityError" DOMException.

7.2.3.7 CrossOriginOwnPropertyKeys ( O )
  1. Let keys be a new empty List.

  2. For each e of ! CrossOriginProperties(O), append e.[[Property]] to keys.

  3. Return the concatenation of keys and « "then", @@toStringTag, @@hasInstance, @@isConcatSpreadable ».