diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 419fd767720e4b..212c6bf5f4498a 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -171,9 +171,13 @@ std::unique_ptr NodeMainInstance::CreateMainEnvironment( isolate_->GetHeapProfiler()->StartTrackingHeapObjects(true); } - Local context = NewContext(isolate_); + Local context; if (deserialize_mode_) { + context = + Context::FromSnapshot(isolate_, kNodeContextIndex).ToLocalChecked(); SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers); + } else { + context = NewContext(isolate_); } CHECK(!context.IsEmpty()); diff --git a/src/node_main_instance.h b/src/node_main_instance.h index 98c17cc8f011dd..531c919f052016 100644 --- a/src/node_main_instance.h +++ b/src/node_main_instance.h @@ -75,6 +75,8 @@ class NodeMainInstance { static const IndexArray* GetIsolateDataIndexes(); static v8::StartupData* GetEmbeddedSnapshotBlob(); + static const size_t kNodeContextIndex = 0; + private: NodeMainInstance(const NodeMainInstance&) = delete; NodeMainInstance& operator=(const NodeMainInstance&) = delete; diff --git a/tools/snapshot/snapshot_builder.cc b/tools/snapshot/snapshot_builder.cc index d1ec17e302ae97..835fca9f4609cb 100644 --- a/tools/snapshot/snapshot_builder.cc +++ b/tools/snapshot/snapshot_builder.cc @@ -104,6 +104,9 @@ std::string SnapshotBuilder::Generate( HandleScope scope(isolate); creator.SetDefaultContext(Context::New(isolate)); isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator); + + size_t index = creator.AddContext(NewContext(isolate)); + CHECK_EQ(index, NodeMainInstance::kNodeContextIndex); } // Must be out of HandleScope