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

Continue to attempt to clarify the reference graph for browsing contexts/Documents/Windows/WindowProxys #2126

Open
domenic opened this issue Dec 1, 2016 · 10 comments
Assignees

Comments

@domenic
Copy link
Member

domenic commented Dec 1, 2016

Previously: 39118df; related: #1336. Raised by @asajeffrey in #whatwg; see logs. Probably also want to solve #1930 as part of this.

I think the ideal setup would be:

  • A clear ownership graph where there are well-known and <dfn>ed terms for each ownership relationship. The current "associated Document" term is an example of this done well. Issue Document object's Window object #1930 is a case of it done poorly. A diagram would be helpful.
  • Isolate the "browsing context" concept as much as possible within the graph. Ideally it should have only one edge coming into it or out of it, or be 1-1 with one of the Web IDL objects.
  • Revamp the garbage collection section in light of this, including the concepts of discarding a document and discarding a browsing context.
  • As a stretch goal, make "discarding" mean "nobody has any references to it" or maybe "nobody but author code has any references to it", to match its intuitive meaning.

This is also vaguely related to #1454, especially the comments about how the spec currently keeps browsing contexts alive for a long time as part of the browsing context tree it uses to track history, whereas implementations have a separate tree. Maybe we'll have to solve that at the same time.

@asajeffrey
Copy link

The matching servo issue is servo/servo#14434, since we're trying to follow the spec for this.

@zetafunction
Copy link

zetafunction commented Dec 14, 2016

A bit tangential, but I noticed that window.closed's return value is inconsistent between browsers.

<script>
function f() {
  var w = window.open();
  console.log('New window? ', w != window);
  w.document.body.appendChild(w.document.createElement('iframe'));
  console.log('Got subframe? ', w.length > 0)
  var subframe = w[0];
  w.close();
  console.log('New window is closed? ', w.closed);
  console.log('New window\'s subframe is closed? ', subframe.closed);
}
</script>
<a onclick="f()">Click</a>

In Firefox and Chrome, the output is:

New window?  true
Got subframe?  true
New window is closed?  true
New window's subframe is closed?  false

But in Edge, the output is:

New window?  true
Got subframe?  true
New window is closed?  false
New window's subframe is closed?  true

@annevk
Copy link
Member

annevk commented Dec 16, 2016

Do you also want to better define the concept that holds a collection of browsing contexts (and their event loop)? We haven't really defined that either and I think it would help if we did with name targeting and such and whether or not globals can reach each other.

@domenic
Copy link
Member Author

domenic commented Dec 16, 2016

I wasn't planning on tackling that as part of this, but who knows what will happen when I start pulling on the threads here. The intent is mainly to clarify the reference graph, not to give names to all concepts.

@asajeffrey
Copy link

@domenic When you said 'As a stretch goal, make "discarding" mean "nobody has any references to it" or maybe "nobody but author code has any references to it", to match its intuitive meaning,' this seems to imply that a Document can be discarded even if script has a reference to it. Is this just when its browsing context is discarded, or can a Document be discarded (e.g. when it is inactive, and the browser decides to reclaim resources) even if user code has a reference to it?

@asajeffrey
Copy link

Mostly as a note to my future self... https://html.spec.whatwg.org/multipage/browsers.html#the-session-history-of-browsing-contexts the first note says:

Each entry, when first created, has a Document. However, when a Document is not active, it's possible for it to be discarded to free resources. The URL and other data in a session history entry is then used to bring a new Document into being to take the place of the original, should the user agent find itself having to reactivate that Document.

this is how a Document can be discarded without its browsing context being discarded.

@asajeffrey
Copy link

IRC chat with @domenic: http://logs.glob.uno/?c=freenode%23whatwg&s=20+Dec+2016&e=20+Dec+2016#c1015135. TL;DR: a browser is allowed to discard a document even if script has a reference to it.

@annevk
Copy link
Member

annevk commented Dec 21, 2016

I don't think that is true. What would that mean for the script reference?

@domenic
Copy link
Member Author

domenic commented Dec 21, 2016

The thing is, "discarded" is a term of art in the spec; it doesn't mean "discarded" in the sense of "garbage collected" or similar. It just means that a certain algorithm, "discard the document", runs. And I think per spec it's totally fine for the "discard the document" algorithm to run even if there's a script reference to the document.

That mismatch between our usual use of the word "discarded" and the spec's is what I alluded to in the OP with

As a stretch goal, make "discarding" mean "nobody has any references to it" or maybe "nobody but author code has any references to it", to match its intuitive meaning.

annevk added a commit that referenced this issue May 3, 2017
This makes several changes:

* Stop throwing an exception in <a> and <area> activation behavior as a
result of popup blocking as it doesn’t match implementations. Fixes
#2616. Formal testing is not possible and tracked by
web-platform-tests/wpt#3867.
* Make matching for special names ASCII case-insensitive. Fixes #2443.
* Centralize all user-configurable behavior instead of having it
duplicated in various ways in all the caller algorithms.
* Call out a known issue with browsing context name matching: #2126.

It also modernizes the writing style and makes variables and what is
returned much more explicit, including no longer relying on some
out-of-band channel for communicating whether a new browsing context
got created.
annevk added a commit that referenced this issue May 3, 2017
This makes several changes:

* Stop throwing an exception in <a> and <area> activation behavior as a
result of popup blocking as it doesn’t match implementations. Fixes
web-platform-tests/wpt#3867.
* Make matching for special names ASCII case-insensitive. Fixes #2443.
* Centralize all user-configurable behavior instead of having it
duplicated in various ways in all the caller algorithms.
* Call out a known issue with browsing context name matching: #2126.

It also modernizes the writing style and makes variables and what is
returned much more explicit, including no longer relying on some
out-of-band channel for communicating whether a new browsing context
got created.
@annevk
Copy link
Member

annevk commented May 4, 2017

#1440 is the browsing context name issue I was after above. It also has ideas how to revamp unit of related browsing contexts into a more imperative construct.

annevk added a commit that referenced this issue May 8, 2017
This makes several changes:

* Stop throwing an exception in <a> and <area> activation behavior as a
result of popup blocking as it doesn’t match implementations. Fixes
web-platform-tests/wpt#3867.
* Make matching for special names ASCII case-insensitive. Fixes #2443.
* Centralize all user-configurable behavior instead of having it
duplicated in various ways in all the caller algorithms.
* Call out a known issue with browsing context name matching: #2126.

It also modernizes the writing style and makes variables and what is
returned much more explicit, including no longer relying on some
out-of-band channel for communicating whether a new browsing context
got created.
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