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: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
Joyee Cheung committed 2020-07-18 11:23:15 +08:00
1 parent 7ecb285842
commit 0b8ae5f2cd
6 files changed
+39 -3

No files matched your search

+10 -1
View File
@@ -1,7 +1,8 @@
#include "node_binding.h"
#include "node_errors.h"
#include <atomic>
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_native_module_env.h"
#include "util.h"
@@ -676,5 +677,13 @@ void RegisterBuiltinModules() {
#undef V
}
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(GetLinkedBinding);
registry->Register(GetInternalBinding);
}
} // namespace binding
} // namespace node
NODE_MODULE_EXTERNAL_REFERENCE(binding,
node::binding::RegisterExternalReferences)
+4 -1
View File
@@ -46,7 +46,10 @@ class ExternalReferenceRegistry {
std::vector<intptr_t> external_references_;
};
#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) V(process_object)
#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
V(binding) \
V(native_module) \
V(process_object)
#define EXTERNAL_REFERENCE_BINDING_LIST(V) \
EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)
+8 -1
View File
@@ -259,10 +259,17 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
env->InitializeInspector({});
#endif
if (env->RunBootstrapping().IsEmpty()) {
if (!deserialize_mode_ && env->RunBootstrapping().IsEmpty()) {
return nullptr;
}
if (deserialize_mode_ && env->BootstrapNode().IsEmpty()) {
return nullptr;
}
CHECK(env->req_wrap_queue()->IsEmpty());
CHECK(env->handle_wrap_queue()->IsEmpty());
env->set_has_run_bootstrapping_code(true);
return env;
}
+14
View File
@@ -1,5 +1,6 @@
#include "node_native_module_env.h"
#include "env-inl.h"
#include "node_external_reference.h"
namespace node {
namespace native_module {
@@ -216,8 +217,21 @@ void NativeModuleEnv::Initialize(Local<Object> target,
target->SetIntegrityLevel(context, IntegrityLevel::kFrozen).FromJust();
}
void NativeModuleEnv::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(ConfigStringGetter);
registry->Register(ModuleIdsGetter);
registry->Register(GetModuleCategories);
registry->Register(GetCacheUsage);
registry->Register(CompileFunction);
registry->Register(HasCachedBuiltins);
}
} // namespace native_module
} // namespace node
NODE_MODULE_CONTEXT_AWARE_INTERNAL(
native_module, node::native_module::NativeModuleEnv::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(
native_module,
node::native_module::NativeModuleEnv::RegisterExternalReferences)
+2
View File
@@ -7,6 +7,7 @@
namespace node {
class Environment;
class ExternalReferenceRegistry;
namespace native_module {
@@ -14,6 +15,7 @@ extern const bool has_code_cache;
class NativeModuleEnv {
public:
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
static void Initialize(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
+1
View File
@@ -130,6 +130,7 @@ std::string SnapshotBuilder::Generate(
nullptr,
node::EnvironmentFlags::kDefaultFlags,
{});
env->BootstrapInternalLoaders().ToLocalChecked();
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
env->PrintAllBaseObjects();
printf("Environment = %p\n", env);