diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-03 00:49:12 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-11 06:40:09 +0800 |
commit | 44a5fe145759a2fa43247da2f40a55df23572944 (patch) | |
tree | 74c346b396e14f5da4fbc85d4a48bd974b2a3432 /src/node_native_module.h | |
parent | 9fb4fa8ded0504f63c89ed969640e5a2df8d0d59 (diff) | |
download | android-node-v8-44a5fe145759a2fa43247da2f40a55df23572944.tar.gz android-node-v8-44a5fe145759a2fa43247da2f40a55df23572944.tar.bz2 android-node-v8-44a5fe145759a2fa43247da2f40a55df23572944.zip |
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.h')
-rw-r--r-- | src/node_native_module.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/node_native_module.h b/src/node_native_module.h index fc0e33c735..02c769ef02 100644 --- a/src/node_native_module.h +++ b/src/node_native_module.h @@ -40,6 +40,9 @@ class NativeModuleLoader { v8::Local<v8::Context> context, void* priv); v8::Local<v8::Object> GetSourceObject(v8::Local<v8::Context> context) const; + // Returns config.gypi as a JSON string + v8::Local<v8::String> GetConfigString(v8::Isolate* isolate) const; + v8::Local<v8::String> GetSource(v8::Isolate* isolate, const char* id) const; // Run a script with JS source bundled inside the binary as if it's wrapped @@ -56,9 +59,15 @@ class NativeModuleLoader { private: static void GetCacheUsage(const v8::FunctionCallbackInfo<v8::Value>& args); - // For legacy process.binding('natives') which is mutable, and for - // internalBinding('native_module').source for internal use - static void GetSourceObject(const v8::FunctionCallbackInfo<v8::Value>& args); + // Passing map of builtin module source code into JS land as + // internalBinding('native_module').source + static void SourceObjectGetter( + v8::Local<v8::Name> property, + const v8::PropertyCallbackInfo<v8::Value>& info); + // Passing config.gypi into JS land as internalBinding('native_module').config + static void ConfigStringGetter( + v8::Local<v8::Name> property, + const v8::PropertyCallbackInfo<v8::Value>& info); // Compile code cache for a specific native module static void CompileCodeCache(const v8::FunctionCallbackInfo<v8::Value>& args); // Compile a specific native module as a function @@ -67,6 +76,7 @@ class NativeModuleLoader { // Generated by tools/js2c.py as node_javascript.cc void LoadJavaScriptSource(); // Loads data into source_ void LoadJavaScriptHash(); // Loads data into source_hash_ + UnionBytes GetConfig(); // Return data for config.gypi // Generated by tools/generate_code_cache.js as node_code_cache.cc when // the build is configured with --code-cache-path=.... They are noops @@ -94,6 +104,8 @@ class NativeModuleLoader { bool has_code_cache_ = false; NativeModuleRecordMap source_; NativeModuleRecordMap code_cache_; + UnionBytes config_; + NativeModuleHashMap source_hash_; NativeModuleHashMap code_cache_hash_; }; |