mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
deps: v8 backport 9689b17687b
[top-level-await] Implement spec fix for cycle root detection Refs: http://github.com/v8/v8/commit/9689b17687b21c800c3f7400df4255c55b9c6ec0 PR-URL: https://github.com/nodejs/node/pull/37865 Backport-PR-URL: https://github.com/nodejs/node/pull/37985 Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
1 parent
f2cef54b6f
commit
2fd97ce687
13 files changed
+109
-62
No files matched your search
+1
-1
@@ -36,7 +36,7 @@
|
||||
|
||||
# Reset this number to 0 on major V8 upgrades.
|
||||
# Increment by one for each non-official patch applied to deps/v8.
|
||||
'v8_embedder_string': '-node.27',
|
||||
'v8_embedder_string': '-node.28',
|
||||
|
||||
##### V8 defaults for Node.js #####
|
||||
|
||||
|
||||
+1
@@ -1601,6 +1601,7 @@ void SourceTextModule::SourceTextModulePrint(std::ostream& os) { // NOLINT
|
||||
os << "\n - requested_modules: " << Brief(requested_modules());
|
||||
os << "\n - script: " << Brief(script());
|
||||
os << "\n - import_meta: " << Brief(import_meta());
|
||||
os << "\n - cycle_root: " << Brief(cycle_root());
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -2505,6 +2505,7 @@ Handle<SourceTextModule> Factory::NewSourceTextModule(
|
||||
module->set_flags(0);
|
||||
module->set_async(IsAsyncModule(code->kind()));
|
||||
module->set_async_evaluating(false);
|
||||
module->set_cycle_root(roots.the_hole_value());
|
||||
module->set_async_parent_modules(*async_parent_modules);
|
||||
module->set_pending_async_dependencies(0);
|
||||
return module;
|
||||
|
||||
Vendored
+8
@@ -112,6 +112,14 @@ class UnorderedModuleSet
|
||||
ZoneAllocator<Handle<Module>>(zone)) {}
|
||||
};
|
||||
|
||||
Handle<SourceTextModule> SourceTextModule::GetCycleRoot(
|
||||
Isolate* isolate) const {
|
||||
CHECK_GE(status(), kEvaluated);
|
||||
DCHECK(!cycle_root().IsTheHole(isolate));
|
||||
Handle<SourceTextModule> root(SourceTextModule::cast(cycle_root()), isolate);
|
||||
return root;
|
||||
}
|
||||
|
||||
void SourceTextModule::AddAsyncParentModule(Isolate* isolate,
|
||||
Handle<SourceTextModule> module,
|
||||
Handle<SourceTextModule> parent) {
|
||||
|
||||
+14
-57
@@ -397,6 +397,7 @@ bool SourceTextModule::MaybeTransitionComponent(
|
||||
DCHECK_LE(module->dfs_ancestor_index(), module->dfs_index());
|
||||
if (module->dfs_ancestor_index() == module->dfs_index()) {
|
||||
// This is the root of its strongly connected component.
|
||||
Handle<SourceTextModule> cycle_root = module;
|
||||
Handle<SourceTextModule> ancestor;
|
||||
do {
|
||||
ancestor = stack->front();
|
||||
@@ -406,6 +407,9 @@ bool SourceTextModule::MaybeTransitionComponent(
|
||||
if (new_status == kInstantiated) {
|
||||
if (!SourceTextModule::RunInitializationCode(isolate, ancestor))
|
||||
return false;
|
||||
} else if (new_status == kEvaluated) {
|
||||
DCHECK(ancestor->cycle_root().IsTheHole(isolate));
|
||||
ancestor->set_cycle_root(*cycle_root);
|
||||
}
|
||||
ancestor->SetStatus(new_status);
|
||||
} while (*ancestor != *module);
|
||||
@@ -619,9 +623,9 @@ MaybeHandle<Object> SourceTextModule::EvaluateMaybeAsync(
|
||||
CHECK(module->status() == kInstantiated || module->status() == kEvaluated);
|
||||
|
||||
// 3. If module.[[Status]] is "evaluated", set module to
|
||||
// GetAsyncCycleRoot(module).
|
||||
// module.[[CycleRoot]].
|
||||
if (module->status() == kEvaluated) {
|
||||
module = GetAsyncCycleRoot(isolate, module);
|
||||
module = module->GetCycleRoot(isolate);
|
||||
}
|
||||
|
||||
// 4. If module.[[TopLevelCapability]] is not undefined, then
|
||||
@@ -736,37 +740,27 @@ void SourceTextModule::AsyncModuleExecutionFulfilled(
|
||||
for (int i = 0; i < module->AsyncParentModuleCount(); i++) {
|
||||
Handle<SourceTextModule> m = module->GetAsyncParentModule(isolate, i);
|
||||
|
||||
// a. If module.[[DFSIndex]] is not equal to module.[[DFSAncestorIndex]],
|
||||
// then
|
||||
if (module->dfs_index() != module->dfs_ancestor_index()) {
|
||||
// i. Assert: m.[[DFSAncestorIndex]] is equal to
|
||||
// module.[[DFSAncestorIndex]].
|
||||
DCHECK_LE(m->dfs_ancestor_index(), module->dfs_ancestor_index());
|
||||
}
|
||||
// b. Decrement m.[[PendingAsyncDependencies]] by 1.
|
||||
// a. Decrement m.[[PendingAsyncDependencies]] by 1.
|
||||
m->DecrementPendingAsyncDependencies();
|
||||
|
||||
// c. If m.[[PendingAsyncDependencies]] is 0 and m.[[EvaluationError]] is
|
||||
// b. If m.[[PendingAsyncDependencies]] is 0 and m.[[EvaluationError]] is
|
||||
// undefined, then
|
||||
if (!m->HasPendingAsyncDependencies() && m->status() == kEvaluated) {
|
||||
// i. Assert: m.[[AsyncEvaluating]] is true.
|
||||
DCHECK(m->async_evaluating());
|
||||
|
||||
// ii. Let cycleRoot be ! GetAsyncCycleRoot(m).
|
||||
auto cycle_root = GetAsyncCycleRoot(isolate, m);
|
||||
|
||||
// iii. If cycleRoot.[[EvaluationError]] is not undefined,
|
||||
// ii. If m.[[CycleRoot]].[[EvaluationError]] is not undefined,
|
||||
// return undefined.
|
||||
if (cycle_root->status() == kErrored) {
|
||||
if (m->GetCycleRoot(isolate)->status() == kErrored) {
|
||||
return;
|
||||
}
|
||||
|
||||
// iv. If m.[[Async]] is true, then
|
||||
// iii. If m.[[Async]] is true, then
|
||||
if (m->async()) {
|
||||
// 1. Perform ! ExecuteAsyncModule(m).
|
||||
ExecuteAsyncModule(isolate, m);
|
||||
} else {
|
||||
// v. Otherwise,
|
||||
// iv. Otherwise,
|
||||
// 1. Let result be m.ExecuteModule().
|
||||
// 2. If result is a normal completion,
|
||||
Handle<Object> unused_result;
|
||||
@@ -1046,8 +1040,8 @@ MaybeHandle<Object> SourceTextModule::InnerModuleEvaluation(
|
||||
required_module->dfs_ancestor_index()));
|
||||
} else {
|
||||
// iv. Otherwise,
|
||||
// 1. Set requiredModule to GetAsyncCycleRoot(requiredModule).
|
||||
required_module = GetAsyncCycleRoot(isolate, required_module);
|
||||
// 1. Set requiredModule to requiredModule.[[CycleRoot]].
|
||||
required_module = required_module->GetCycleRoot(isolate);
|
||||
|
||||
// 2. Assert: requiredModule.[[Status]] is "evaluated".
|
||||
CHECK_GE(required_module->status(), kEvaluated);
|
||||
@@ -1105,43 +1099,6 @@ MaybeHandle<Object> SourceTextModule::InnerModuleEvaluation(
|
||||
return result;
|
||||
}
|
||||
|
||||
Handle<SourceTextModule> SourceTextModule::GetAsyncCycleRoot(
|
||||
Isolate* isolate, Handle<SourceTextModule> module) {
|
||||
// 1. Assert: module.[[Status]] is "evaluated".
|
||||
CHECK_GE(module->status(), kEvaluated);
|
||||
|
||||
// 2. If module.[[AsyncParentModules]] is an empty List, return module.
|
||||
if (module->AsyncParentModuleCount() == 0) {
|
||||
return module;
|
||||
}
|
||||
|
||||
// 3. Repeat, while module.[[DFSIndex]] is greater than
|
||||
// module.[[DFSAncestorIndex]],
|
||||
while (module->dfs_index() > module->dfs_ancestor_index()) {
|
||||
// a. Assert: module.[[AsyncParentModules]] is a non-empty List.
|
||||
DCHECK_GT(module->AsyncParentModuleCount(), 0);
|
||||
|
||||
// b. Let nextCycleModule be the first element of
|
||||
// module.[[AsyncParentModules]].
|
||||
Handle<SourceTextModule> next_cycle_module =
|
||||
module->GetAsyncParentModule(isolate, 0);
|
||||
|
||||
// c. Assert: nextCycleModule.[[DFSAncestorIndex]] is less than or equal
|
||||
// to module.[[DFSAncestorIndex]].
|
||||
DCHECK_LE(next_cycle_module->dfs_ancestor_index(),
|
||||
module->dfs_ancestor_index());
|
||||
|
||||
// d. Set module to nextCycleModule
|
||||
module = next_cycle_module;
|
||||
}
|
||||
|
||||
// 4. Assert: module.[[DFSIndex]] is equal to module.[[DFSAncestorIndex]].
|
||||
DCHECK_EQ(module->dfs_index(), module->dfs_ancestor_index());
|
||||
|
||||
// 5. Return module.
|
||||
return module;
|
||||
}
|
||||
|
||||
void SourceTextModule::Reset(Isolate* isolate,
|
||||
Handle<SourceTextModule> module) {
|
||||
Factory* factory = isolate->factory();
|
||||
|
||||
+3
-4
@@ -79,6 +79,9 @@ class SourceTextModule
|
||||
Handle<SourceTextModule> module,
|
||||
Handle<SourceTextModule> parent);
|
||||
|
||||
// Get the non-hole cycle root. Only valid when status >= kEvaluated.
|
||||
inline Handle<SourceTextModule> GetCycleRoot(Isolate* isolate) const;
|
||||
|
||||
// Returns a SourceTextModule, the
|
||||
// ith parent in depth first traversal order of a given async child.
|
||||
inline Handle<SourceTextModule> GetAsyncParentModule(Isolate* isolate,
|
||||
@@ -163,10 +166,6 @@ class SourceTextModule
|
||||
Isolate* isolate, Handle<SourceTextModule> module,
|
||||
ZoneForwardList<Handle<SourceTextModule>>* stack, Status new_status);
|
||||
|
||||
// Implementation of spec GetAsyncCycleRoot.
|
||||
static V8_WARN_UNUSED_RESULT Handle<SourceTextModule> GetAsyncCycleRoot(
|
||||
Isolate* isolate, Handle<SourceTextModule> module);
|
||||
|
||||
// Implementation of spec ExecuteModule is broken up into
|
||||
// InnerExecuteAsyncModule for asynchronous modules and ExecuteModule
|
||||
// for synchronous modules.
|
||||
|
||||
+5
@@ -34,6 +34,11 @@ extern class SourceTextModule extends Module {
|
||||
// a JSObject afterwards.
|
||||
import_meta: TheHole|JSObject;
|
||||
|
||||
// The first visited module of a cycle. For modules not in a cycle, this is
|
||||
// the module itself. It's the hole before the module state transitions to
|
||||
// kEvaluated.
|
||||
cycle_root: SourceTextModule|TheHole;
|
||||
|
||||
async_parent_modules: ArrayList;
|
||||
top_level_capability: JSPromise|Undefined;
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --harmony-top-level-await
|
||||
|
||||
import "modules-skip-async-cycle-start.mjs"
|
||||
|
||||
assertEquals(globalThis.test_order, [
|
||||
'2', 'async before', 'async after', '1',
|
||||
'3', 'start',
|
||||
]);
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --harmony-top-level-await
|
||||
|
||||
import "modules-skip-async-cycle-2.mjs";
|
||||
import "modules-skip-async-cycle-leaf.mjs";
|
||||
|
||||
if (globalThis.test_order === undefined) {
|
||||
globalThis.test_order = [];
|
||||
}
|
||||
globalThis.test_order.push('1');
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --harmony-top-level-await
|
||||
|
||||
import "modules-skip-async-cycle-1.mjs";
|
||||
|
||||
if (globalThis.test_order === undefined) {
|
||||
globalThis.test_order = [];
|
||||
}
|
||||
globalThis.test_order.push('2');
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --harmony-top-level-await
|
||||
|
||||
import "modules-skip-async-cycle-2.mjs";
|
||||
|
||||
if (globalThis.test_order === undefined) {
|
||||
globalThis.test_order = [];
|
||||
}
|
||||
globalThis.test_order.push('3');
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --harmony-top-level-await
|
||||
|
||||
if (globalThis.test_order === undefined) {
|
||||
globalThis.test_order = [];
|
||||
}
|
||||
|
||||
globalThis.test_order.push('async before');
|
||||
await 0;
|
||||
globalThis.test_order.push('async after');
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2021 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --harmony-top-level-await
|
||||
|
||||
import "modules-skip-async-cycle-1.mjs";
|
||||
import "modules-skip-async-cycle-3.mjs";
|
||||
|
||||
if (globalThis.test_order === undefined) {
|
||||
globalThis.test_order = [];
|
||||
}
|
||||
globalThis.test_order.push('start');
|
||||
Reference in new issue
Block a user