Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-02 19:49:12 +0300
committerJoyee Cheung <joyeec9h3@gmail.com>2018-12-11 01:40:09 +0300
commit44a5fe145759a2fa43247da2f40a55df23572944 (patch)
tree74c346b396e14f5da4fbc85d4a48bd974b2a3432 /src/node_native_module.cc
parent9fb4fa8ded0504f63c89ed969640e5a2df8d0d59 (diff)
process: specialize building and storage of process.config
Instead of treating config.gypi as a JavaScript file, specialize the processing in js2c and make the serialized result a real JSON string (with 'true' and 'false' converted to boolean values) so we don't have to use a custom deserializer during bootstrap. In addition, store the JSON string separately in NativeModuleLoader, and keep it separate from the map of the builtin source code, so we don't have to put it onto `NativeModule._source` and delete it later, though we still preserve it in `process.binding('natives')`, which we don't use anymore. This patch also makes the map of builtin source code and the config.gypi string available through side-effect-free getters in C++. PR-URL: https://github.com/nodejs/node/pull/24816 Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'src/node_native_module.cc')
-rw-r--r--src/node_native_module.cc48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/node_native_module.cc b/src/node_native_module.cc
index 6e5f08e3545..85f8d83d63a 100644
--- a/src/node_native_module.cc
+++ b/src/node_native_module.cc
@@ -9,6 +9,7 @@ using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferCreationMode;
using v8::Context;
+using v8::DEFAULT;
using v8::EscapableHandleScope;
using v8::Function;
using v8::FunctionCallbackInfo;
@@ -19,11 +20,15 @@ using v8::Isolate;
using v8::Local;
using v8::Maybe;
using v8::MaybeLocal;
+using v8::Name;
+using v8::None;
using v8::Object;
+using v8::PropertyCallbackInfo;
using v8::Script;
using v8::ScriptCompiler;
using v8::ScriptOrigin;
using v8::Set;
+using v8::SideEffectType;
using v8::String;
using v8::Uint8Array;
using v8::Value;
@@ -70,10 +75,16 @@ void NativeModuleLoader::GetCacheUsage(
args.GetReturnValue().Set(result);
}
-void NativeModuleLoader::GetSourceObject(
- const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args);
- args.GetReturnValue().Set(per_process_loader.GetSourceObject(env->context()));
+void NativeModuleLoader::SourceObjectGetter(
+ Local<Name> property, const PropertyCallbackInfo<Value>& info) {
+ Local<Context> context = info.GetIsolate()->GetCurrentContext();
+ info.GetReturnValue().Set(per_process_loader.GetSourceObject(context));
+}
+
+void NativeModuleLoader::ConfigStringGetter(
+ Local<Name> property, const PropertyCallbackInfo<Value>& info) {
+ info.GetReturnValue().Set(
+ per_process_loader.GetConfigString(info.GetIsolate()));
}
Local<Object> NativeModuleLoader::GetSourceObject(
@@ -81,6 +92,10 @@ Local<Object> NativeModuleLoader::GetSourceObject(
return MapToObject(context, source_);
}
+Local<String> NativeModuleLoader::GetConfigString(Isolate* isolate) const {
+ return config_.ToStringChecked(isolate);
+}
+
Local<String> NativeModuleLoader::GetSource(Isolate* isolate,
const char* id) const {
const auto it = source_.find(id);
@@ -88,7 +103,7 @@ Local<String> NativeModuleLoader::GetSource(Isolate* isolate,
return it->second.ToStringChecked(isolate);
}
-NativeModuleLoader::NativeModuleLoader() {
+NativeModuleLoader::NativeModuleLoader() : config_(GetConfig()) {
LoadJavaScriptSource();
LoadJavaScriptHash();
LoadCodeCache();
@@ -321,8 +336,27 @@ void NativeModuleLoader::Initialize(Local<Object> target,
void* priv) {
Environment* env = Environment::GetCurrent(context);
- env->SetMethod(
- target, "getSource", NativeModuleLoader::GetSourceObject);
+ CHECK(target
+ ->SetAccessor(env->context(),
+ env->config_string(),
+ ConfigStringGetter,
+ nullptr,
+ MaybeLocal<Value>(),
+ DEFAULT,
+ None,
+ SideEffectType::kHasNoSideEffect)
+ .FromJust());
+ CHECK(target
+ ->SetAccessor(env->context(),
+ env->source_string(),
+ SourceObjectGetter,
+ nullptr,
+ MaybeLocal<Value>(),
+ DEFAULT,
+ None,
+ SideEffectType::kHasNoSideEffect)
+ .FromJust());
+
env->SetMethod(
target, "getCacheUsage", NativeModuleLoader::GetCacheUsage);
env->SetMethod(