Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/node_modules.h
1 #ifndef SRC_NODE_MODULES_H_ 2 #define SRC_NODE_MODULES_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "node.h" 7 #include "node_snapshotable.h" 8 #include "simdjson.h" 9 #include "util.h" 10 #include "v8-fast-api-calls.h" 11 #include "v8.h" 12 13 #include <filesystem> 14 #include <optional> 15 #include <string> 16 #include <string_view> 17 #include <unordered_map> 18 19 namespace node { 20 class ExternalReferenceRegistry; 21 22 namespace modules { 23 24 class BindingData : public SnapshotableObject { 25 public: 26 using InternalFieldInfo = InternalFieldInfoBase; 27 28 struct PackageConfig { 29 std::string file_path; 30 std::optional<std::string> name; 31 std::optional<std::string> main; 32 std::string type = "none"; 33 std::optional<std::string> exports; 34 std::optional<std::string> imports; 35 std::optional<std::string> scripts; 36 std::string raw_json; 37 38 v8::Local<v8::Array> Serialize(Realm* realm) const; 39 }; 40 41 struct ErrorContext { 42 std::optional<std::string> base; 43 std::string specifier; 44 bool is_esm; 45 }; 46 47 BindingData(Realm* realm, 48 v8::Local<v8::Object> obj, 49 InternalFieldInfo* info = nullptr); 50 SERIALIZABLE_OBJECT_METHODS() 51 SET_BINDING_ID(modules_binding_data) 52 53 void MemoryInfo(MemoryTracker* tracker) const override; 54 SET_SELF_SIZE(BindingData) 55 SET_MEMORY_INFO_NAME(BindingData) 56 57 static void ReadPackageJSON(const v8::FunctionCallbackInfo<v8::Value>& args); 58 static void GetNearestParentPackageJSONType( 59 const v8::FunctionCallbackInfo<v8::Value>& args); 60 template <bool return_only_type> 61 static void GetPackageScopeConfig( 62 const v8::FunctionCallbackInfo<v8::Value>& args); 63 static void GetPackageJSONScripts( 64 const v8::FunctionCallbackInfo<v8::Value>& args); 65 66 static void CreatePerIsolateProperties(IsolateData* isolate_data, 67 v8::Local<v8::ObjectTemplate> ctor); 68 static void CreatePerContextProperties(v8::Local<v8::Object> target, 69 v8::Local<v8::Value> unused, 70 v8::Local<v8::Context> context, 71 void* priv); 72 static void RegisterExternalReferences(ExternalReferenceRegistry* registry); 73 74 private: 75 std::unordered_map<std::string, PackageConfig> package_configs_; 76 simdjson::ondemand::parser json_parser; 77 // returns null on error 78 static const PackageConfig* GetPackageJSON( 79 Realm* realm, 80 std::string_view path, 81 ErrorContext* error_context = nullptr); 82 static const PackageConfig* TraverseParent( 83 Realm* realm, const std::filesystem::path& check_path); 84 }; 85 86 } // namespace modules 87 } // namespace node 88 89 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 90 91 #endif // SRC_NODE_MODULES_H_