You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Set |worker|'s [=script resource map=][|url|] to |response|.
2488
2490
1. Set |worker|'s <a>script resource</a>'s <a>HTTPS state</a> to |httpsState|.
2489
2491
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.
:: *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=]
2638
2639
2639
2640
1. Let |script| be |serviceWorker|'s [=service worker/script resource=].
2640
2641
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=]
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=]
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>.
0 commit comments