This repository has been archived by the owner on Dec 14, 2024. It is now read-only.
forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnode_modules.h
89 lines (72 loc) · 2.68 KB
/
node_modules.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef SRC_NODE_MODULES_H_
#define SRC_NODE_MODULES_H_
#include "v8-function-callback.h"
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node.h"
#include "node_snapshotable.h"
#include "simdjson.h"
#include "util.h"
#include "v8-fast-api-calls.h"
#include "v8.h"
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
namespace node {
class ExternalReferenceRegistry;
namespace modules {
class BindingData : public SnapshotableObject {
public:
using InternalFieldInfo = InternalFieldInfoBase;
struct PackageConfig {
std::string file_path;
std::optional<std::string> name;
std::optional<std::string> main;
std::string type = "none";
std::optional<std::string> exports;
std::optional<std::string> imports;
std::string raw_json;
v8::Local<v8::Array> Serialize(Realm* realm) const;
};
struct ErrorContext {
std::optional<std::string> base;
std::string specifier;
bool is_esm;
};
BindingData(Realm* realm,
v8::Local<v8::Object> obj,
InternalFieldInfo* info = nullptr);
SERIALIZABLE_OBJECT_METHODS()
SET_BINDING_ID(modules_binding_data)
void MemoryInfo(MemoryTracker* tracker) const override;
SET_SELF_SIZE(BindingData)
SET_MEMORY_INFO_NAME(BindingData)
static void ReadPackageJSON(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetNearestParentPackageJSON(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetNearestParentPackageJSONType(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetPackageScopeConfig(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void CreatePerIsolateProperties(IsolateData* isolate_data,
v8::Local<v8::ObjectTemplate> ctor);
static void CreatePerContextProperties(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
private:
std::unordered_map<std::string, PackageConfig> package_configs_;
simdjson::ondemand::parser json_parser;
// returns null on error
static const PackageConfig* GetPackageJSON(
Realm* realm,
std::string_view path,
ErrorContext* error_context = nullptr);
static const PackageConfig* TraverseParent(Realm* realm,
std::string_view check_path);
};
} // namespace modules
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_NODE_MODULES_H_