[JSC] ReferenceError when multiple modules are simultaneously importing a module containing a top-level await#24122
Conversation
|
EWS run on previous version of this PR (hash 7aabdfe) Details |
|
This is a horrible bug. |
|
Is there a work around for this until this is fixed? This is causing a lot of issues for a product I'm working on and supporting Safari. |
The fix proposed in this PR breaks the case of module importing itself. I don't see any other way except for re-implementing the module loader to adhere to the spec (https://tc39.es/ecma262/#cyclic-module-record), which will take some time. |
So what do we do then until this is fixed, tell people not to use Safari? I mean this is a pretty big problem for any modern web application. |
Would be great if this could be prioritized. A lot of people using modern frameworks like SvelteKit or Astro (that use native ESM modules) are running into this, and it's often very hard to debug, so they don't realize it's this bug. |
Thank you for linking the issues, it's super important for our internal bookkeeping. Good news is that this issue being worked on, we are rewriting module loader to adhere to the spec, ETA is only a few weeks. |
|
@shvaikalesh, Is there an update on this? Also, when this gets merged, what is the usual process/timeline for getting this fix out to end users? |
7aabdfe to
aee0d36
Compare
|
EWS run on previous version of this PR (hash aee0d36) Details |
aee0d36 to
a0c5449
Compare
|
EWS run on previous version of this PR (hash a0c5449) Details |
a0c5449 to
8c637db
Compare
|
EWS run on previous version of this PR (hash 8c637db) Details |
8c637db to
3aacdb9
Compare
|
EWS run on previous version of this PR (hash 3aacdb9) Details |
3aacdb9 to
7f9c271
Compare
|
EWS run on previous version of this PR (hash 8541e4f) Details |
8541e4f to
7708e7d
Compare
|
EWS run on previous version of this PR (hash 7708e7d) Details |
Safer C++ Build #909❌ Found 1 new failure. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
|
Safer C++ Build #936❌ Found 1 new failure. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
|
…ng a module containing a top-level await https://bugs.webkit.org/show_bug.cgi?id=242740 <rdar://problem/97370038> Reviewed by NOBODY (OOPS!). This change completely re-implements module loader to precisely follow the spec steps [1], resolving multiple issues revolving around importing modules with top-level `await`. Infinite retry of module fetching & parsing is removed as it's not part of the spec, nor other browsers behave in the same way. This patch also rewires the way module loader is hooked into workers / worklets, which became necessary due to functions like evaluateModule() became always `async`. Along with this, errors occuring in modules with top-level `await` are now properly reported to the console, resolving another developers' pain point. [1]: https://tc39.es/ecma262/#sec-cyclic-module-records * JSTests/test262/expectations.yaml: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.sharedworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-workerglobalscope-onerror-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-workerglobalscope-onerror-module-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/evaluation-order-1-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/evaluation-order-1-throw-importScripts.any.sharedworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/evaluation-order-1-throw-importScripts.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/evaluation-order-2-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/choice-of-error-2-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/choice-of-error-3-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/crossorigin-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/blob-url.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/blob-url.any.sharedworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/blob-url.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/dynamic-imports-fetch-error.sub-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/dynamic-imports-script-error-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/error-type-2-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/error-type-3-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-error-1-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-error-2-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-error-3-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/evaluation-error-4-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-1-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-2-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-3-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-4-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-5-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-6-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-7-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-processing-algorithm-error/worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-blob-url.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-blob-url.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-import-failure-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/modules/dedicated-worker-parse-error-failure-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/modules/shared-worker-import-blob-url.window-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/modules/shared-worker-parse-error-failure-expected.txt: * Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj: * Source/JavaScriptCore/builtins/BuiltinNames.h: * Source/JavaScriptCore/builtins/ModuleLoader.js: (visibility.PrivateRecursive.ensureModuleMapEntry): (visibility.PrivateRecursive.hostFetchAndLoadImportedModule): (visibility.PrivateRecursive.hostLoadImportedModule): (visibility.PrivateRecursive.fetchDescendantsOfAndLink): (visibility.PrivateRecursive.innerModuleLoading): (visibility.PrivateRecursive.moduleLinking): (visibility.PrivateRecursive.innerModuleLinking): (visibility.PrivateRecursive.moduleEvaluation): (visibility.PrivateRecursive.innerModuleEvaluation): (visibility.PrivateRecursive.async executeAsyncModule): (linkTimeConstant.gatherAvailableAncestors): (visibility.PrivateRecursive.asyncModuleExecutionFulfilled): (linkTimeConstant.asyncModuleExecutionRejected): (visibility.PrivateRecursive.fetchModule): (visibility.PrivateRecursive.fetchModuleAndEvaluate): (visibility.PrivateRecursive.evaluateModule): (visibility.PrivateRecursive.loadModule): (visibility.PrivateRecursive.loadModuleAndEvaluate): (visibility.PrivateRecursive.requestImportModule): (visibility.PrivateRecursive.dependencyKeysIfEvaluated): (linkTimeConstant.setStateToMax): Deleted. (linkTimeConstant.newRegistryEntry): Deleted. (visibility.PrivateRecursive.ensureRegistered): Deleted. (linkTimeConstant.forceFulfillPromise): Deleted. (linkTimeConstant.fulfillFetch): Deleted. (visibility.PrivateRecursive.requestFetch): Deleted. (linkTimeConstant.cacheSatisfy): Deleted. (async linkTimeConstant.cacheSatisfyAndReturn): Deleted. (visibility.PrivateRecursive.requestSatisfy): Deleted. (visibility.PrivateRecursive.requestSatisfyUtil): Deleted. (visibility.PrivateRecursive.link): Deleted. (visibility.PrivateRecursive.async asyncModuleEvaluation): Deleted. (visibility.PrivateRecursive.provideFetch): Deleted. (visibility.PrivateRecursive.async loadModule): Deleted. (visibility.PrivateRecursive.linkAndEvaluateModule): Deleted. (visibility.PrivateRecursive.async loadAndEvaluateModule): Deleted. (visibility.PrivateRecursive.async requestImportModule): Deleted. * Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp: (JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry): * Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h: * Source/JavaScriptCore/jsc.cpp: (dumpException): (runWithOptions): * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseInner): * Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp: (JSC::AbstractModuleRecord::hostResolveImportedModule): (JSC::AbstractModuleRecord::link): * Source/JavaScriptCore/runtime/ArrayPrototype.cpp: (JSC::ArrayPrototype::finishCreation): * Source/JavaScriptCore/runtime/Completion.cpp: (JSC::createSymbolForEntryPointModule): Deleted. (JSC::rejectPromise): Deleted. (JSC::loadAndEvaluateModule): Deleted. (JSC::loadModule): Deleted. (JSC::linkAndEvaluateModule): Deleted. * Source/JavaScriptCore/runtime/Completion.h: * Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/JSModuleLoader.cpp: (JSC::JSModuleLoader::finishCreation): (JSC::createSymbolForEntryPointModule): (JSC::JSModuleLoader::loadModule): (JSC::JSModuleLoader::loadModuleAndEvaluate): (JSC::JSModuleLoader::fetchModule): (JSC::JSModuleLoader::fetchModuleAndEvaluate): (JSC::JSModuleLoader::evaluateModule): (JSC::JSC_DEFINE_HOST_FUNCTION): (JSC::JSModuleLoader::provideFetch): Deleted. (JSC::JSModuleLoader::loadAndEvaluateModule): Deleted. (JSC::JSModuleLoader::linkAndEvaluateModule): Deleted. * Source/JavaScriptCore/runtime/JSModuleLoader.h: * Source/JavaScriptCore/runtime/SyntheticModuleRecord.cpp: (JSC::SyntheticModuleRecord::link): * Source/JavaScriptCore/runtime/SyntheticModuleRecord.h: * Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): * Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h: * Source/WebCore/bindings/js/JSExecState.h: (WebCore::JSExecState::loadModule): (WebCore::JSExecState::loadModuleAndEvaluate): (WebCore::JSExecState::fetchModule): (WebCore::JSExecState::fetchModuleAndEvaluate): (WebCore::JSExecState::evaluateModule): (WebCore::JSExecState::linkAndEvaluateModule): Deleted. * Source/WebCore/bindings/js/ScheduledAction.cpp: (WebCore::ScheduledAction::execute): * Source/WebCore/bindings/js/ScriptController.cpp: (WebCore::ScriptController::loadModuleScriptInWorld): (WebCore::ScriptController::evaluateModuleScriptInWorld): (WebCore::ScriptController::evaluateModuleScript): (WebCore::ScriptController::linkAndEvaluateModuleScriptInWorld): Deleted. (WebCore::ScriptController::linkAndEvaluateModuleScript): Deleted. * Source/WebCore/bindings/js/ScriptController.h: * Source/WebCore/bindings/js/WorkerScriptFetcher.h: * Source/WebCore/dom/ScriptElement.cpp: (WebCore::ScriptElement::executeModuleScript): * Source/WebCore/workers/DedicatedWorkerThread.h: (WebCore::DedicatedWorkerThread::workerObjectProxy const): (WebCore::DedicatedWorkerThread::start): Deleted. * Source/WebCore/workers/WorkerOrWorkletScriptController.cpp: (WebCore::WorkerOrWorkletScriptController::evaluateAndReportException): (WebCore::WorkerOrWorkletScriptController::evaluate): (WebCore::WorkerOrWorkletScriptController::loadModuleAndEvaluate): (WebCore::WorkerOrWorkletScriptController::fetchWorkletModuleAndEvaluate): (WebCore::jsValueToModuleKey): Deleted. (WebCore::WorkerOrWorkletScriptController::loadModuleSynchronously): Deleted. (WebCore::WorkerOrWorkletScriptController::linkAndEvaluateModule): Deleted. (WebCore::WorkerOrWorkletScriptController::loadAndEvaluateModule): Deleted. * Source/WebCore/workers/WorkerOrWorkletScriptController.h: * Source/WebCore/workers/WorkerOrWorkletThread.cpp: (WebCore::WorkerOrWorkletThread::workerOrWorkletThread): * Source/WebCore/workers/WorkerOrWorkletThread.h: (WebCore::WorkerOrWorkletThread::evaluateScriptIfNecessary): * Source/WebCore/workers/WorkerThread.cpp: (WebCore::WorkerThread::evaluateScriptIfNecessary): * Source/WebCore/workers/WorkerThread.h: * Source/WebCore/workers/shared/context/SharedWorkerContextManager.cpp: (WebCore::SharedWorkerContextManager::registerSharedWorkerThread): * Source/WebCore/worklets/WorkletGlobalScope.cpp: (WebCore::WorkletGlobalScope::evaluate): (WebCore::WorkletGlobalScope::fetchAndInvokeScript):
7708e7d to
cf39202
Compare
|
EWS run on current version of this PR (hash cf39202) Details |
Safer C++ Build #988❌ Found 1 new failure. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
|
|
Just expressing additional interest in seeing these changes go through as it's not uncommon to run into this issue. Thanks for the hard work |
Ditto! |
Ditto |
|
This PR requires significant feature-level work to complete. We don't currently have anyone working on it, but we hear the requests and will consider it in our planning. Thanks. |
|
I’m so glad someone took a crack at this, but it seems like we need quite a bit more work to complete it. |
|
is there any workaround possible, for example retrying a failed import? Any application that wants to have client code blocked until environment-specific code ran will encounter this, right? |
|
I hope this will be merged soon |
|
There's an on-going rewrite that will fix this issue: #57827 |
🧪 api-wpe
cf39202
cf39202