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:
Dan Clark 2022-01-13 14:21:41 -08:00 committed by V8 LUCI CQ
parent 39fb087292
commit 8ee40cfc1f
2 changed files with 16 additions and 4 deletions

View File

@ -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;

View 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.