Don't double-fetch a module specified on the d8 command line
Shell::FetchModuleTree assumes that the module at file_name wasn't already fetched. Shell::ExecuteModule is calling into FetchModuleTree without checking if the module is already in the module map, violating this assumption. This change fixes this by having Shell::ExecuteModule check for the existence of the module before calling into Shell::ExecuteModule, the same way that Shell::DoHostImportModuleDynamically does. Bug: v8:12530 Change-Id: Ia038cbd1715e85c9c92c4554fd486c657ef952e8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3388130 Reviewed-by: Marja Hölttä <marja@chromium.org> Commit-Queue: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/main@{#78636}
This commit is contained in:
parent
39fb087292
commit
8ee40cfc1f
12
src/d8/d8.cc
12
src/d8/d8.cc
@ -1365,11 +1365,15 @@ bool Shell::ExecuteModule(Isolate* isolate, const char* file_name) {
|
||||
// isolate->ReportPendingMessages().
|
||||
TryCatch try_catch(isolate);
|
||||
|
||||
ModuleEmbedderData* d = GetModuleDataFromContext(realm);
|
||||
Local<Module> root_module;
|
||||
|
||||
if (!FetchModuleTree(Local<Module>(), realm, absolute_path,
|
||||
ModuleType::kJavaScript)
|
||||
.ToLocal(&root_module)) {
|
||||
auto module_it = d->module_map.find(
|
||||
std::make_pair(absolute_path, ModuleType::kJavaScript));
|
||||
if (module_it != d->module_map.end()) {
|
||||
root_module = module_it->second.Get(isolate);
|
||||
} else if (!FetchModuleTree(Local<Module>(), realm, absolute_path,
|
||||
ModuleType::kJavaScript)
|
||||
.ToLocal(&root_module)) {
|
||||
CHECK(try_catch.HasCaught());
|
||||
ReportException(isolate, &try_catch);
|
||||
return false;
|
||||
|
8
test/mjsunit/d8/d8-multiple-module-exec.js
Normal file
8
test/mjsunit/d8/d8-multiple-module-exec.js
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright 2022 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: test/mjsunit/modules-skip-1.mjs test/mjsunit/modules-skip-1.mjs
|
||||
|
||||
// Just test that d8 doesn't crash when running the same module on the
|
||||
// command line twice.
|
Loading…
Reference in New Issue
Block a user