Skip to content

Commit

Permalink
Backed out 4 changesets (bug 1689499, bug 1686218) for causing failur…
Browse files Browse the repository at this point in the history
…e at bug1689499.js;module;async. CLOSED TREE

Backed out changeset e5819ad68d91 (bug 1686218)
Backed out changeset b42024c79b4c (bug 1689499)
Backed out changeset 83dcd14e375a (bug 1689499)
Backed out changeset bf45ac283ab7 (bug 1689499)
  • Loading branch information
Butkovits Atila committed Feb 24, 2021
1 parent d537f75 commit df23c6e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 96 deletions.
10 changes: 4 additions & 6 deletions js/src/builtin/Module.js
Expand Up @@ -594,7 +594,7 @@ function ModuleEvaluate()
if (isTopLevelAwaitEnabled) {
// Top-level Await Step 4
if (module.status === MODULE_STATUS_EVALUATED) {
module = GetCycleRoot(module);
module = GetAsyncCycleRoot(module);
}

// Top-level Await Step 5
Expand Down Expand Up @@ -713,11 +713,11 @@ function InnerModuleEvaluation(module, stack, index)
requiredModule.dfsAncestorIndex));
} else {
if (isTopLevelAwaitEnabled) {
requiredModule = GetCycleRoot(requiredModule);
assert(requiredModule.status >= MODULE_STATUS_EVALUATED,
requiredModule = GetAsyncCycleRoot(requiredModule);
assert(requiredModule.status === MODULE_STATUS_EVALUATED,
`Bad module status in InnerModuleEvaluation: ${requiredModule.status}`);
if (requiredModule.evaluationError) {
throw GetModuleEvaluationError(requiredModule);
throw GetModuleEvaluationError(module);
}
}
}
Expand Down Expand Up @@ -757,12 +757,10 @@ function InnerModuleEvaluation(module, stack, index)

// Step 14
if (module.dfsAncestorIndex === module.dfsIndex) {
let cycleRoot = module;
let requiredModule;
do {
requiredModule = callFunction(std_Array_pop, stack);
ModuleSetStatus(requiredModule, MODULE_STATUS_EVALUATED);
SetCycleRoot(requiredModule, cycleRoot);
} while (requiredModule !== module);
}

Expand Down
66 changes: 44 additions & 22 deletions js/src/builtin/ModuleObject.cpp
Expand Up @@ -994,9 +994,7 @@ uint32_t ModuleObject::dfsAncestorIndex() const {
}

JSObject* ModuleObject::topLevelCapability() const {
Value capability = getReservedSlot(TopLevelCapabilitySlot);
MOZ_RELEASE_ASSERT(capability.isObject());
return &capability.toObject();
return &getReservedSlot(TopLevelCapabilitySlot).toObject();
}

PromiseObject* ModuleObject::createTopLevelCapability(
Expand Down Expand Up @@ -1033,16 +1031,6 @@ void ModuleObject::setPendingAsyncDependencies(uint32_t newValue) {
return setReservedSlot(PendingAsyncDependenciesSlot, NumberValue(newValue));
}

void ModuleObject::setCycleRoot(ModuleObject* cycleRoot) {
return setReservedSlot(CycleRootSlot, ObjectValue(*cycleRoot));
}

ModuleObject* ModuleObject::getCycleRoot() const {
Value cycleRoot = getReservedSlot(CycleRootSlot);
MOZ_RELEASE_ASSERT(cycleRoot.isObject());
return &cycleRoot.toObject().as<ModuleObject>();
}

bool ModuleObject::hasTopLevelCapability() const {
return !getReservedSlot(TopLevelCapabilitySlot).isUndefined();
}
Expand Down Expand Up @@ -1972,6 +1960,36 @@ JSObject* js::CallModuleResolveHook(JSContext* cx,
return result;
}

// https://tc39.es/proposal-top-level-await/#sec-getasynccycleroot
ModuleObject* js::GetAsyncCycleRoot(ModuleObject* module) {
// Step 1.
MOZ_ASSERT(module->status() == MODULE_STATUS_EVALUATED);

// Step 2.
if (module->asyncParentModules()->empty()) {
return module;
}

// Step 3.
ModuleObject* currentModule = module;
while (currentModule->dfsIndex() > currentModule->dfsAncestorIndex()) {
MOZ_ASSERT(!currentModule->asyncParentModules()->empty());
ModuleObject* nextCycleModule = &currentModule->asyncParentModules()
->get(0)
.toObject()
.as<ModuleObject>();
MOZ_ASSERT(nextCycleModule->dfsAncestorIndex() <=
currentModule->dfsAncestorIndex());
currentModule = nextCycleModule;
}

// Step 4.
MOZ_ASSERT(currentModule->dfsIndex() == currentModule->dfsAncestorIndex());

// Step 5.
return currentModule;
}

bool js::AsyncModuleExecutionFulfilledHandler(JSContext* cx, unsigned argc,
Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
Expand Down Expand Up @@ -2026,12 +2044,16 @@ void js::AsyncModuleExecutionFulfilled(JSContext* cx,
for (uint32_t i = 0; i < length; i++) {
m = &module->asyncParentModules()->get(i).toObject().as<ModuleObject>();

if (module->dfsIndex() != module->dfsAncestorIndex()) {
MOZ_ASSERT(m->dfsAncestorIndex() <= module->dfsAncestorIndex());
}

m->setPendingAsyncDependencies(m->pendingAsyncDependencies() - 1);

if (m->pendingAsyncDependencies() == 0 && !m->hadEvaluationError()) {
MOZ_ASSERT(m->isAsyncEvaluating());

cycleRoot = m->getCycleRoot();
cycleRoot = GetAsyncCycleRoot(m);

if (cycleRoot->hadEvaluationError()) {
return;
Expand All @@ -2056,7 +2078,7 @@ void js::AsyncModuleExecutionFulfilled(JSContext* cx,

// Step 6.
if (module->hasTopLevelCapability()) {
MOZ_ASSERT(module->getCycleRoot() == module);
MOZ_ASSERT(module->dfsIndex() == module->dfsAncestorIndex());
ModuleObject::topLevelCapabilityResolve(cx, module);
}

Expand All @@ -2067,8 +2089,7 @@ void js::AsyncModuleExecutionFulfilled(JSContext* cx,
void js::AsyncModuleExecutionRejected(JSContext* cx, HandleModuleObject module,
HandleValue error) {
// Step 1.
MOZ_ASSERT(module->status() == MODULE_STATUS_EVALUATED ||
module->status() == MODULE_STATUS_EVALUATED_ERROR);
MOZ_ASSERT(module->status() == MODULE_STATUS_EVALUATED);

// Step 2.
if (!module->isAsyncEvaluating()) {
Expand All @@ -2091,12 +2112,15 @@ void js::AsyncModuleExecutionRejected(JSContext* cx, HandleModuleObject module,
for (uint32_t i = 0; i < length; i++) {
parent =
&module->asyncParentModules()->get(i).toObject().as<ModuleObject>();
if (module->dfsIndex() != module->dfsAncestorIndex()) {
MOZ_ASSERT(parent->dfsAncestorIndex() == module->dfsAncestorIndex());
}
AsyncModuleExecutionRejected(cx, parent, error);
}

// Step 7.
if (module->hasTopLevelCapability()) {
MOZ_ASSERT(module->getCycleRoot() == module);
MOZ_ASSERT(module->dfsIndex() == module->dfsAncestorIndex());
ModuleObject::topLevelCapabilityReject(cx, module, error);
}

Expand Down Expand Up @@ -2234,10 +2258,8 @@ static bool OnResolvedDynamicModule(JSContext* cx, unsigned argc, Value* vp) {
return RejectPromiseWithPendingError(cx, promise);
}

MOZ_ASSERT(module->getCycleRoot()
->topLevelCapability()
->as<PromiseObject>()
.state() == JS::PromiseState::Fulfilled);
MOZ_ASSERT(module->topLevelCapability()->as<PromiseObject>().state() ==
JS::PromiseState::Fulfilled);

RootedObject ns(cx, ModuleObject::GetOrCreateModuleNamespace(cx, module));
if (!ns) {
Expand Down
6 changes: 3 additions & 3 deletions js/src/builtin/ModuleObject.h
Expand Up @@ -277,7 +277,6 @@ class ModuleObject : public NativeObject {
TopLevelCapabilitySlot,
AsyncParentModulesSlot,
PendingAsyncDependenciesSlot,
CycleRootSlot,
SlotCount
};

Expand Down Expand Up @@ -357,8 +356,6 @@ class ModuleObject : public NativeObject {
JSObject* topLevelCapability() const;
ListObject* asyncParentModules() const;
uint32_t pendingAsyncDependencies() const;
void setCycleRoot(ModuleObject* cycleRoot);
ModuleObject* getCycleRoot() const;

static bool appendAsyncParentModule(JSContext* cx, HandleModuleObject self,
HandleModuleObject parent);
Expand Down Expand Up @@ -414,6 +411,9 @@ JSObject* GetOrCreateModuleMetaObject(JSContext* cx, HandleObject module);
JSObject* CallModuleResolveHook(JSContext* cx, HandleValue referencingPrivate,
HandleString specifier);

// https://tc39.es/proposal-top-level-await/#sec-getasynccycleroot
ModuleObject* GetAsyncCycleRoot(ModuleObject* module);

// https://tc39.es/proposal-top-level-await/#sec-asyncmodulexecutionfulfilled
void AsyncModuleExecutionFulfilled(JSContext* cx, HandleModuleObject module);

Expand Down
5 changes: 0 additions & 5 deletions js/src/tests/non262/module/bug1689499-a.js

This file was deleted.

6 changes: 0 additions & 6 deletions js/src/tests/non262/module/bug1689499-b.js

This file was deleted.

8 changes: 0 additions & 8 deletions js/src/tests/non262/module/bug1689499-c.js

This file was deleted.

3 changes: 0 additions & 3 deletions js/src/tests/non262/module/bug1689499-x.js

This file was deleted.

29 changes: 0 additions & 29 deletions js/src/tests/non262/module/bug1689499.js

This file was deleted.

18 changes: 4 additions & 14 deletions js/src/vm/SelfHosting.cpp
Expand Up @@ -1951,21 +1951,12 @@ static bool intrinsic_IsTopLevelAwaitEnabled(JSContext* cx, unsigned argc,
return true;
}

static bool intrinsic_SetCycleRoot(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 2);
RootedModuleObject module(cx, &args[0].toObject().as<ModuleObject>());
RootedModuleObject cycleRoot(cx, &args[1].toObject().as<ModuleObject>());
module->setCycleRoot(cycleRoot);
args.rval().setUndefined();
return true;
}

static bool intrinsic_GetCycleRoot(JSContext* cx, unsigned argc, Value* vp) {
static bool intrinsic_GetAsyncCycleRoot(JSContext* cx, unsigned argc,
Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 1);
RootedModuleObject module(cx, &args[0].toObject().as<ModuleObject>());
JSObject* result = module->getCycleRoot();
JSObject* result = js::GetAsyncCycleRoot(module);
if (!result) {
return false;
}
Expand Down Expand Up @@ -2606,8 +2597,7 @@ static const JSFunctionSpec intrinsic_functions[] = {
intrinsic_InstantiateModuleFunctionDeclarations, 1, 0),
JS_FN("ExecuteModule", intrinsic_ExecuteModule, 1, 0),
JS_FN("IsTopLevelAwaitEnabled", intrinsic_IsTopLevelAwaitEnabled, 0, 0),
JS_FN("SetCycleRoot", intrinsic_SetCycleRoot, 2, 0),
JS_FN("GetCycleRoot", intrinsic_GetCycleRoot, 1, 0),
JS_FN("GetAsyncCycleRoot", intrinsic_GetAsyncCycleRoot, 1, 0),
JS_FN("AppendAsyncParentModule", intrinsic_AppendAsyncParentModule, 2, 0),
JS_FN("CreateTopLevelCapability", intrinsic_CreateTopLevelCapability, 1, 0),
JS_FN("ModuleTopLevelCapabilityResolve",
Expand Down

0 comments on commit df23c6e

Please sign in to comment.