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

What happens to the responsible browsing context of a settings object when the browsing context is discarded? #3846

Closed
bzbarsky opened this issue Jul 24, 2018 · 4 comments · Fixed by #4393

Comments

@bzbarsky
Copy link
Contributor

https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document says:

each environment settings object has strong references to its global object, responsible browsing context

Does this reference outlive the browsing context being discarded?

@domenic
Copy link
Member

domenic commented Jul 30, 2018

I looked into this and waffled back and forth on the answer.

Currently I'm leaning toward "yes", because if you save let old = frames[0].frames[0] and then unload frames[0], old (a global object ~ environment settings object) probably has lots of properties that depend on the browsing context, and we shouldn't do a spec-segfault if you access them. We'd have to do an audit of places that use "responsible browsing context"; the ones I've seen so far are not guarded by null checks.

On the other hand it seems like the intent of discarding a browsing context is pretty clearly to allow freeing memory? And maybe this hurts that? Unclear to me how badly.

@domenic
Copy link
Member

domenic commented Jul 30, 2018

Hmm, there may be a clue lower down.

A WindowProxy does not have a strong reference to the browsing context it was created alongside. In particular, it is possible for a nested browsing context to be discarded even if JavaScript code holds a reference to its WindowProxy object.

(I vaguely remember you and me working through adding that in the past.)

Right now I see a strong reference graph of WindowProxy -> Window -> environment settings object -> responsible browsing context, which "discard" does not sever, so the above statement seems false. Maybe if we severed the last link in "discard" it would become true.

Edit: diagram of the current situation in #3863.

@bzbarsky
Copy link
Contributor Author

Right now I see a strong reference graph of

Yeah, I agree.

I wonder what UAs do in practice. I am pretty sure that Gecko severs the equivalent of the "environment settings object -> responsible browsing context" link and has null-checks as needed.

annevk added a commit that referenced this issue Feb 15, 2019
annevk added a commit that referenced this issue Feb 19, 2019
Previously, a Document could sometimes "have no browsing context". Now,
"a Document's browsing context" is either a browsing context or null.

Previously, "a Window's browsing context" was not defined, despite being
referenced extensively. Now, it is defined to be the Window's associated
Document's browsing context.

Related to #3846, #4363, and #4366.
annevk added a commit that referenced this issue Feb 26, 2019
This fixes #3846, though does not clarify the situation for all callers necessarily.

Removing this concept altogether is tricky as it's used in workers for disabled scripts. #1580 tracks that.
@annevk
Copy link
Member

annevk commented Feb 26, 2019

Note that elsewhere we concluded that there should indeed be null checks on these browsing context getters throughout. #4363 tracks adding them.

domenic pushed a commit that referenced this issue Feb 26, 2019
This fixes #3846, though does not clarify the situation for all callers necessarily.

Removing this concept altogether is tricky as it's used in workers for disabled scripts. #1580 tracks that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants