Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ JSPromise* loadAndEvaluateModule(JSGlobalObject* globalObject, SourceCode&& sour
ScriptFetchParameters::Type type = getSourceType(source);

// Insert the given source code to the ModuleLoader registry as the fetched registry entry.
globalObject->moduleLoader()->provideFetch(globalObject, key, type, WTF::move(source));
ModuleRegistryEntry* entry = globalObject->moduleLoader()->provideFetch(globalObject, key, type, WTF::move(source));
RETURN_IF_EXCEPTION(scope, rejectPromise(scope, globalObject));

JSPromise* statePromise = JSPromise::create(vm, globalObject->promiseStructure());
Expand All @@ -253,7 +253,7 @@ JSPromise* loadAndEvaluateModule(JSGlobalObject* globalObject, SourceCode&& sour

AbstractModuleRecord::ModuleRequest request { WTF::move(key), ScriptFetchParameters::create(type) };

JSPromise* promise = globalObject->moduleLoader()->loadModule(globalObject, globalObject, request, graphLoadingState, WTF::move(scriptFetcher), { ModuleLoadFlag::Evaluate });
JSPromise* promise = globalObject->moduleLoader()->loadModule(globalObject, entry, request, graphLoadingState, WTF::move(scriptFetcher), { ModuleLoadFlag::Evaluate });
RETURN_IF_EXCEPTION(scope, rejectPromise(scope, globalObject));

JSPromise* resultPromise = JSPromise::create(vm, globalObject->promiseStructure());
Expand Down
55 changes: 12 additions & 43 deletions Source/JavaScriptCore/runtime/JSMicrotask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,27 +1173,13 @@ static void moduleLoadTopSettled(JSGlobalObject* globalObject, VM& vm, ThrowScop
// arguments[1] = resolution (JSSourceCode*) or error
// arguments[2] = ModuleLoadingContext*
auto* context = uncheckedDowncast<ModuleLoadingContext>(arguments[2]);
auto* entry = context->entry();
auto* intermediatePromise = uncheckedDowncast<JSPromise>(arguments[0]);
auto status = static_cast<JSPromise::Status>(payload);
if (status == JSPromise::Status::Fulfilled) {
const Identifier& specifier = context->moduleRequest().m_specifier;
auto type = context->moduleRequest().type();
ScriptFetcher* scriptFetcher = context->scriptFetcher();

#if USE(BUN_JSC_ADDITIONS)
// ModuleRegistryEntry::provideModule(): the entry already holds its record, nothing to provide.
if (!arguments[1].inherits<AbstractModuleRecord>()) {
#endif
auto* jsSourceCode = downcast<JSSourceCode>(arguments[1]);
context->loader()->provideFetch(globalObject, specifier, type, jsSourceCode);
if (scope.exception()) {
intermediatePromise->rejectWithCaughtException(vm, scope);
return;
}
#if USE(BUN_JSC_ADDITIONS)
}
#endif

JSPromise* statePromise = JSPromise::create(vm, globalObject->promiseStructure());
statePromise->markAsHandled();
AbstractModuleRecord::ModuleRequest request { specifier, context->moduleRequest().m_attributes };
Expand All @@ -1203,20 +1189,18 @@ static void moduleLoadTopSettled(JSGlobalObject* globalObject, VM& vm, ThrowScop
JSPromise* loadPromise;

OptionSet<ModuleLoadFlag> innerLoadFlags;
if (context->useImportMap())
innerLoadFlags.add(ModuleLoadFlag::UseImportMap);
if (context->dynamic()) {
#if USE(BUN_JSC_ADDITIONS)
combinedCell = ModuleLoaderPayload::create(vm, statePromise, context->deferred(), context->referrerAsyncOrder());
#else
combinedCell = ModuleLoaderPayload::create(vm, statePromise, context->deferred());
#endif
loadPromise = context->loader()->loadModule(globalObject, globalObject, request, combinedCell, scriptFetcher, innerLoadFlags);
loadPromise = context->loader()->loadModule(globalObject, entry, request, combinedCell, scriptFetcher, innerLoadFlags);
} else {
combinedCell = ModuleGraphLoadingState::create(vm, statePromise, scriptFetcher);
if (context->evaluate())
innerLoadFlags.add(ModuleLoadFlag::Evaluate);
loadPromise = context->loader()->loadModule(globalObject, globalObject, request, combinedCell, scriptFetcher, innerLoadFlags);
loadPromise = context->loader()->loadModule(globalObject, entry, request, combinedCell, scriptFetcher, innerLoadFlags);
if (scope.exception()) {
intermediatePromise->rejectWithCaughtException(vm, scope);
return;
Expand Down Expand Up @@ -1245,19 +1229,13 @@ static void moduleLoadTopSettled(JSGlobalObject* globalObject, VM& vm, ThrowScop
const Identifier& specifier = context->moduleRequest().m_specifier;
auto type = context->moduleRequest().type();
JSValue errorValue = arguments[1];
if (auto* error = dynamicDowncast<ErrorInstance>(errorValue)) {
auto failure = JSModuleLoader::getErrorInfo(globalObject, error);
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script step 13.1
// Don't register the module unless it's an evaluation error.
if (failure.isEvaluationError(specifier, type)) {
ModuleRegistryEntry* entry = context->loader()->ensureRegistered(globalObject, specifier, type);
if (scope.exception()) {
intermediatePromise->rejectWithCaughtException(vm, scope);
return;
}
entry->setEvaluationError(globalObject, error);
}
}
auto* error = dynamicDowncast<ErrorInstance>(errorValue);
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script step 13.1
// Don't keep the module registered unless it's an evaluation error.
if (error && JSModuleLoader::getErrorInfo(globalObject, error).isEvaluationError(specifier, type))
entry->setEvaluationError(globalObject, error);
else
entry->setFetchError(globalObject, errorValue);
Comment thread
dylan-conway marked this conversation as resolved.
Resolved
intermediatePromise->reject(vm, errorValue);
}
}
Expand All @@ -1274,12 +1252,7 @@ static void moduleLoadTopRejected(JSGlobalObject* globalObject, VM& vm, std::spa
if (status == JSPromise::Status::Fulfilled)
resultPromise->fulfill(vm, arguments[1]);
else {
const Identifier& specifier = context->moduleRequest().m_specifier;
auto type = context->moduleRequest().type();
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script step 13.1
// Only set an error if the entry already exists.
if (ModuleRegistryEntry* entry = context->loader()->getRegisteredMayBeNull(specifier, type))
entry->setEvaluationError(globalObject, arguments[1]);
context->entry()->setEvaluationError(globalObject, arguments[1]);
resultPromise->reject(vm, arguments[1]);
}
}
Expand Down Expand Up @@ -1431,11 +1404,7 @@ static void moduleLoadStoreError(JSGlobalObject* globalObject, std::span<const J
JSValue errorValue = arguments[1];
const Identifier& specifier = context->moduleRequest().m_specifier;
auto type = context->moduleRequest().type();
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script step 13.1
// Only set an error if the entry already exists.
ModuleRegistryEntry* entry = context->loader()->getRegisteredMayBeNull(specifier, type);
if (!entry)
return;
ModuleRegistryEntry* entry = context->entry();
if (auto* error = dynamicDowncast<ErrorInstance>(errorValue)) {
auto failure = JSModuleLoader::getErrorInfo(globalObject, error);
if (failure.isEvaluationError(specifier, type))
Expand Down
Loading
Loading