Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: include bootstrapped Environment in builtin snapshot #32984

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: snapshot node
This runs `lib/internal/bootstrap/node.js` before creating
the builtin snapshot and deserialize the loaders from the
snapshot in deserialization mode.
  • Loading branch information
joyeecheung committed Jul 14, 2020
commit 720abb860146adcc2f061e9996bcc688a63b3840
22 changes: 22 additions & 0 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "async_wrap-inl.h"
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "tracing/traced_value.h"
#include "util-inl.h"

Expand Down Expand Up @@ -695,6 +696,25 @@ void AsyncWrap::Initialize(Local<Object> target,
PromiseWrap::Initialize(env);
}

void AsyncWrap::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(SetupHooks);
registry->Register(SetCallbackTrampoline);
registry->Register(PushAsyncContext);
registry->Register(PopAsyncContext);
registry->Register(ExecutionAsyncResource);
registry->Register(ClearAsyncIdStack);
registry->Register(QueueDestroyAsyncId);
registry->Register(EnablePromiseHook);
registry->Register(DisablePromiseHook);
registry->Register(RegisterDestroyHook);
registry->Register(AsyncWrapObject::New);
registry->Register(AsyncWrap::GetAsyncId);
registry->Register(AsyncWrap::AsyncReset);
registry->Register(AsyncWrap::GetProviderType);
registry->Register(PromiseWrap::GetAsyncId);
registry->Register(PromiseWrap::GetTriggerAsyncId);
}

