Skip to content

Commit 5a422d2

Browse files
committed
src: snapshot loaders
1 parent 77b0efe commit 5a422d2

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/node_main_instance.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "node_external_reference.h"
77
#include "node_internals.h"
88
#include "node_main_instance.h"
9+
#include "node_native_module_env.h"
910
#include "node_options-inl.h"
1011
#include "node_process.h"
1112
#include "node_v8_platform-inl.h"
@@ -56,6 +57,10 @@ const std::vector<intptr_t>& NodeMainInstance::CollectExternalReferences() {
5657
registry_.reset(new ExternalReferenceRegistry());
5758

5859
registry_->Register(node::RawDebug);
60+
registry_->Register(node::binding::GetLinkedBinding);
61+
registry_->Register(node::binding::GetInternalBinding);
62+
node::native_module::NativeModuleEnv::RegisterExternalReferences(
63+
registry_.get());
5964
// TODO(joyeecheung): collect more external references here.
6065
return registry_->external_references();
6166
}
@@ -286,10 +291,17 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
286291
env->InitializeInspector({});
287292
#endif
288293

289-
if (env->RunBootstrapping().IsEmpty()) {
294+
if (!deserialize_mode_ && env->RunBootstrapping().IsEmpty()) {
290295
return nullptr;
291296
}
292297

298+
if (deserialize_mode_ && env->BootstrapNode().IsEmpty()) {
299+
return nullptr;
300+
}
301+
302+
CHECK(env->req_wrap_queue()->IsEmpty());
303+
CHECK(env->handle_wrap_queue()->IsEmpty());
304+
env->set_has_run_bootstrapping_code(true);
293305
return env;
294306
}
295307

src/node_native_module_env.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "node_native_module_env.h"
22
#include "env-inl.h"
3+
#include "node_external_reference.h"
34

45
namespace node {
56
namespace native_module {
@@ -221,6 +222,17 @@ void NativeModuleEnv::Initialize(Local<Object> target,
221222
target->SetIntegrityLevel(context, IntegrityLevel::kFrozen).FromJust();
222223
}
223224

225+
void NativeModuleEnv::RegisterExternalReferences(
226+
ExternalReferenceRegistry* registry) {
227+
registry->Register(ConfigStringGetter);
228+
registry->Register(ModuleIdsGetter);
229+
registry->Register(ModuleIdsGetter);
230+
registry->Register(GetModuleCategories);
231+
registry->Register(GetCacheUsage);
232+
registry->Register(CompileFunction);
233+
registry->Register(HasCachedBuiltins);
234+
}
235+
224236
} // namespace native_module
225237
} // namespace node
226238

src/node_native_module_env.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
namespace node {
99
class Environment;
10+
class ExternalReferenceRegistry;
1011

1112
namespace native_module {
1213

1314
extern const bool has_code_cache;
1415

1516
class NativeModuleEnv {
1617
public:
18+
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
1719
static void Initialize(v8::Local<v8::Object> target,
1820
v8::Local<v8::Value> unused,
1921
v8::Local<v8::Context> context,

tools/snapshot/snapshot_builder.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ std::string SnapshotBuilder::Generate(
157157
env->PrintAllBaseObjects();
158158
printf("Environment = %p\n", env);
159159
}
160+
env->BootstrapInternalLoaders().ToLocalChecked();
160161
env_info = env->Serialize(&creator);
161162
size_t index = creator.AddContext(
162163
context, {SerializeNodeContextInternalFields, env});
@@ -168,7 +169,7 @@ std::string SnapshotBuilder::Generate(
168169
// Must be out of HandleScope
169170
StartupData blob =
170171
creator.CreateBlob(SnapshotCreator::FunctionCodeHandling::kClear);
171-
CHECK(blob.CanBeRehashed());
172+
// CHECK(blob.CanBeRehashed());
172173
// Must be done while the snapshot creator isolate is entered i.e. the
173174
// creator is still alive.
174175
env->set_stopping(true);

0 commit comments

Comments
 (0)