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

[worklets] Introduce an "owner document" for each WorkletGlobalScope. #389

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions worklets/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:html; type:dfn; for:environment settings object;
text: https state
text: referrer policy
spec:html; type:dfn; for:environment; text:id
spec:infra; type:dfn; text:list
spec:webidl; type:dfn; for:interface; text:inherit
</pre>

Expand All @@ -49,6 +50,8 @@ urlPrefix: https://html.spec.whatwg.org/multipage/workers.html; type: dfn;
urlPrefix: #dom-workerglobalscope-;
text: self
urlPrefix: https://html.spec.whatwg.org/multipage/webappapis.html; type: dfn;
text: abort a running script
text: currently running task
text: document environment
text: event loop processing model
text: microtask queue
Expand Down Expand Up @@ -194,7 +197,10 @@ When a user agent is to <dfn>create a WorkletGlobalScope</dfn>, given |workletGl

4. Associate the |insideSettings| with |workletGlobalScope|.

5. For each |entry| in the given |moduleResponsesMap| (in insertion order), run the following
5. Set |workletGlobalScope|'s <a>owner document</a> be |outsideSettings|'s
<a>responsible document</a>.

6. For each |entry| in the given |moduleResponsesMap| (in insertion order), run the following
substeps:

1. Let |moduleURLRecord| be |entry|'s key.
Expand All @@ -210,7 +216,7 @@ When a user agent is to <dfn>create a WorkletGlobalScope</dfn>, given |workletGl
point it should have successfully been parsed by another worklet global scope. I.e.
|script| should never be <em>null</em> here.

6. Run the <a>responsible event loop</a> specified by |insideSettings|.
7. Run the <a>responsible event loop</a> specified by |insideSettings|.
</div>

### Script settings for worklets ### {#script-settings-for-worklets}
Expand Down Expand Up @@ -497,14 +503,38 @@ Issue(w3c/css-houdini-drafts#47): Need ability to load code into a {{WorkletGlob
Lifetime of the Worklet {#lifetime-of-the-worklet}
--------------------------------------------------

The lifetime of a {{Worklet}} is tied to the object it belongs to, for example the {{Window}}.
A {{WorkletGlobalScope}} has a <dfn for=workletglobalscope export>owner document</dfn>.

When the <a>owner document</a> is <a lt="discard a document">discarded</a> the user agent <em>must</em> <a
lt="destroy a WorkletGlobalScope">destroy</a> all {{WorkletGlobalScope}}s.

<div algorithm>
When the user agent is to <dfn export>destroy a WorkletGlobalScope</dfn>, given
|workletGlobalScope|, it must run the following steps:
1. <a for=list>Remove</a> |workletGlobalScope| from <a>worklet's WorkletGlobalScopes</a>.

2. If there are any <a>tasks</a> queued in the |workletGlobalScope|'s <a>event loop</a>, discard
them without processing them.

3. Wait for the |workletGlobalScope|'s <a>event loop</a> to complete the <a>currently running
task</a>.

4. If the above step doesn't complete within a period of time as defined by the user agent,
<a lt="abort a running script">abort the script</a> currently running in
|workletGlobalScope|.

5. Destroy |workletGlobalScope|'s <a>event loop</a>.

6. Clear |workletGlobalScope|'s <a>owner document</a>.
</div>

The lifetime of a {{WorkletGlobalScope}} should be defined by subsequent specifications which
inherit from {{WorkletGlobalScope}}.
Note: Most {{Worklet}}s will be instantiated lazily when the web developer wants to use them, it is
expected that they won't be created eagerly.

Subsequent specifications <em>may</em> define that a {{WorkletGlobalScope}} can be terminated at any
time particularly if there are no pending operations, or detects abnormal operation such as infinite
loops and callbacks exceeding imposed time limits.
loops and callbacks exceeding imposed time limits. In such cases the specification should call
<a>destroy a WorkletGlobalScope</a>.

Security Considerations {#security-considerations}
==================================================
Expand Down