Skip to content

Commit 595e504

Browse files
mfalkenjungkees
authored andcommitted
Clarify "uncaught runtime script error". (#1346)
The HTML standard returns Completion Records to convey the result of running a script. Use that.
1 parent 7b85d13 commit 595e504

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

docs/index.bs

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ spec: ecma-262; urlPrefix: http://tc39.github.io/ecma262/
5959
text: map objects; url: sec-map-objects
6060
text: InitializeHostDefinedRealm; url: sec-initializehostdefinedrealm
6161
text: execution context; url: sec-execution-contexts
62+
text: abrupt completion; url: sec-completion-record-specification-type
63+
text: Completion; url: sec-completion-record-specification-type
6264

6365
spec: page-visibility; urlPrefix: https://www.w3.org/TR/page-visibility/
6466
type: enum; text: VisibilityState; url: VisibilityState
@@ -2487,12 +2489,12 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24872489
1. Set |worker|'s [=script resource map=][|url|] to |response|.
24882490
1. Set |worker|'s <a>script resource</a>'s <a>HTTPS state</a> to |httpsState|.
24892491
1. Set |worker|'s <a>script resource</a>'s [=script resource/referrer policy=] to |referrerPolicy|.
2490-
1. Invoke <a>Run Service Worker</a> algorithm given |worker|, and with the *force bypass cache for importscripts flag* set if |job|'s [=job/force bypass cache flag=] is set.
2491-
1. If an uncaught runtime script error occurs during the above step, then:
2492-
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
2493-
1. If |newestWorker| is null, invoke <a>Clear Registration</a> algorithm passing |registration| as its argument.
2494-
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
2495-
1. Invoke <a>Install</a> algorithm with |job|, |worker|, and |registration| as its arguments.
2492+
1. Invoke [=Run Service Worker=] algorithm given |worker|, with the *force bypass cache for importscripts flag* set if |job|'s [=job/force bypass cache flag=] is set, and with the following callback steps given |evaluationStatus|:
2493+
1. If |evaluationStatus| is an [=abrupt completion=] or |evaluationStatus|.\[[Value]] is empty, then:
2494+
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
2495+
1. If |newestWorker| is null, invoke [=Clear Registration=] algorithm passing |registration| as its argument.
2496+
1. Invoke [=Finish Job=] with |job|.
2497+
1. Else, invoke [=Install=] algorithm with |job|, |worker|, and |registration| as its arguments.
24962498
</section>
24972499

24982500
<section algorithm>
@@ -2633,59 +2635,58 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26332635
: Input
26342636
:: |serviceWorker|, a [=/service worker=]
26352637
:: *force bypass cache for importscripts flag*, an optional flag unset by default
2636-
: Output
2637-
:: None
2638+
:: optional |callbackSteps|, an algorithm which takes a [=Completion=]
26382639

26392640
1. Let |script| be |serviceWorker|'s [=service worker/script resource=].
26402641
1. Assert: |script| is not null.
2641-
1. If |serviceWorker| is already running, abort these steps.
2642-
1. Create a separate parallel execution environment (i.e. a separate thread or process or equivalent construct), and run the rest of these steps in that context.
2643-
1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations:
2644-
* For the global object, create a new {{ServiceWorkerGlobalScope}} object. Let |workerGlobalScope| be the created object.
2645-
* Let |realmExecutionContext| be the created [=execution context|JavaScript execution context=].
2646-
1. Set |serviceWorker|'s [=service worker/global object=] to |workerGlobalScope|.
2647-
1. Let |workerEventLoop| be a newly created <a>event loop</a>.
2648-
1. Let |settingsObject| be a new <a>environment settings object</a> whose algorithms are defined as follows:
2649-
2650-
: The [=environment settings object/realm execution context=]
2651-
:: Return |realmExecutionContext|.
2652-
: The [=environment settings object/global object=]
2653-
:: Return |workerGlobalScope|.
2654-
: The <a>responsible event loop</a>
2655-
:: Return |workerEventLoop|.
2656-
: The [=environment settings object/referrer policy=]
2657-
:: Return |workerGlobalScope|'s [=WorkerGlobalScope/referrer policy=].
2658-
: The <a>API URL character encoding</a>
2659-
:: Return UTF-8.
2660-
: The <a>API base URL</a>
2661-
:: Return |serviceWorker|'s [=service worker/script url=].
2662-
: The [=environment settings object/origin=]
2663-
:: Return its registering [=/service worker client=]'s [=environment settings object/origin=].
2664-
: The <a>creation URL</a>
2665-
:: Return |workerGlobalScope|'s [=WorkerGlobalScope/url=].
2666-
: The [=environment settings object/HTTPS state=]
2667-
:: Return |workerGlobalScope|'s [=WorkerGlobalScope/HTTPS state=].
2668-
2669-
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/url=] to |serviceWorker|'s [=service worker/script url=].
2670-
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/HTTPS state=] to |serviceWorker|'s <a>script resource</a>'s <a>HTTPS state</a>.
2671-
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/referrer policy=] to |serviceWorker|'s <a>script resource</a>'s [=script resource/referrer policy=].
2672-
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/type=] to |serviceWorker|'s [=service worker/type=].
2673-
1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set.
2674-
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
2675-
1. If |serviceWorker| is an <a>active worker</a>, and there are any <a>tasks</a> queued in |serviceWorker|'s <a>containing service worker registration</a>'s [=service worker registration/task queues=], <a lt="queue a task">queue</a> them to |serviceWorker|'s <a>event loop</a>'s [=/task queues=] in the same order using their original <a>task sources</a>.
2676-
1. If |script| is a <a>classic script</a>, then <a lt="run a classic script">run the classic script</a> |script|. Otherwise, it is a <a>module script</a>; <a lt="run a module script">run the module script</a> |script|.
2677-
2678-
Note: In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the <a>terminate service worker</a> algorithm.
2679-
2680-
1. If |script|'s <a>has ever been evaluated flag</a> is unset, then:
2681-
1. For each |eventType| of |settingsObject|'s [=environment settings object/global object=]'s associated list of <a>event listeners</a>' event types:
2682-
1. [=set/Append=] |eventType| to |workerGlobalScope|'s associated [=ServiceWorkerGlobalScope/service worker=]'s <a>set of event types to handle</a>.
2683-
2684-
Note: If the global object's associated list of event listeners does not have any event listener added at this moment, the service worker's set of event types to handle remains an empty set. The user agents are encouraged to show a warning that the event listeners must be added on the very first evaluation of the worker script.
2685-
2686-
1. Set |script|'s <a>has ever been evaluated flag</a>.
2687-
1. Run the <a>responsible event loop</a> specified by |settingsObject| until it is destroyed.
2688-
1. Empty |workerGlobalScope|'s <a>list of active timers</a>.
2642+
1. If |serviceWorker| is already running, this algorithm must have been invoked previously. If |callbackSteps| is provided, run them with the same value as the previous time, and abort these steps.
2643+
1. Create a separate parallel execution environment (i.e. a separate thread or process or equivalent construct), and run the following substeps in that context:
2644+
1. Call the JavaScript [=InitializeHostDefinedRealm|InitializeHostDefinedRealm()=] abstract operation with the following customizations:
2645+
* For the global object, create a new {{ServiceWorkerGlobalScope}} object. Let |workerGlobalScope| be the created object.
2646+
* Let |realmExecutionContext| be the created [=execution context|JavaScript execution context=].
2647+
1. Set |serviceWorker|'s [=service worker/global object=] to |workerGlobalScope|.
2648+
1. Let |workerEventLoop| be a newly created <a>event loop</a>.
2649+
1. Let |settingsObject| be a new <a>environment settings object</a> whose algorithms are defined as follows:
2650+
2651+
: The [=environment settings object/realm execution context=]
2652+
:: Return |realmExecutionContext|.
2653+
: The [=environment settings object/global object=]
2654+
:: Return |workerGlobalScope|.
2655+
: The <a>responsible event loop</a>
2656+
:: Return |workerEventLoop|.
2657+
: The [=environment settings object/referrer policy=]
2658+
:: Return |workerGlobalScope|'s [=WorkerGlobalScope/referrer policy=].
2659+
: The <a>API URL character encoding</a>
2660+
:: Return UTF-8.
2661+
: The <a>API base URL</a>
2662+
:: Return |serviceWorker|'s [=service worker/script url=].
2663+
: The [=environment settings object/origin=]
2664+
:: Return its registering [=/service worker client=]'s [=environment settings object/origin=].
2665+
: The <a>creation URL</a>
2666+
:: Return |workerGlobalScope|'s [=WorkerGlobalScope/url=].
2667+
: The [=environment settings object/HTTPS state=]
2668+
:: Return |workerGlobalScope|'s [=WorkerGlobalScope/HTTPS state=].
2669+
2670+
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/url=] to |serviceWorker|'s [=service worker/script url=].
2671+
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/HTTPS state=] to |serviceWorker|'s <a>script resource</a>'s <a>HTTPS state</a>.
2672+
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/referrer policy=] to |serviceWorker|'s <a>script resource</a>'s [=script resource/referrer policy=].
2673+
1. Set |workerGlobalScope|'s [=WorkerGlobalScope/type=] to |serviceWorker|'s [=service worker/type=].
2674+
1. Set |workerGlobalScope|'s [=ServiceWorkerGlobalScope/force bypass cache for importscripts flag=] if the *force bypass cache for importscripts flag* is set.
2675+
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
2676+
1. If |serviceWorker| is an <a>active worker</a>, and there are any <a>tasks</a> queued in |serviceWorker|'s <a>containing service worker registration</a>'s [=service worker registration/task queues=], <a lt="queue a task">queue</a> them to |serviceWorker|'s <a>event loop</a>'s [=/task queues=] in the same order using their original <a>task sources</a>.
2677+
1. Let |evaluationStatus| be the result of <a lt="run a classic script">running the classic script</a> |script| if |script| is a <a>classic script</a>, otherwise, the result of <a lt="run a module script">running the module script</a> |script| if |script| is a [=module script=].
2678+
2679+
Note: In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the <a>terminate service worker</a> algorithm.
2680+
1. If |callbackSteps| is provided, run them with |evaluationStatus| on the original thread that invoked this algorithm, while continuing in parallel with these steps.
2681+
1. If |script|'s <a>has ever been evaluated flag</a> is unset, then:
2682+
1. For each |eventType| of |settingsObject|'s [=environment settings object/global object=]'s associated list of <a>event listeners</a>' event types:
2683+
1. [=set/Append=] |eventType| to |workerGlobalScope|'s associated [=ServiceWorkerGlobalScope/service worker=]'s <a>set of event types to handle</a>.
2684+
2685+
Note: If the global object's associated list of event listeners does not have any event listener added at this moment, the service worker's set of event types to handle remains an empty set. The user agents are encouraged to show a warning that the event listeners must be added on the very first evaluation of the worker script.
2686+
2687+
1. Set |script|'s <a>has ever been evaluated flag</a>.
2688+
1. Run the <a>responsible event loop</a> specified by |settingsObject| until it is destroyed.
2689+
1. Empty |workerGlobalScope|'s <a>list of active timers</a>.
26892690
</section>
26902691

26912692
<section algorithm>

0 commit comments

Comments
 (0)