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

Return empty on "do not run" for running a script. #3907

Merged
merged 3 commits into from
Aug 14, 2018

Conversation

mfalken
Copy link
Contributor

@mfalken mfalken commented Aug 13, 2018

Previously, the algorithm returned NormalCompletion(undefined) when the
script was not run.

But the service worker script will need to distinguish between when the
script was run vs not, for deciding whether it can proceed with
installation. The counterpart service worker spec change is:
w3c/ServiceWorker#1346


/browsing-the-web.html ( diff )
/webappapis.html ( diff )

Previously, the algorithm returned NormalCompletion(undefined) when the
script was not run.

But the service worker script will need to distinguish between when the
script was run vs not, for deciding whether it can proceed with
installation. The counterpart service worker spec change is:
w3c/ServiceWorker#1346
@mfalken
Copy link
Contributor Author

mfalken commented Aug 13, 2018

@domenic It turns out I need to distinguish between "do not run" vs ran. WDYT of this? See w3c/ServiceWorker#1346

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

I'd prefer keeping the return type of an algorithm consistent. Domenic probably has more ideas but I could think of two ways to do that:

@mfalken
Copy link
Contributor Author

mfalken commented Aug 13, 2018

Thanks @TimothyGu ! "empty" sounds like it does the trick, assuming that running the script will never result in a NormalCompletion(empty).

@TimothyGu
Copy link
Member

@mattto See https://tc39.github.io/ecma262/#sec-runtime-semantics-scriptevaluation, specifically step 13, which guarantees that "empty" will never get returned from classic script evaluation. And https://tc39.github.io/ecma262/#sec-module-semantics-runtime-semantics-evaluation for module scripts.

@mfalken
Copy link
Contributor Author

mfalken commented Aug 13, 2018

Thanks. Is Type(empty) defined to be Undefined? The javascript: steps take the result and do Type(result).

@mfalken
Copy link
Contributor Author

mfalken commented Aug 13, 2018

Revised. It can be make simpler if Type(empty) is Undefined, but I'm not clear on that.

@TimothyGu
Copy link
Member

empty is “no value at all” and it doesn’t have a type – i.e., Type(empty) is undefined (as in not defined, not Undefined 😅).

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

LGTM other than the nit.

source Outdated
<p class="note">This value is only ever used by the <span data-x="javascript
protocol"><code>javascript:</code> URL steps</span>.</p>
</li>
<li><p>If <var>evaluationStatus</var> is a normal completion, return
Copy link
Member

Choose a reason for hiding this comment

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

, then

source Outdated
@@ -81986,8 +81986,9 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
<li><p>Let <var>evaluationStatus</var> be the result of <span data-x="run a classic
script">running the classic script</span> <var>script</var>.</p></li>

<li><p>Let <var>result</var> be undefined if <var>evaluationStatus</var> is an <span>abrupt
completion</span>, or <var>evaluationStatus</var>.[[Value]] otherwise.</p></li>
<li><p>Let <var>result</var> be undefined if <var>evalutionStatus</var> is an
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, also reminding myself to fix a typo: "evalutionStatus"

@mfalken mfalken changed the title Return undefined on "do not run" for running a script. Return empty on "do not run" for running a script. Aug 14, 2018
@mfalken
Copy link
Contributor Author

mfalken commented Aug 14, 2018

Thanks, I've updated the PR. I think the merger will need to edit the commit description to say it's returning "empty" instead of "undefined".

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

I'm not super-excited about introducing another not-actually-there value (in addition to undefined and null) into the world of things people have to care about when consuming our specs. In particular completions that can contain non-JS values as their [[Value]] are pretty rare, and mean every consumer has to handle them in a way that they may not be used to.

But, this is reasonably elegant. And we know our consumers are fairly limited for now. I guess we should just do it.

@domenic domenic merged commit b71f885 into whatwg:master Aug 14, 2018
@mfalken
Copy link
Contributor Author

mfalken commented Aug 15, 2018

Thanks! FWIW I thought the <boolean, CompletionRecord> tuple would be better for readability but a bit harder to write. I guess we can always adjust later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants