@masknet/compartment
Advanced tools
Comparing version 0.3.9 to 0.3.10
@@ -50,2 +50,14 @@ class ModuleSource { | ||
} | ||
/** @internal */ function NormalCompletion(value) { | ||
return { | ||
Type: 'normal', | ||
Value: value | ||
}; | ||
} | ||
/** @internal */ function ThrowCompletion(error) { | ||
return { | ||
Type: 'throw', | ||
Value: error | ||
}; | ||
} | ||
@@ -313,2 +325,3 @@ function getOpaqueProxy() { | ||
const requestedModule = Module.#GetImportedModule(module, e2.ModuleRequest); | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(requestedModule); | ||
@@ -351,2 +364,3 @@ const starNames = requestedModule.#GetExportedNames(exportStarSet); | ||
const importedModule = Module.#GetImportedModule(module1, e4.ModuleRequest); | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(importedModule); | ||
@@ -374,2 +388,3 @@ if (e4.ImportName === all) { | ||
const importedModule1 = Module.#GetImportedModule(module1, e5.ModuleRequest); | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(importedModule1); | ||
@@ -392,3 +407,2 @@ let resolution = importedModule1.#ResolveExport(exportName, resolveSet); | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-LoadRequestedModules | ||
#LoadRequestedModules(HostDefined = undefined) { | ||
@@ -408,5 +422,4 @@ const module2 = this; | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-InnerModuleLoading | ||
static #InnerModuleLoading(state1, module3) { | ||
assert(state1.IsLoading); | ||
assert(state1.Action === 'graph-loading' && state1.IsLoading); | ||
if (module3.#Status === 0 && !state1.Visited.includes(module3)) { | ||
@@ -417,3 +430,8 @@ state1.Visited.push(module3); | ||
for (const required of module3.#RequestedModules){ | ||
Module.#LoadImportedModule(module3, required, state1); | ||
const record = module3.#LoadedModules.get(required); | ||
if (record) { | ||
Module.#ContinueModuleLoading(state1, NormalCompletion(record)); | ||
} else { | ||
Module.#HostLoadImportedModule(module3, required, state1.HostDefined, state1); | ||
} | ||
} | ||
@@ -431,4 +449,4 @@ } | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-ContinueModuleLoading | ||
static #ContinueModuleLoading(state2, result) { | ||
assert(state2.Action === 'graph-loading'); | ||
if (!state2.IsLoading) return; | ||
@@ -555,3 +573,2 @@ if (result.Type === 'normal') Module.#InnerModuleLoading(state2, result.Value); | ||
if (this.#NeedsImport) { | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-import-call-runtime-semantics-evaluation | ||
this.#ContextObject.import = async (specifier, options)=>{ | ||
@@ -561,8 +578,5 @@ specifier = String(specifier); | ||
Action: 'dynamic-import', | ||
PromiseCapability: PromiseCapability(), | ||
IsLoading: true, | ||
PendingModules: 1, | ||
Visited: [] | ||
PromiseCapability: PromiseCapability() | ||
}; | ||
Module.#LoadImportedModule(this, specifier, status); | ||
Module.#HostLoadImportedModule(this, specifier, status.HostDefined, status); | ||
return status.PromiseCapability.Promise; | ||
@@ -934,34 +948,15 @@ }; | ||
//#endregion | ||
//#region Module refactor methods https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/ | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-GetImportedModule | ||
//#region Module refactor methods https://github.com/tc39/ecma262/pull/2905/ | ||
static #GetImportedModule(module13, spec) { | ||
return module13.#LoadedModules.get(spec); | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-LoadImportedModule | ||
static #LoadImportedModule(referrer, specifier, state3) { | ||
if (referrer && referrer.#LoadedModules.has(specifier)) { | ||
Module.#DispatchLoadImportedModuleContinuation(state3, { | ||
Type: 'normal', | ||
Value: referrer.#LoadedModules.get(specifier) | ||
}); | ||
} else { | ||
Module.#HostLoadImportedModule(referrer, specifier, state3.HostDefined, state3); | ||
} | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-HostLoadImportedModule | ||
static #HostLoadImportedModule(referrer1, specifier1, hostDefined, payload) { | ||
let promiseCapability = referrer1.#ImportHookCache.get(specifier1); | ||
static #HostLoadImportedModule(referrer, specifier, hostDefined, payload) { | ||
let promiseCapability = referrer.#ImportHookCache.get(specifier); | ||
function onFulfilled(module) { | ||
promiseCapability?.Resolve(module); | ||
Module.#FinishLoadImportedModule(referrer1, specifier1, payload, { | ||
Type: 'normal', | ||
Value: module | ||
}); | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, NormalCompletion(module)); | ||
} | ||
function onRejected(reason) { | ||
promiseCapability?.Reject(reason); | ||
Module.#FinishLoadImportedModule(referrer1, specifier1, payload, { | ||
Type: 'throw', | ||
Value: reason | ||
}); | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, ThrowCompletion(reason)); | ||
} | ||
@@ -979,6 +974,6 @@ if (promiseCapability) { | ||
promiseCapability = PromiseCapability(); | ||
referrer1.#ImportHookCache.set(specifier1, promiseCapability); | ||
referrer.#ImportHookCache.set(specifier, promiseCapability); | ||
try { | ||
const result1 = referrer1.#ImportHook(specifier1, referrer1.#Referral); | ||
if (result1 === null) throw new SyntaxError(`Failed to load module ${specifier1}.`); | ||
const result1 = referrer.#ImportHook(specifier, referrer.#Referral); | ||
if (result1 === null) throw new SyntaxError(`Failed to load module ${specifier}.`); | ||
try { | ||
@@ -992,3 +987,3 @@ const module14 = result1; | ||
Promise.resolve(result1).then((result)=>{ | ||
if (result === null) onRejected(new SyntaxError(`Failed to load module ${specifier1}.`)); | ||
if (result === null) onRejected(new SyntaxError(`Failed to load module ${specifier}.`)); | ||
try { | ||
@@ -1006,27 +1001,25 @@ const module = result; | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-FinishLoadImportedModule | ||
static #FinishLoadImportedModule(referrer2, specifier2, payload1, result2) { | ||
static #FinishLoadImportedModule(referrer1, specifier1, payload1, result2) { | ||
if (result2.Type === 'normal') { | ||
const record = referrer2.#LoadedModules.get(specifier2); | ||
if (record) { | ||
assert(record === result2.Value); | ||
const record1 = referrer1.#LoadedModules.get(specifier1); | ||
if (record1) { | ||
assert(record1 === result2.Value); | ||
} else { | ||
referrer2.#LoadedModules.set(specifier2, result2.Value); | ||
referrer1.#LoadedModules.set(specifier1, result2.Value); | ||
} | ||
} | ||
Module.#DispatchLoadImportedModuleContinuation(payload1, result2); | ||
if (payload1.Action === 'graph-loading') { | ||
Module.#ContinueModuleLoading(payload1, result2); | ||
} else { | ||
Module.#ContinueDynamicImport(payload1, result2); | ||
} | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-DispatchLoadImportedModuleContinuation | ||
static #DispatchLoadImportedModuleContinuation(state4, result3) { | ||
if (state4.Action === 'graph-loading') this.#ContinueModuleLoading(state4, result3); | ||
else this.#ContinueDynamicImport(state4, result3); | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-ContinueDynamicImport | ||
static #ContinueDynamicImport(state5, result4) { | ||
const promiseCapability1 = state5.PromiseCapability; | ||
if (result4.Type === 'throw') { | ||
promiseCapability1.Reject(result4.Value); | ||
static #ContinueDynamicImport(state3, result3) { | ||
assert(state3.Action === 'dynamic-import'); | ||
const promiseCapability1 = state3.PromiseCapability; | ||
if (result3.Type === 'throw') { | ||
promiseCapability1.Reject(result3.Value); | ||
return; | ||
} | ||
const module15 = result4.Value; | ||
const module15 = result3.Value; | ||
const onRejected1 = (reason)=>{ | ||
@@ -1057,3 +1050,2 @@ promiseCapability1.Reject(reason); | ||
/** @internal */ static{ | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-import-call-runtime-semantics-evaluation | ||
imports = async (module, options)=>{ | ||
@@ -1063,12 +1055,5 @@ const promiseCapability = PromiseCapability(); | ||
Action: 'dynamic-import', | ||
PromiseCapability: promiseCapability, | ||
// Note: those three fields are not used in dynamic import. | ||
IsLoading: true, | ||
PendingModules: 1, | ||
Visited: [] | ||
PromiseCapability: promiseCapability | ||
}; | ||
Module.#ContinueDynamicImport(state, { | ||
Type: 'normal', | ||
Value: module | ||
}); | ||
Module.#ContinueDynamicImport(state, NormalCompletion(module)); | ||
return promiseCapability.Promise; | ||
@@ -1075,0 +1060,0 @@ }; |
import { ModuleSource } from './ModuleSource.js'; | ||
import { all, ambiguous, empty, namespace, PromiseCapability, } from './utils/spec.js'; | ||
import { all, ambiguous, empty, namespace, NormalCompletion, PromiseCapability, ThrowCompletion, } from './utils/spec.js'; | ||
import { normalizeBindingsToSpecRecord, normalizeVirtualModuleRecord } from './utils/normalize.js'; | ||
@@ -105,2 +105,3 @@ import { assert, internalError, opaqueProxy } from './utils/assert.js'; | ||
const requestedModule = Module.#GetImportedModule(module, e.ModuleRequest); | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(requestedModule); | ||
@@ -139,2 +140,3 @@ const starNames = requestedModule.#GetExportedNames(exportStarSet); | ||
const importedModule = Module.#GetImportedModule(module, e.ModuleRequest); | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(importedModule); | ||
@@ -160,2 +162,3 @@ if (e.ImportName === all) { | ||
const importedModule = Module.#GetImportedModule(module, e.ModuleRequest); | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(importedModule); | ||
@@ -185,3 +188,2 @@ let resolution = importedModule.#ResolveExport(exportName, resolveSet); | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-LoadRequestedModules | ||
#LoadRequestedModules(HostDefined = undefined) { | ||
@@ -201,5 +203,4 @@ const module = this; | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-InnerModuleLoading | ||
static #InnerModuleLoading(state, module) { | ||
assert(state.IsLoading); | ||
assert(state.Action === 'graph-loading' && state.IsLoading); | ||
if (module.#Status === ModuleStatus.new && !state.Visited.includes(module)) { | ||
@@ -210,3 +211,9 @@ state.Visited.push(module); | ||
for (const required of module.#RequestedModules) { | ||
Module.#LoadImportedModule(module, required, state); | ||
const record = module.#LoadedModules.get(required); | ||
if (record) { | ||
Module.#ContinueModuleLoading(state, NormalCompletion(record)); | ||
} | ||
else { | ||
Module.#HostLoadImportedModule(module, required, state.HostDefined, state); | ||
} | ||
} | ||
@@ -225,4 +232,4 @@ } | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-ContinueModuleLoading | ||
static #ContinueModuleLoading(state, result) { | ||
assert(state.Action === 'graph-loading'); | ||
if (!state.IsLoading) | ||
@@ -348,3 +355,2 @@ return; | ||
if (this.#NeedsImport) { | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-import-call-runtime-semantics-evaluation | ||
this.#ContextObject.import = async (specifier, options) => { | ||
@@ -355,7 +361,4 @@ specifier = String(specifier); | ||
PromiseCapability: PromiseCapability(), | ||
IsLoading: true, | ||
PendingModules: 1, | ||
Visited: [], | ||
}; | ||
Module.#LoadImportedModule(this, specifier, status); | ||
Module.#HostLoadImportedModule(this, specifier, status.HostDefined, status); | ||
return status.PromiseCapability.Promise; | ||
@@ -698,20 +701,6 @@ }; | ||
//#endregion | ||
//#region Module refactor methods https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/ | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-GetImportedModule | ||
//#region Module refactor methods https://github.com/tc39/ecma262/pull/2905/ | ||
static #GetImportedModule(module, spec) { | ||
return module.#LoadedModules.get(spec); | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-LoadImportedModule | ||
static #LoadImportedModule(referrer, specifier, state) { | ||
if (referrer && referrer.#LoadedModules.has(specifier)) { | ||
Module.#DispatchLoadImportedModuleContinuation(state, { | ||
Type: 'normal', | ||
Value: referrer.#LoadedModules.get(specifier), | ||
}); | ||
} | ||
else { | ||
Module.#HostLoadImportedModule(referrer, specifier, state.HostDefined, state); | ||
} | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-HostLoadImportedModule | ||
static #HostLoadImportedModule(referrer, specifier, hostDefined, payload) { | ||
@@ -721,7 +710,7 @@ let promiseCapability = referrer.#ImportHookCache.get(specifier); | ||
promiseCapability?.Resolve(module); | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, { Type: 'normal', Value: module }); | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, NormalCompletion(module)); | ||
} | ||
function onRejected(reason) { | ||
promiseCapability?.Reject(reason); | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, { Type: 'throw', Value: reason }); | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, ThrowCompletion(reason)); | ||
} | ||
@@ -770,3 +759,2 @@ if (promiseCapability) { | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-FinishLoadImportedModule | ||
static #FinishLoadImportedModule(referrer, specifier, payload, result) { | ||
@@ -782,13 +770,11 @@ if (result.Type === 'normal') { | ||
} | ||
Module.#DispatchLoadImportedModuleContinuation(payload, result); | ||
if (payload.Action === 'graph-loading') { | ||
Module.#ContinueModuleLoading(payload, result); | ||
} | ||
else { | ||
Module.#ContinueDynamicImport(payload, result); | ||
} | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-DispatchLoadImportedModuleContinuation | ||
static #DispatchLoadImportedModuleContinuation(state, result) { | ||
if (state.Action === 'graph-loading') | ||
this.#ContinueModuleLoading(state, result); | ||
else | ||
this.#ContinueDynamicImport(state, result); | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-ContinueDynamicImport | ||
static #ContinueDynamicImport(state, result) { | ||
assert(state.Action === 'dynamic-import'); | ||
const promiseCapability = state.PromiseCapability; | ||
@@ -828,3 +814,2 @@ if (result.Type === 'throw') { | ||
static { | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-import-call-runtime-semantics-evaluation | ||
imports = async (module, options) => { | ||
@@ -835,11 +820,4 @@ const promiseCapability = PromiseCapability(); | ||
PromiseCapability: promiseCapability, | ||
// Note: those three fields are not used in dynamic import. | ||
IsLoading: true, | ||
PendingModules: 1, | ||
Visited: [], | ||
}; | ||
Module.#ContinueDynamicImport(state, { | ||
Type: 'normal', | ||
Value: module, | ||
}); | ||
Module.#ContinueDynamicImport(state, NormalCompletion(module)); | ||
return promiseCapability.Promise; | ||
@@ -846,0 +824,0 @@ }; |
@@ -32,2 +32,16 @@ /** @internal */ | ||
} | ||
/** @internal */ | ||
export function NormalCompletion(value) { | ||
return { | ||
Type: 'normal', | ||
Value: value, | ||
}; | ||
} | ||
/** @internal */ | ||
export function ThrowCompletion(error) { | ||
return { | ||
Type: 'throw', | ||
Value: error, | ||
}; | ||
} | ||
//# sourceMappingURL=spec.js.map |
{ | ||
"name": "@masknet/compartment", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -14,3 +14,5 @@ import { ModuleSource } from './ModuleSource.js' | ||
namespace, | ||
NormalCompletion, | ||
PromiseCapability, | ||
ThrowCompletion, | ||
type Completion, | ||
@@ -128,2 +130,3 @@ type ModuleExportEntry, | ||
const requestedModule = Module.#GetImportedModule(module, e.ModuleRequest) | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(requestedModule) | ||
@@ -163,2 +166,3 @@ const starNames = requestedModule.#GetExportedNames(exportStarSet) | ||
const importedModule = Module.#GetImportedModule(module, e.ModuleRequest) | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(importedModule) | ||
@@ -183,2 +187,3 @@ if (e.ImportName === all) { | ||
const importedModule = Module.#GetImportedModule(module, e.ModuleRequest) | ||
// TODO: https://github.com/tc39/ecma262/pull/2905/files#r973044508 | ||
assert(importedModule) | ||
@@ -209,6 +214,5 @@ let resolution = importedModule.#ResolveExport(exportName, resolveSet) | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-LoadRequestedModules | ||
#LoadRequestedModules(HostDefined = undefined) { | ||
const module = this | ||
const pc = PromiseCapability<void | ModuleNamespace>() | ||
const pc = PromiseCapability<void>() | ||
const state: ModuleLoadState = { | ||
@@ -225,5 +229,4 @@ Action: 'graph-loading', | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-InnerModuleLoading | ||
static #InnerModuleLoading(state: ModuleLoadState, module: Module) { | ||
assert(state.IsLoading) | ||
assert(state.Action === 'graph-loading' && state.IsLoading) | ||
if (module.#Status === ModuleStatus.new && !state.Visited.includes(module)) { | ||
@@ -234,3 +237,8 @@ state.Visited.push(module) | ||
for (const required of module.#RequestedModules) { | ||
Module.#LoadImportedModule(module, required, state) | ||
const record = module.#LoadedModules.get(required) | ||
if (record) { | ||
Module.#ContinueModuleLoading(state, NormalCompletion(record)) | ||
} else { | ||
Module.#HostLoadImportedModule(module, required, state.HostDefined, state) | ||
} | ||
} | ||
@@ -248,4 +256,4 @@ } | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-ContinueModuleLoading | ||
static #ContinueModuleLoading(state: ModuleLoadState, result: Completion<Module>) { | ||
assert(state.Action === 'graph-loading') | ||
if (!state.IsLoading) return | ||
@@ -376,3 +384,2 @@ if (result.Type === 'normal') Module.#InnerModuleLoading(state, result.Value) | ||
if (this.#NeedsImport) { | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-import-call-runtime-semantics-evaluation | ||
this.#ContextObject!.import = async (specifier: string, options?: ImportCallOptions) => { | ||
@@ -383,7 +390,4 @@ specifier = String(specifier) | ||
PromiseCapability: PromiseCapability(), | ||
IsLoading: true, | ||
PendingModules: 1, | ||
Visited: [], | ||
} | ||
Module.#LoadImportedModule(this, specifier, status) | ||
Module.#HostLoadImportedModule(this, specifier, status.HostDefined, status) | ||
return status.PromiseCapability.Promise as any | ||
@@ -747,20 +751,7 @@ } | ||
//#region Module refactor methods https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/ | ||
//#region Module refactor methods https://github.com/tc39/ecma262/pull/2905/ | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-GetImportedModule | ||
static #GetImportedModule(module: Module, spec: string) { | ||
return module.#LoadedModules.get(spec) | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-LoadImportedModule | ||
static #LoadImportedModule(referrer: Module, specifier: string, state: ModuleLoadState) { | ||
if (referrer && referrer.#LoadedModules.has(specifier)) { | ||
Module.#DispatchLoadImportedModuleContinuation(state, { | ||
Type: 'normal', | ||
Value: referrer.#LoadedModules.get(specifier)!, | ||
}) | ||
} else { | ||
Module.#HostLoadImportedModule(referrer, specifier, state.HostDefined, state) | ||
} | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-HostLoadImportedModule | ||
static #HostLoadImportedModule( | ||
@@ -775,7 +766,7 @@ referrer: Module, | ||
promiseCapability?.Resolve(module) | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, { Type: 'normal', Value: module }) | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, NormalCompletion(module)) | ||
} | ||
function onRejected(reason: unknown) { | ||
promiseCapability?.Reject(reason) | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, { Type: 'throw', Value: reason }) | ||
Module.#FinishLoadImportedModule(referrer, specifier, payload, ThrowCompletion(reason)) | ||
} | ||
@@ -820,3 +811,2 @@ if (promiseCapability) { | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-FinishLoadImportedModule | ||
static #FinishLoadImportedModule( | ||
@@ -836,12 +826,11 @@ referrer: Module, | ||
} | ||
Module.#DispatchLoadImportedModuleContinuation(payload, result) | ||
if (payload.Action === 'graph-loading') { | ||
Module.#ContinueModuleLoading(payload, result) | ||
} else { | ||
Module.#ContinueDynamicImport(payload, result) | ||
} | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-DispatchLoadImportedModuleContinuation | ||
static #DispatchLoadImportedModuleContinuation(state: ModuleLoadState, result: Completion<Module>) { | ||
if (state.Action === 'graph-loading') this.#ContinueModuleLoading(state, result) | ||
else this.#ContinueDynamicImport(state, result) | ||
} | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-ContinueDynamicImport | ||
static #ContinueDynamicImport(state: ModuleLoadState, result: Completion<Module>) { | ||
assert(state.Action === 'dynamic-import') | ||
const promiseCapability = state.PromiseCapability | ||
@@ -879,3 +868,2 @@ if (result.Type === 'throw') { | ||
static { | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#sec-import-call-runtime-semantics-evaluation | ||
imports = async (module, options) => { | ||
@@ -885,12 +873,5 @@ const promiseCapability = PromiseCapability<ModuleNamespace>() | ||
Action: 'dynamic-import', | ||
PromiseCapability: promiseCapability as any, | ||
// Note: those three fields are not used in dynamic import. | ||
IsLoading: true, | ||
PendingModules: 1, | ||
Visited: [], | ||
PromiseCapability: promiseCapability, | ||
} | ||
Module.#ContinueDynamicImport(state, { | ||
Type: 'normal', | ||
Value: module, | ||
}) | ||
Module.#ContinueDynamicImport(state, NormalCompletion(module)) | ||
return promiseCapability.Promise as any | ||
@@ -906,6 +887,5 @@ } | ||
// https://nicolo-ribaudo.github.io/modules-import-hooks-refactor/#table-moduleloadstate-record-fields | ||
interface ModuleLoadState { | ||
Action: 'graph-loading' | 'dynamic-import' | ||
PromiseCapability: PromiseCapability<void | ModuleNamespace> | ||
interface ModuleLoadState_GraphLoading { | ||
Action: 'graph-loading' | ||
PromiseCapability: PromiseCapability<void> | ||
IsLoading: boolean | ||
@@ -916,2 +896,8 @@ PendingModules: number | ||
} | ||
interface ModuleLoadState_DynamicImport { | ||
Action: 'dynamic-import' | ||
PromiseCapability: PromiseCapability<ModuleNamespace> | ||
HostDefined?: undefined | ||
} | ||
type ModuleLoadState = ModuleLoadState_DynamicImport | ModuleLoadState_GraphLoading | ||
@@ -918,0 +904,0 @@ const enum ModuleStatus { |
@@ -70,1 +70,15 @@ /** @internal */ | ||
export type Completion<T> = NormalCompletion<T> | ThrowCompletion | ||
/** @internal */ | ||
export function NormalCompletion<T>(value: T): NormalCompletion<T> { | ||
return { | ||
Type: 'normal', | ||
Value: value, | ||
} | ||
} | ||
/** @internal */ | ||
export function ThrowCompletion(error: unknown): ThrowCompletion { | ||
return { | ||
Type: 'throw', | ||
Value: error, | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
212115
4108