AsyncWrap::AsyncWrap(Environment* env,
Local<Object> object,
Expand Down Expand Up @@ -924,3 +944,5 @@ Local<Object> AsyncWrap::GetOwner(Environment* env, Local<Object> obj) {
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(async_wrap, node::AsyncWrap::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(async_wrap,
node::AsyncWrap::RegisterExternalReferences)
2 changes: 2 additions & 0 deletions src/async_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace node {

class Environment;
class DestroyParam;
class ExternalReferenceRegistry;

class AsyncWrap : public BaseObject {
public:
Expand Down Expand Up @@ -135,6 +136,7 @@ class AsyncWrap : public BaseObject {
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
Environment* env);

static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
static void Initialize(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
Expand Down
11 changes: 11 additions & 0 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "handle_wrap.h"
#include "async_wrap-inl.h"
#include "env-inl.h"
#include "node_external_reference.h"
#include "util-inl.h"

namespace node {
Expand Down Expand Up @@ -152,5 +153,15 @@ Local<FunctionTemplate> HandleWrap::GetConstructorTemplate(Environment* env) {
return tmpl;
}

void HandleWrap::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(HandleWrap::Close);
registry->Register(HandleWrap::HasRef);
registry->Register(HandleWrap::Ref);
registry->Register(HandleWrap::Unref);
}

} // namespace node

NODE_MODULE_EXTERNAL_REFERENCE(handle_wrap,
node::HandleWrap::RegisterExternalReferences)
2 changes: 2 additions & 0 deletions src/handle_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace node {

class Environment;
class ExternalReferenceRegistry;

// Rules:
//
Expand Down Expand Up @@ -77,6 +78,7 @@ class HandleWrap : public AsyncWrap {

static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
Environment* env);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

protected:
HandleWrap(Environment* env,
Expand Down
30 changes: 29 additions & 1 deletion src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#include "inspector_agent.h"
#include "inspector_io.h"
#include "memory_tracker-inl.h"
#include "node_external_reference.h"
#include "util-inl.h"
#include "v8.h"
#include "v8-inspector.h"
#include "v8.h"

#include <memory>

Expand Down Expand Up @@ -345,8 +346,35 @@ void Initialize(Local<Object> target, Local<Value> unused,
}

} // namespace

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(InspectorConsoleCall);
registry->Register(SetConsoleExtensionInstaller);
registry->Register(CallAndPauseOnStart);
registry->Register(Open);
registry->Register(Url);
registry->Register(WaitForDebugger);

registry->Register(AsyncTaskScheduledWrapper);
registry->Register(InvokeAsyncTaskFnWithId<&Agent::AsyncTaskCanceled>);
registry->Register(InvokeAsyncTaskFnWithId<&Agent::AsyncTaskStarted>);
registry->Register(InvokeAsyncTaskFnWithId<&Agent::AsyncTaskFinished>);

registry->Register(RegisterAsyncHookWrapper);
registry->Register(IsEnabled);

registry->Register(JSBindingsConnection<LocalConnection>::New);
registry->Register(JSBindingsConnection<LocalConnection>::Dispatch);
registry->Register(JSBindingsConnection<LocalConnection>::Disconnect);
registry->Register(JSBindingsConnection<MainThreadConnection>::New);
registry->Register(JSBindingsConnection<MainThreadConnection>::Dispatch);
registry->Register(JSBindingsConnection<MainThreadConnection>::Disconnect);
}

} // namespace inspector
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(inspector,
node::inspector::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(inspector,
node::inspector::RegisterExternalReferences)
39 changes: 39 additions & 0 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "allocated_buffer-inl.h"
#include "node.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_internals.h"

#include "env-inl.h"
Expand Down Expand Up @@ -1197,7 +1198,45 @@ void Initialize(Local<Object> target,
}

} // anonymous namespace

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(SetBufferPrototype);
registry->Register(CreateFromString);

registry->Register(ByteLengthUtf8);
registry->Register(Copy);
registry->Register(Compare);
registry->Register(CompareOffset);
registry->Register(Fill);
registry->Register(IndexOfBuffer);
registry->Register(IndexOfNumber);
registry->Register(IndexOfString);

registry->Register(Swap16);
registry->Register(Swap32);
registry->Register(Swap64);

registry->Register(EncodeInto);
registry->Register(EncodeUtf8String);

registry->Register(StringSlice<ASCII>);
registry->Register(StringSlice<BASE64>);
registry->Register(StringSlice<LATIN1>);
registry->Register(StringSlice<HEX>);
registry->Register(StringSlice<UCS2>);
registry->Register(StringSlice<UTF8>);

registry->Register(StringWrite<ASCII>);
registry->Register(StringWrite<BASE64>);
registry->Register(StringWrite<LATIN1>);
registry->Register(StringWrite<HEX>);
registry->Register(StringWrite<UCS2>);
registry->Register(StringWrite<UTF8>);
registry->Register(GetZeroFillToggle);
}

} // namespace Buffer
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(buffer, node::Buffer::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(buffer, node::Buffer::RegisterExternalReferences)
22 changes: 22 additions & 0 deletions src/node_credentials.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "env-inl.h"
#include "node_external_reference.h"
#include "node_internals.h"
#include "util-inl.h"

Expand Down Expand Up @@ -371,6 +372,25 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {

#endif // NODE_IMPLEMENTS_POSIX_CREDENTIALS

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(SafeGetenv);

#ifdef NODE_IMPLEMENTS_POSIX_CREDENTIALS
registry->Register(GetUid);
registry->Register(GetEUid);
registry->Register(GetGid);
registry->Register(GetEGid);
registry->Register(GetGroups);

registry->Register(InitGroups);
registry->Register(SetEGid);
registry->Register(SetEUid);
registry->Register(SetGid);
registry->Register(SetUid);
registry->Register(SetGroups);
#endif // NODE_IMPLEMENTS_POSIX_CREDENTIALS
}

static void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
Expand Down Expand Up @@ -403,3 +423,5 @@ static void Initialize(Local<Object> target,
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(credentials, node::credentials::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(credentials,
node::credentials::RegisterExternalReferences)
11 changes: 11 additions & 0 deletions src/node_env_var.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "debug_utils-inl.h"
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_process.h"

#include <time.h> // tzset(), _tzset()
Expand Down Expand Up @@ -384,4 +385,14 @@ MaybeLocal<Object> CreateEnvVarProxy(Local<Context> context, Isolate* isolate) {
PropertyHandlerFlags::kHasNoSideEffect));
return scope.EscapeMaybe(env_proxy_template->NewInstance(context));
}

void RegisterEnvVarExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(EnvGetter);
registry->Register(EnvSetter);
registry->Register(EnvQuery);
registry->Register(EnvDeleter);
registry->Register(EnvEnumerator);
}
} // namespace node

NODE_MODULE_EXTERNAL_REFERENCE(env_var, node::RegisterEnvVarExternalReferences)
12 changes: 11 additions & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#include "debug_utils-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_internals.h"
#include "node_report.h"
#include "node_process.h"
#include "node_report.h"
#include "node_v8_platform-inl.h"
#include "util-inl.h"

Expand Down Expand Up @@ -852,6 +853,14 @@ static void TriggerUncaughtException(const FunctionCallbackInfo<Value>& args) {
errors::TriggerUncaughtException(isolate, exception, message, from_promise);
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(SetPrepareStackTraceCallback);
registry->Register(EnableSourceMaps);
registry->Register(SetEnhanceStackForFatalException);
registry->Register(NoSideEffectsToString);
registry->Register(TriggerUncaughtException);
}

void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
Expand Down Expand Up @@ -1023,3 +1032,4 @@ void TriggerUncaughtException(Isolate* isolate, const v8::TryCatch& try_catch) {
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(errors, node::errors::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(errors, node::errors::RegisterExternalReferences)
33 changes: 31 additions & 2 deletions src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,41 @@ class ExternalReferenceRegistry {
};

#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
V(async_wrap) \
V(binding) \
V(buffer) \
V(credentials) \
V(env_var) \
V(errors) \
V(handle_wrap) \
V(messaging) \
V(native_module) \
V(process_object)
V(process_methods) \
V(process_object) \
V(task_queue) \
V(url) \
V(util) \
V(string_decoder) \
V(trace_events) \
V(timers) \
V(types)

#if NODE_HAVE_I18N_SUPPORT
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) V(icu)
#else
#define EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)
#endif // NODE_HAVE_I18N_SUPPORT

#if HAVE_INSPECTOR
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) V(inspector)
#else
#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V)
#endif // HAVE_INSPECTOR

#define EXTERNAL_REFERENCE_BINDING_LIST(V) \
EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)
EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \
EXTERNAL_REFERENCE_BINDING_LIST_I18N(V)

} // namespace node

Expand Down
13 changes: 13 additions & 0 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@


#include "node_i18n.h"
#include "node_external_reference.h"

#if defined(NODE_HAVE_I18N_SUPPORT)

Expand Down Expand Up @@ -824,9 +825,21 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "hasConverter", ConverterObject::Has);
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(ToUnicode);
registry->Register(ToASCII);
registry->Register(GetStringWidth);
registry->Register(ICUErrorName);
registry->Register(Transcode);
registry->Register(ConverterObject::Create);
registry->Register(ConverterObject::Decode);
registry->Register(ConverterObject::Has);
}

} // namespace i18n
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(icu, node::i18n::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(icu, node::i18n::RegisterExternalReferences)

#endif // NODE_HAVE_I18N_SUPPORT
1 change: 0 additions & 1 deletion src/node_i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <string>

namespace node {

namespace i18n {

bool InitializeICUDirectory(const std::string& path);
Expand Down
4 changes: 0 additions & 4 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
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);
Expand Down
Loading