Skip to content

Commit 6239ec1

Browse files
GeorgNeisCommit Bot
authored andcommitted
[modules] Fix bug in instantiation failure handling
It's not sufficient to reset only the modules on the current DFS path. Bug: chromium:1050164 Change-Id: I00e5e12144ad70ac6371eea5e11590b72feaeecc Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2049853 Auto-Submit: Georg Neis <[email protected]> Reviewed-by: Adam Klein <[email protected]> Commit-Queue: Adam Klein <[email protected]> Cr-Commit-Position: refs/heads/master@{#66229}
1 parent 447e2a7 commit 6239ec1

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

src/objects/module.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ void Module::RecordError(Isolate* isolate, Handle<Object> error) {
7676
}
7777

7878
void Module::ResetGraph(Isolate* isolate, Handle<Module> module) {
79-
DCHECK_NE(module->status(), kInstantiating);
8079
DCHECK_NE(module->status(), kEvaluating);
81-
if (module->status() != kPreInstantiating) return;
80+
if (module->status() != kPreInstantiating &&
81+
module->status() != kInstantiating) {
82+
return;
83+
}
8284

8385
Handle<FixedArray> requested_modules =
8486
module->IsSourceTextModule()
@@ -180,15 +182,14 @@ bool Module::Instantiate(Isolate* isolate, Handle<Module> module,
180182

181183
if (!PrepareInstantiate(isolate, module, context, callback)) {
182184
ResetGraph(isolate, module);
185+
DCHECK_EQ(module->status(), kUninstantiated);
183186
return false;
184187
}
185188
Zone zone(isolate->allocator(), ZONE_NAME);
186189
ZoneForwardList<Handle<SourceTextModule>> stack(&zone);
187190
unsigned dfs_index = 0;
188191
if (!FinishInstantiate(isolate, module, &stack, &dfs_index, &zone)) {
189-
for (auto& descendant : stack) {
190-
Reset(isolate, descendant);
191-
}
192+
ResetGraph(isolate, module);
192193
DCHECK_EQ(module->status(), kUninstantiated);
193194
return false;
194195
}

test/mjsunit/modules-reset.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax
6+
7+
import("./modules-skip-reset1.js").then(() => %AbortJS("must throw"));
8+
import("./modules-skip-reset3.js").then(() => %AbortJS("must throw"));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import {a} from "./modules-skip-reset2.js";
6+
import {b} from "./modules-skip-reset3.js";
7+
export let c = 42;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
export {a} from "./modules-skip-reset2.js";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright 2020 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import {c} from "./modules-skip-reset1.js";
6+
export let b = 23;

0 commit comments

Comments
 (0)