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

Normative: Constrain all host hooks to return either normal or throw completions #2442

Merged
merged 1 commit into from
Jul 21, 2021

Conversation

syg
Copy link
Contributor

@syg syg commented Jun 24, 2021

This supersedes #2433.

This PR also makes the prose around requirements for host hook
implementations consistent to the template "An implementation of
HostHook must conform to the following requirements:".

@syg syg requested a review from a team June 24, 2021 02:02
@syg
Copy link
Contributor Author

syg commented Jun 24, 2021

cc @jugglinmike

spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated
@@ -10543,7 +10545,8 @@ <h1>Host Hooks</h1>

<emu-clause id="sec-host-cleanup-finalization-registry" aoid="HostEnqueueFinalizationRegistryCleanupJob">
<h1>HostEnqueueFinalizationRegistryCleanupJob ( _finalizationRegistry_ )</h1>
<p>The abstract operation HostEnqueueFinalizationRegistryCleanupJob takes argument _finalizationRegistry_ (a FinalizationRegistry). HostEnqueueFinalizationRegistryCleanupJob is an implementation-defined abstract operation that is expected to call CleanupFinalizationRegistry(_finalizationRegistry_) at some point in the future, if possible. The host's responsibility is to make this call at a time which does not interrupt synchronous ECMAScript code execution.</p>
<p>The abstract operation HostEnqueueFinalizationRegistryCleanupJob takes argument _finalizationRegistry_ (a FinalizationRegistry). HostEnqueueFinalizationRegistryCleanupJob is an implementation-defined abstract operation that is expected to call CleanupFinalizationRegistry(_finalizationRegistry_) at some point in the future, if possible.</p>
<p>An implementation of HostEnqueueFinalizationRegistryCleanupJob must conform to the requirements in <emu-xref href="#sec-jobs"></emu-xref>.</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The host's responsibility is to make this call at a time which does not interrupt synchronous ECMAScript code execution.

At first glance, I thought the new requirement on host hooks obviated this statement. On second thought, it doesn't seem like it applies to the behavior of an abstract operation invoked after the host hook has returned. Is there some other justification for removing the statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention here was the "must not interrupt synchronous execution" is more precisely captured by the requirements in #sec-jobs, specifically the stuff around waiting for the execution context stack to be empty. No job queued by a job-queuing host defined AO in ecma262 is allowed to interrupt synchronous execution.

Copy link
Contributor Author

@syg syg Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, a strict reading of the #sec-jobs restriction only applies to Job Abstract Closures, which HostEnqueueFinalizationRegistryCleanupJob doesn't explicitly spell out. I'll spell that out so it's clear that it applies.

spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the master branch 3 times, most recently from 3d0c24c to 7a79833 Compare June 29, 2021 02:21
<p>A <dfn id="host-hook">host hook</dfn> is an abstract operation that is defined in whole or in part by an external source. All host hooks must be listed in Annex <emu-xref href="#sec-host-layering-points"></emu-xref>.</p>
<p>A <dfn id="host-hook">host hook</dfn> is an abstract operation that is defined in whole or in part by an external source. All host hooks must be listed in Annex <emu-xref href="#sec-host-layering-points"></emu-xref>. A host hook must conform to at least the following requirements:</p>
<ul>
<li>It must return either a normal completion or a throw completion.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it's currently used twice, I don't think we've defined the term "throw completion". We should probably address those existing uses similarly to my suggestion below:

Suggested change
<li>It must return either a normal completion or a throw completion.</li>
<li>It must return a completion with a [[Type]] value of ~normal~ or ~throw~.</li>

This is the same form used in #2448. Perhaps we want to define a term "callable completion" or something that can be used in all of these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to unless we start referring to this disjunction in more places. Otherwise it's just another thing to look up when the full definition isn't very long.

Copy link
Contributor Author

@syg syg Jul 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll define a generic shorthand, like "foo completion means a completion with a [[Type]] value of ~foo~".

spec.html Outdated Show resolved Hide resolved
@syg syg force-pushed the restrict-host-hooks-completions branch from 9475b14 to aa2b28c Compare July 9, 2021 19:56
@@ -171,7 +171,7 @@ <h1>Hosts and Implementations</h1>
<p>A <dfn id="host">host</dfn> is an external source that further defines facilities listed in Annex <emu-xref href="#sec-host-layering-points"></emu-xref> but does not further define other implementation-defined or implementation-approximated facilities. In informal use, a host refers to the set of all implementations, such as the set of all web browsers, that interface with this specification in the same way via Annex <emu-xref href="#sec-host-layering-points"></emu-xref>. A host is often an external specification, such as WHATWG HTML (<a href="https://html.spec.whatwg.org/">https://html.spec.whatwg.org/</a>). In other words, facilities that are host-defined are often further defined in external specifications.</p>
<p>A <dfn id="host-hook">host hook</dfn> is an abstract operation that is defined in whole or in part by an external source. All host hooks must be listed in Annex <emu-xref href="#sec-host-layering-points"></emu-xref>. A host hook must conform to at least the following requirements:</p>
<ul>
<li>It must return either a normal completion or a throw completion.</li>
<li>It must return a completion with a [[Type]] value of ~normal~ or ~throw~.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you've defined the shorthands, you don't need to make this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it to be consistent with #2448 as you pointed out. Any preference on going with this or staying with "normal or throw completion" for both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"normal completion or throw completion" for both seems best to me. It means your addition of the definitions of those terms will race. Maybe just split it out and we get that in now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just sequence this one before the other -- meeting's in 2 days and we should get consensus for the other one by then.

syg added a commit to syg/ecma262 that referenced this pull request Jul 9, 2021
@ljharb ljharb added needs consensus This needs committee consensus before it can be eligible to be merged. normative change Affects behavior required to correctly evaluate some ECMAScript source text labels Jul 12, 2021
@ljharb ljharb added has consensus This has committee consensus. and removed needs consensus This needs committee consensus before it can be eligible to be merged. labels Jul 14, 2021
@michaelficarra michaelficarra added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Jul 15, 2021
@ljharb ljharb removed the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Jul 15, 2021
@ljharb
Copy link
Member

ljharb commented Jul 15, 2021

@syg this will need a rebase before it's mergeable

@syg syg force-pushed the restrict-host-hooks-completions branch from 6979282 to f811ffc Compare July 21, 2021 17:54
@syg syg added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Jul 21, 2021
@syg
Copy link
Contributor Author

syg commented Jul 21, 2021

Rebased against structured headers.

…completions (tc39#2442)

This PR also makes the prose around requirements for host hook
implementations consistent to the template "An implementation of
HostHook must conform to the following requirements:".
@ljharb ljharb force-pushed the restrict-host-hooks-completions branch from f811ffc to 61f7950 Compare July 21, 2021 18:42
@ljharb ljharb merged commit 61f7950 into tc39:master Jul 21, 2021
mathiasbynens pushed a commit to mathiasbynens/ecma262 that referenced this pull request Oct 18, 2021
…completions (tc39#2442)

This PR also makes the prose around requirements for host hook
implementations consistent to the template "An implementation of
HostHook must conform to the following requirements:".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus This has committee consensus. normative change Affects behavior required to correctly evaluate some ECMAScript source text ready to merge Editors believe this PR needs no further reviews, and is ready to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants