Skip to content

Scope ModelContext to Document, and handle detached documents#177

Merged
domfarolino merged 2 commits into
mainfrom
fix-modelcontext-lifetime
May 19, 2026
Merged

Scope ModelContext to Document, and handle detached documents#177
domfarolino merged 2 commits into
mainfrom
fix-modelcontext-lifetime

Conversation

@domfarolino
Copy link
Copy Markdown
Collaborator

@domfarolino domfarolino commented May 15, 2026

This PR does two things:

  • Scopes the ModelContext object to Document instead of Navigator, and explains why.
  • Makes the modelContext attribute return null when the document is detached (by checking when the Window's browsing context is null). This matches the behavior of the contentWindow and contentDocument getters—return nothing, even if those objects are allocated and kept alive by other references, in the detached document case.

Note that this PR does not handle the "document not fully active" case, which covers detached documents and documents in the bf-cache. Non-fully active documents probably shouldn't impact the modelContext getter—it seems weird for getters like that to return different values based on whether the document is in the bf-cache—but rather need special behavior in the registerTool() method, and the coming getTools() and executeTool() methods.

This PR mostly addresses #173, with the exception of considering moving the API to self, from navigator. As much as I want to do this, I'm sympathetic to w3ctag/design-principles#426 (comment), so for now I'm leaning towards not moving it. So I'll say that this PR closes #173.


Preview | Diff

@domfarolino domfarolino requested a review from bwalderman May 15, 2026 23:33
Comment thread index.bs
@domfarolino domfarolino changed the title Scope and null-out for detached documents Tie ModelContext lifetime to Document and handle detached documents May 15, 2026
@domfarolino domfarolino changed the title Tie ModelContext lifetime to Document and handle detached documents Scope ModelContext to Document, and handle detached documents May 15, 2026
Comment thread index.bs Outdated
Comment thread index.bs Outdated
@domfarolino domfarolino requested a review from bwalderman May 18, 2026 20:25
@domfarolino domfarolino merged commit 986f461 into main May 19, 2026
2 checks passed
@domfarolino domfarolino deleted the fix-modelcontext-lifetime branch May 19, 2026 02:19
github-actions Bot added a commit that referenced this pull request May 19, 2026
SHA: 986f461
Reason: push, by domfarolino

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make tools Document-scoped instead of Window-scoped

4 participants