diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-10 05:08:48 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-13 17:24:51 +0800 |
commit | dfd7e994258a36f3941c74295a8c037cb4850418 (patch) | |
tree | 03eaa022a99159912c97773a1b41952f3ee404b1 /src/node_native_module_env.h | |
parent | 9b6b567bc4dd8f40bad12528eebf12dac8a8027f (diff) | |
download | android-node-v8-dfd7e994258a36f3941c74295a8c037cb4850418.tar.gz android-node-v8-dfd7e994258a36f3941c74295a8c037cb4850418.tar.bz2 android-node-v8-dfd7e994258a36f3941c74295a8c037cb4850418.zip |
src: make a Environment-independent proxy class for NativeModuleLoader
This patch splits `NativeModuleLoader` into two parts - a singleton
that only relies on v8 and `node::Mutex` and a proxy class for
the singleton (`NativeModuleEnv`) that provides limited access to
the singleton as well as C++ bindings for the Node.js binary.
`NativeModuleLoader` is then no longer aware of `Environment`.
PR-URL: https://github.com/nodejs/node/pull/27160
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'src/node_native_module_env.h')
-rw-r--r-- | src/node_native_module_env.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/node_native_module_env.h b/src/node_native_module_env.h new file mode 100644 index 0000000000..2b1fabf89b --- /dev/null +++ b/src/node_native_module_env.h @@ -0,0 +1,64 @@ +#ifndef SRC_NODE_NATIVE_MODULE_ENV_H_ +#define SRC_NODE_NATIVE_MODULE_ENV_H_ + +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#include "node_native_module.h" + +namespace node { +class Environment; + +namespace native_module { + +class NativeModuleEnv { + public: + static void Initialize(v8::Local<v8::Object> target, + v8::Local<v8::Value> unused, + v8::Local<v8::Context> context, + void* priv); + + static v8::MaybeLocal<v8::Function> LookupAndCompile( + v8::Local<v8::Context> context, + const char* id, + std::vector<v8::Local<v8::String>>* parameters, + Environment* optional_env); + + static v8::Local<v8::Object> GetSourceObject(v8::Local<v8::Context> context); + // Returns config.gypi as a JSON string + static v8::Local<v8::String> GetConfigString(v8::Isolate* isolate); + static bool Exists(const char* id); + + // Loads data into NativeModuleLoader::.instance.code_cache_ + // Generated by mkcodecache as node_code_cache.cc when + // the build is configured with --code-cache-path=.... They are noops + // in node_code_cache_stub.cc + static void InitializeCodeCache(); + + private: + static void RecordResult(const char* id, + NativeModuleLoader::Result result, + Environment* env); + static void GetModuleCategories( + v8::Local<v8::Name> property, + const v8::PropertyCallbackInfo<v8::Value>& info); + static void GetCacheUsage(const v8::FunctionCallbackInfo<v8::Value>& args); + // Passing ids of builtin module source code into JS land as + // internalBinding('native_module').moduleIds + static void ModuleIdsGetter(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 a specific native module as a function + static void CompileFunction(const v8::FunctionCallbackInfo<v8::Value>& args); + static void GetCodeCache(const v8::FunctionCallbackInfo<v8::Value>& args); +}; + +} // namespace native_module + +} // namespace node + +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#endif // SRC_NODE_NATIVE_MODULE_ENV_H_ |