Commit b2831b5d authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[d8] Fix crash in shell when using dynamic import

This patch delays the DisposeModuleEmbedderData call for 
the interative shell case until we exit the RunShell function.

Bug: v8:5785
Change-Id: I01ff76000882cd1d6801fefc9ea3770c3f38c83b
Reviewed-on: https://chromium-review.googlesource.com/476024
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44630}
parent e2670e80
......@@ -849,8 +849,10 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) {
PerIsolateData::RealmScope::~RealmScope() {
// Drop realms to avoid keeping them alive.
for (int i = 0; i < data_->realm_count_; ++i) {
// Drop realms to avoid keeping them alive. We don't dispose the
// module embedder data for the first realm here, but instead do
// it in RunShell or in RunMain, if not running in interactive mode
for (int i = 1; i < data_->realm_count_; ++i) {
Global<Context>& realm = data_->realms_[i];
if (realm.IsEmpty()) continue;
DisposeModuleEmbedderData(realm.Get(data_->isolate_));
......@@ -2015,6 +2017,9 @@ void Shell::RunShell(Isolate* isolate) {
ExecuteString(isolate, input, name, true, true);
}
printf("\n");
// We need to explicitly clean up the module embedder data for
// the interative shell context.
DisposeModuleEmbedderData(context);
}
class InspectorFrontend final : public v8_inspector::V8Inspector::Channel {
......@@ -2619,7 +2624,8 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[], bool last_run) {
}
HandleScope scope(isolate);
Local<Context> context = CreateEvaluationContext(isolate);
if (last_run && options.use_interactive_shell()) {
bool use_existing_context = last_run && options.use_interactive_shell();
if (use_existing_context) {
// Keep using the same context in the interactive shell.
evaluation_context_.Reset(isolate, context);
}
......@@ -2629,7 +2635,9 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[], bool last_run) {
PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
options.isolate_sources[0].Execute(isolate);
}
DisposeModuleEmbedderData(context);
if (!use_existing_context) {
DisposeModuleEmbedderData(context);
}
WriteLcovData(isolate, options.lcov_file);
}
CollectGarbage(isolate);
......
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