Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relevant global object #3613

Open
annevk opened this issue Apr 6, 2018 · 9 comments
Open

Relevant global object #3613

annevk opened this issue Apr 6, 2018 · 9 comments

Comments

@annevk
Copy link
Member

annevk commented Apr 6, 2018

I wonder about two things:

  1. Is this global object immutable? (I suspect that Firefox mutates it per https://www.w3.org/Bugs/Public/show_bug.cgi?id=20567 as otherwise Firefox would continue leaking globals, but are there other such cases and do other browsers ever do it?)
  2. For a node, do we ever not want the relevant global object of its node document, rather than the node itself? (This depends in part on 1. Browsers that don't change the global when moving nodes around, probably don't want to use the node's global, but rather it's node document's global. I observed this at least for window.event: Extra window.event tests web-platform-tests/wpt#10329.)

cc @bzbarsky @domenic

@annevk
Copy link
Member Author

annevk commented Apr 6, 2018

(My window.event debugging appears to be wrong.)

@bzbarsky
Copy link
Contributor

bzbarsky commented Apr 6, 2018

Is this global object immutable?

Per spec, no. https://heycam.github.io/webidl/#es-platform-objects explicitly says:

The global environment that a given platform object is associated with can change
after it has been created.

And yes, Firefox does change it on adopt.

For a node, do we ever not want the relevant global object of its node document, rather than the node itself?

Mmm. Good question; I hadn't thought about this before because in Firefox the two are always the same. We would probably need to audit all uses of relevant global on nodes and see what they're really after...

@domenic
Copy link
Member

domenic commented Apr 6, 2018

I'm not sure how to approach this issue, as it appears to be all Firefox-specific concerns.

@bzbarsky
Copy link
Contributor

bzbarsky commented Apr 6, 2018

Concern 2 is only a concern for non-Firefox browers, no?

@guest271314
Copy link
Contributor

Can "Relevant global object", "node's global" and "node document's global" be clearly defined, here? What are the distinctions between the three terms? How to determine and verify each case?

@guest271314
Copy link
Contributor

Is window.event value expected to be an event programmatically dispatched to an node where the document which contains the node is, for example a document loaded from an XMLHttpRequest()?

@bzbarsky
Copy link
Contributor

bzbarsky commented Apr 6, 2018

Can "Relevant global object", "node's global" and "node document's global" be clearly defined, here?

See https://html.spec.whatwg.org/multipage/webappapis.html#relevant

"node's global" and "node document's global" are shorthand for "the relevant global object of the node" and "the relevant global object of the node's node document", in the https://dom.spec.whatwg.org/#concept-node-document sense.

How to determine and verify each case?

I'm not sure what you're asking. For purposes of this issue, what probably needs to happen is identifying all APIs exposed on nodes that use the "relevant global" concept, testing each one with a node that has a different-global node document, and seeing what browsers do in practice in terms of which global they use.

@guest271314
Copy link
Contributor

Not yet gathering the full scope of the inquiry. This is what tried so far

      let doc;
      const request = new XMLHttpRequest();
      request.responseType = "document";
      request.onload = e => {
        doc = request.response;
        doc.onclick = e => console.log(e, window.event);
        console.log(window.event, doc.activeElement);
        doc.documentElement.click();
      }
      request.onerror = e => console.log(e);
      request.open("GET", "document.html", true);
      request.send();

Trying to get top.event or parent.event at plnkr throws CORS error. Have not yet tried to create a test where the parent window.event is logged when the event is dispatched at #document loaded from XMLHttpRequest() and no element of that #document is appended to a displayed document.

@bzbarsky
Copy link
Contributor

bzbarsky commented Apr 6, 2018

The relevant global of everything in your testcase is the same. The testcase of interest that involves window.event is more like this:

<iframe></iframe>
<script>
  var body = frames[0].document.body;
  document.documentElement.appendChild(body);
  // During dispatch of the event below, is .event set on _this_ window
  // or the window in the subframe?  The former is the global of the node
  // document; the latter is the global of the node in some browsers.
  body.dispatchEvent(new Event("test"));
</script>

But the bigger question is what should happen for all APIs on nodes that use the relevant global.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants