Commit 8ee40cfc authored by Dan Clark's avatar Dan Clark Committed by V8 LUCI CQ

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/+/3388130Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78636}
parent 39fb0872
......@@ -1365,9 +1365,13 @@ 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,
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());
......
// 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.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment