1 #ifndef SRC_NODE_NATIVE_MODULE_ENV_H_ 2 #define SRC_NODE_NATIVE_MODULE_ENV_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "node_native_module.h" 7 8 namespace node { 9 class Environment; 10 11 namespace native_module { 12 13 extern const bool has_code_cache; 14 15 class NativeModuleEnv { 16 public: 17 static void Initialize(v8::Local<v8::Object> target, 18 v8::Local<v8::Value> unused, 19 v8::Local<v8::Context> context, 20 void* priv); 21 22 static v8::MaybeLocal<v8::Function> LookupAndCompile( 23 v8::Local<v8::Context> context, 24 const char* id, 25 std::vector<v8::Local<v8::String>>* parameters, 26 Environment* optional_env); 27 28 static v8::Local<v8::Object> GetSourceObject(v8::Local<v8::Context> context); 29 // Returns config.gypi as a JSON string 30 static v8::Local<v8::String> GetConfigString(v8::Isolate* isolate); 31 static bool Exists(const char* id); 32 static bool Add(const char* id, const UnionBytes& source); 33 34 // Loads data into NativeModuleLoader::.instance.code_cache_ 35 // Generated by mkcodecache as node_code_cache.cc when 36 // the build is configured with --code-cache-path=.... They are noops 37 // in node_code_cache_stub.cc 38 static void InitializeCodeCache(); 39 40 private: 41 static void RecordResult(const char* id, 42 NativeModuleLoader::Result result, 43 Environment* env); 44 static void GetModuleCategories( 45 v8::Local<v8::Name> property, 46 const v8::PropertyCallbackInfo<v8::Value>& info); 47 static void GetCacheUsage(const v8::FunctionCallbackInfo<v8::Value>& args); 48 // Passing ids of builtin module source code into JS land as 49 // internalBinding('native_module').moduleIds 50 static void ModuleIdsGetter(v8::Local<v8::Name> property, 51 const v8::PropertyCallbackInfo<v8::Value>& info); 52 // Passing config.gypi into JS land as internalBinding('native_module').config 53 static void ConfigStringGetter( 54 v8::Local<v8::Name> property, 55 const v8::PropertyCallbackInfo<v8::Value>& info); 56 // Compile a specific native module as a function 57 static void CompileFunction(const v8::FunctionCallbackInfo<v8::Value>& args); 58 }; 59 60 } // namespace native_module 61 62 } // namespace node 63 64 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 65 66 #endif // SRC_NODE_NATIVE_MODULE_ENV_H_ 67