Skip to content

Commit 0b8ae5f

Browse files
committed
src: snapshot loaders
This runs `lib/internal/bootstrap/loaders.js` before creating the builtin snapshot and deserialize the loaders from the snapshot in deserialization mode. PR-URL: #32984 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent 7ecb285 commit 0b8ae5f

6 files changed

+39
-3
lines changed

src/node_binding.cc

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "node_binding.h"
2-
#include "node_errors.h"
32
#include <atomic>
43
#include "env-inl.h"
4+
#include "node_errors.h"
5+
#include "node_external_reference.h"
56
#include "node_native_module_env.h"
67
#include "util.h"
78

@@ -676,5 +677,13 @@ void RegisterBuiltinModules() {
676677
#undef V
677678
}
678679

680+
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
681+
registry->Register(GetLinkedBinding);
682+
registry->Register(GetInternalBinding);
683+
}
684+
679685
} // namespace binding
680686
} // namespace node
687+
688+
NODE_MODULE_EXTERNAL_REFERENCE(binding,
689+
node::binding::RegisterExternalReferences)

src/node_external_reference.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class ExternalReferenceRegistry {
4646
std::vector<intptr_t> external_references_;
4747
};
4848

49-
#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) V(process_object)
49+
#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
50+
V(binding) \
51+
V(native_module) \
52+
V(process_object)
5053

5154
#define EXTERNAL_REFERENCE_BINDING_LIST(V) \
5255
EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)

src/node_main_instance.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,17 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
259259
env->InitializeInspector({});
260260
#endif
261261

262-
if (env->RunBootstrapping().IsEmpty()) {
262+
if (!deserialize_mode_ && env->RunBootstrapping().IsEmpty()) {
263263
return nullptr;
264264
}
265265

266+
if (deserialize_mode_ && env->BootstrapNode().IsEmpty()) {
267+
return nullptr;
268+
}
269+
270+
CHECK(env->req_wrap_queue()->IsEmpty());
271+
CHECK(env->handle_wrap_queue()->IsEmpty());
272+
env->set_has_run_bootstrapping_code(true);
266273
return env;
267274
}
268275

src/node_native_module_env.cc

+14
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 {
@@ -216,8 +217,21 @@ void NativeModuleEnv::Initialize(Local<Object> target,
216217
target->SetIntegrityLevel(context, IntegrityLevel::kFrozen).FromJust();
217218
}
218219

220+
void NativeModuleEnv::RegisterExternalReferences(
221+
ExternalReferenceRegistry* registry) {
222+
registry->Register(ConfigStringGetter);
223+
registry->Register(ModuleIdsGetter);
224+
registry->Register(GetModuleCategories);
225+
registry->Register(GetCacheUsage);
226+
registry->Register(CompileFunction);
227+
registry->Register(HasCachedBuiltins);
228+
}
229+
219230
} // namespace native_module
220231
} // namespace node
221232

222233
NODE_MODULE_CONTEXT_AWARE_INTERNAL(
223234
native_module, node::native_module::NativeModuleEnv::Initialize)
235+
NODE_MODULE_EXTERNAL_REFERENCE(
236+
native_module,
237+
node::native_module::NativeModuleEnv::RegisterExternalReferences)

src/node_native_module_env.h

+2
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

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ std::string SnapshotBuilder::Generate(
130130
nullptr,
131131
node::EnvironmentFlags::kDefaultFlags,
132132
{});
133+
env->BootstrapInternalLoaders().ToLocalChecked();
133134
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
134135
env->PrintAllBaseObjects();
135136
printf("Environment = %p\n", env);

0 commit comments

Comments
 (0)