Skip to content

Commit 52d8832

Browse files
committed
src: snapshot loaders
1 parent cae01f6 commit 52d8832

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

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
}
@@ -282,10 +287,17 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
282287
env->InitializeInspector({});
283288
#endif
284289

285-
if (env->RunBootstrapping().IsEmpty()) {
290+
if (!deserialize_mode_ && env->RunBootstrapping().IsEmpty()) {
286291
return nullptr;
287292
}
288293

294+
if (deserialize_mode_ && env->BootstrapNode().IsEmpty()) {
295+
return nullptr;
296+
}
297+
298+
CHECK(env->req_wrap_queue()->IsEmpty());
299+
CHECK(env->handle_wrap_queue()->IsEmpty());
300+
env->set_has_run_bootstrapping_code(true);
289301
return env;
290302
}
291303

src/node_native_module_env.cc

Lines changed: 11 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 {
@@ -205,6 +206,16 @@ void NativeModuleEnv::Initialize(Local<Object> target,
205206
env->SetMethod(target, "compileFunction", NativeModuleEnv::CompileFunction);
206207
env->SetMethod(target, "hasCachedBuiltins", HasCachedBuiltins);
207208
}
209+
void NativeModuleEnv::RegisterExternalReferences(
210+
ExternalReferenceRegistry* registry) {
211+
registry->Register(ConfigStringGetter);
212+
registry->Register(ModuleIdsGetter);
213+
registry->Register(ModuleIdsGetter);
214+
registry->Register(GetModuleCategories);
215+
registry->Register(GetCacheUsage);
216+
registry->Register(CompileFunction);
217+
registry->Register(HasCachedBuiltins);
218+
}
208219
} // namespace native_module
209220
} // namespace node
210221

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
@@ -210,6 +210,7 @@ std::string SnapshotBuilder::Generate(
210210
env->PrintAllBaseObjects();
211211
printf("Environment = %p\n", env);
212212
}
213+
env->BootstrapInternalLoaders().ToLocalChecked();
213214
env_info = env->Serialize(&creator);
214215
size_t index = creator.AddContext(
215216
context, {SerializeNodeContextInternalFields, env});
@@ -221,7 +222,7 @@ std::string SnapshotBuilder::Generate(
221222
// Must be out of HandleScope
222223
StartupData blob =
223224
creator.CreateBlob(SnapshotCreator::FunctionCodeHandling::kClear);
224-
CHECK(blob.CanBeRehashed());
225+
// CHECK(blob.CanBeRehashed());
225226
// Must be done while the snapshot creator isolate is entered i.e. the
226227
// creator is still alive.
227228
env->set_stopping(true);

0 commit comments

Comments
 (0)