Skip to content

Commit 904be1c

Browse files
committed
Bug 1992103 - Align async modules rejection order with fulfillment order r=jonco
This patch inverts the order in which we reject promises in AsyncModuleExecutionRejected to match AsyncModuleExecutionFulfilled: first the promise corresponding to the leaf module (the one that throws) is rejected, and then its ancestors. This change was discussed at the July 2025 TC39 meeting. Spec PR: tc39/ecma262#3695 test262: tc39/test262#4591 Differential Revision: https://phabricator.services.mozilla.com/D267210 UltraBlame original commit: a3cf4d1eef17209c4c4194e07f38fe870c417781
1 parent 6eefa29 commit 904be1c

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

js/src/vm/Modules.cpp

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,35 @@ JS_PUBLIC_API JSObject* JS::CompileJsonModule(
294294
return moduleObject;
295295
}
296296

297+
JS_PUBLIC_API JSObject* JS::CreateCssModule(
298+
JSContext* cx, const ReadOnlyCompileOptions& options,
299+
const Value& cssValue) {
300+
Rooted<ExportNameVector> exportNames(cx);
301+
if (!exportNames.append(cx->names().default_)) {
302+
ReportOutOfMemory(cx);
303+
return nullptr;
304+
}
305+
306+
Rooted<ModuleObject*> moduleObject(
307+
cx, ModuleObject::createSynthetic(cx, &exportNames));
308+
if (!moduleObject) {
309+
return nullptr;
310+
}
311+
312+
RootedVector<Value> exportValues(cx);
313+
if (!exportValues.append(cssValue)) {
314+
ReportOutOfMemory(cx);
315+
return nullptr;
316+
}
317+
318+
if (!ModuleObject::createSyntheticEnvironment(cx, moduleObject,
319+
exportValues)) {
320+
return nullptr;
321+
}
322+
323+
return moduleObject;
324+
}
325+
297326
JS_PUBLIC_API void JS::SetModulePrivate(JSObject* module, const Value& value) {
298327
JSRuntime* rt = module->zone()->runtimeFromMainThread();
299328
module->as<ModuleObject>().scriptSourceObject()->setPrivate(rt, value);
@@ -2492,18 +2521,8 @@ void js::AsyncModuleExecutionRejected(JSContext* cx,
24922521

24932522
MOZ_ASSERT(module->status() == ModuleStatus::Evaluated);
24942523

2495-
module->clearAsyncEvaluatingPostOrder();
2496-
24972524

2498-
2499-
Rooted<ListObject*> parents(cx, module->asyncParentModules());
2500-
Rooted<ModuleObject*> parent(cx);
2501-
for (uint32_t i = 0; i < parents->length(); i++) {
2502-
parent = &parents->get(i).toObject().as<ModuleObject>();
2503-
2504-
2505-
AsyncModuleExecutionRejected(cx, parent, error);
2506-
}
2525+
module->clearAsyncEvaluatingPostOrder();
25072526

25082527

25092528
if (module->hasTopLevelCapability()) {
@@ -2519,6 +2538,17 @@ void js::AsyncModuleExecutionRejected(JSContext* cx,
25192538
}
25202539

25212540

2541+
2542+
Rooted<ListObject*> parents(cx, module->asyncParentModules());
2543+
Rooted<ModuleObject*> parent(cx);
2544+
for (uint32_t i = 0; i < parents->length(); i++) {
2545+
parent = &parents->get(i).toObject().as<ModuleObject>();
2546+
2547+
2548+
AsyncModuleExecutionRejected(cx, parent, error);
2549+
}
2550+
2551+
25222552
}
25232553

25242554

0 commit comments

Comments
 (0)