diff --git a/source b/source index ee75ede27f7..a0b9f6c2f7e 100644 --- a/source +++ b/source @@ -86487,6 +86487,10 @@ interface ApplicationCache : EventTarget {
Return record.[[HostDefined]].
The active script concept is so far only used by the
+ import()
feature, to determine the base
+ URL to use for resolving relative module specifiers.
An environment is an object that identifies the settings of a @@ -88288,14 +88292,54 @@ document.querySelector("button").addEventListener("click", bound);
Let active script be the active script.
Assert: active script is not null, as jobs are only enqueued by the JavaScript - specification while a script is active.
Let script execution context be null.
Let script execution context be a new JavaScript execution - context, with its Function field set to null, its Realm field set to active - script's settings object's Realm, and its ScriptOrModule set to active script's record.
If active script is not null, set script execution context to a new + JavaScript execution context, with its Function field set to null, its Realm field + set to active script's settings object's Realm, and its ScriptOrModule set to active script's + record.
+ +As seen below, this is used in order to propagate the current active + script forward to the time when the job is executed.
+ +A case where active script is non-null, and saving it in this way is useful, is + the following:
+ +Promise.resolve('import(`./example.mjs`)').then(eval);
+
+ Without this step (and the steps below that use it), there would be no active
+ script when the import()
expression is evaluated, since eval()
+ is a built-in function that does not originate from any particular script.
With this step in place, the active script is propagated from the above code into the job,
+ allowing import()
to use the original script's base URL appropriately.
active script can be null if the user clicks on the following button, before any
+ script ever accesses the button's onclick
property:
<button onclick="Promise.resolve('import(`./example.mjs`)').then(eval)">Click me</button>
+
+ In this case, the JavaScript function for the event + handler will be created by the get the current value of the event handler algorithm as a direct result of user + action, with no script on the stack (i.e. no active script). Thus, when the + promise machinery calls EnqueueJob, there will be no active script to + pass along.
+ +As a consequence, this means that when the import()
expression is evaluated,
+ there will still be no active script. Fortunately that is handled by our
+ implementations of HostResolveImportedModule and
+ HostImportModuleDynamically, by falling back to using the current settings
+ object's API base URL.
Queue a microtask, on job settings's responsible event @@ -88320,20 +88364,20 @@ document.querySelector("button").addEventListener("click", bound);
Push script execution context onto the - JavaScript execution context stack.
+If script execution context is not null, then push script execution context onto the JavaScript execution + context stack.
-This affects the active script while the job runs, in cases like
- Promise.resolve("...").then(eval)
where there would otherwise be no
- active script since eval()
is a built-in function that does not originate from
- any particular script.
As explained above, this affects the active script while the job + runs.
Let result be the result of performing the abstract operation specified by job, using the elements of arguments as its arguments.
Pop script execution context from the - JavaScript execution context stack.
If script execution context is not null, then pop script execution context from the JavaScript execution context + stack.
Clean up after running a callback with incumbent settings.
Let referencing script be - referencingScriptOrModule.[[HostDefined]].
Let settings object be the current settings object.
Let moduleMap be referencing script's settings object's - module map.
Let base URL be settings object's API base + URL.
If referencingScriptOrModule is not null, then:
+ +Let referencing script be + referencingScriptOrModule.[[HostDefined]].
Set settings object to referencing script's settings + object.
Set base URL to referencing script's base URL.
referencingScriptOrModule is not usually null. One case where it can be + null is if the user clicks the control in the following example:
+ +<button onclick="import('./foo.mjs')">Click me</button>
+
+ In this case, at the time the import()
expression runs,
+ GetActiveScriptOrModule will return null, which will be passed to this abstract
+ operation when HostResolveImportedModule is
+ called by FinishDynamicImport.
Let moduleMap be settings object's module map.
Let url be the result of resolving a - module specifier given referencing script's base URL and specifier.
Assert: url is never failure, because resolving a module specifier must have been previously successful with these - same two arguments.
Let resolved module script be moduleMap[url]. (This entry must exist for us to have gotten to this point.)
Let referencing script be - referencingScriptOrModule.[[HostDefined]].
Let settings object be the current settings object.
Let base URL be settings object's API base + URL.
Let fetch options be the default classic script fetch + options.
If referencingScriptOrModule is not null, then:
+ +Let referencing script be + referencingScriptOrModule.[[HostDefined]].
+ +Set settings object to referencing script's settings + object.
Set base URL to referencing script's base URL.
Set fetch options to the descendant script fetch options for + referencing script's fetch + options.
As explained above for HostResolveImportedModule, in the common + case, referencingScriptOrModule is non-null.
+Let url be the result of resolving a - module specifier given referencing script's base URL and specifier.
If url is failure, then:
@@ -88537,14 +88635,9 @@ import "https://example.com/foo/../module2.mjs";Let options be the descendant script fetch options for - referencing script's fetch - options.
Fetch a module script graph given url, referencing
- script's settings object, "script
", and
- options. Wait until the algorithm asynchronously completes with
- result.
Fetch a module script graph given url, settings object,
+ "script
", and fetch options. Wait until the algorithm
+ asynchronously completes with result.
If result is null, then: