Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
node/src/module_wrap.h at doc-embedding-shared-loop · codebytere/node · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
codebytere
node
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
doc-embedding-shared-loop
Breadcrumbs
node
/
src
/
module_wrap.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
231 lines (194 loc) · 8.12 KB
doc-embedding-shared-loop
Breadcrumbs
node
/
src
/
module_wrap.h
Copy path
Top
File metadata and controls
Code
Blame
231 lines (194 loc) · 8.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#
ifndef
SRC_MODULE_WRAP_H_
#
define
SRC_MODULE_WRAP_H_
#
if
defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#
include
<
optional
>
#
include
<
string
>
#
include
<
unordered_map
>
#
include
<
vector
>
#
include
"
base_object.h
"
#
include
"
v8-script.h
"
namespace
node
{
class
IsolateData
;
class
Environment
;
class
ExternalReferenceRegistry
;
namespace
contextify
{
class
ContextifyContext
;
}
namespace
loader
{
enum
ScriptType :
int
{
kScript
,
kModule
,
kFunction
,
};
enum
HostDefinedOptions :
int
{
kID
=
8
,
kLength
=
9
,
};
enum
ModulePhase :
int
{
kSourcePhase
=
1
,
kDeferPhase
=
2
,
kEvaluationPhase
=
3
,
};
/*
*
* ModuleCacheKey is used to uniquely identify a module request
* in the module cache. It is a composition of the module specifier
* and the import attributes. ModuleImportPhase is not included
* in the key.
*/
struct
ModuleCacheKey
:
public
MemoryRetainer
{
using
ImportAttributeVector =
std::vector<std::pair<std::string, std::string>>;
std::string specifier;
ImportAttributeVector import_attributes;
//
A hash of the specifier, and import attributes.
//
This does not guarantee uniqueness, but is used to reduce
//
the number of comparisons needed when checking for equality.
std::
size_t
hash;
SET_MEMORY_INFO_NAME
(ModuleCacheKey)
SET_SELF_SIZE
(ModuleCacheKey)
void
MemoryInfo
(MemoryTracker* tracker)
const
override
;
//
Returns a string representation of the ModuleCacheKey.
std::string
ToString
()
const
;
template
<
int
elements_per_attribute =
3
>
static
ModuleCacheKey
From
(v8::Local<v8::String> specifier,
v8::Local<v8::FixedArray> import_attributes);
static
ModuleCacheKey
From
(v8::Local<v8::ModuleRequest> v8_request);
struct
Hash
{
std::
size_t
operator
()(
const
ModuleCacheKey& request)
const
{
return
request.
hash
;
}
};
//
Equality operator for ModuleCacheKey.
bool
operator
==(
const
ModuleCacheKey& other)
const
{
//
Hash does not provide uniqueness guarantee, so ignore it.
return
specifier == other.
specifier
&&
import_attributes == other.
import_attributes
;
}
private:
//
Use public ModuleCacheKey::From to create instances.
ModuleCacheKey
(std::string specifier,
ImportAttributeVector import_attributes,
std::
size_t
hash)
: specifier(specifier),
import_attributes
(import_attributes),
hash(hash) {}
};
class
ModuleWrap
:
public
BaseObject
{
public:
enum
InternalFields {
kModuleSlot
= BaseObject::
kInternalFieldCount
,
kModuleSourceObjectSlot
,
kSyntheticEvaluationStepsSlot
,
kContextObjectSlot
,
//
Object whose creation context is the target Context
kLinkedRequestsSlot
,
//
Array of linked requests, each is a ModuleWrap JS
//
wrapper object.
kInternalFieldCount
};
static
void
CreatePerIsolateProperties
(IsolateData* isolate_data,
v8::Local<v8::ObjectTemplate> target);
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);
static
void
HostInitializeImportMetaObjectCallback
(
v8::Local<v8::Context> context,
v8::Local<v8::Module>
module
,
v8::Local<v8::Object> meta);
v8::Local<v8::Context>
context
()
const
;
v8::Maybe<
bool
>
CheckUnsettledTopLevelAwait
();
bool
HasAsyncGraph
();
SET_MEMORY_INFO_NAME
(ModuleWrap)
SET_SELF_SIZE
(ModuleWrap)
SET_NO_MEMORY_INFO
()
bool
IsNotIndicativeOfMemoryLeakAtExit
()
const
override
{
//
XXX: The garbage collection rules for ModuleWrap are *super* unclear.
//
Do these objects ever get GC'd? Are we just okay with leaking them?
return
true
;
}
bool
IsLinked
()
const
{
return
linked_; }
static
v8::Local<v8::PrimitiveArray>
GetHostDefinedOptions
(
v8::Isolate* isolate, v8::Local<v8::Symbol> symbol);
//
When user_cached_data is not std::nullopt, use the code cache if it's not
//
nullptr, otherwise don't use code cache.
//
TODO(joyeecheung): when it is std::nullopt, use on-disk cache
//
See: https://github.com/nodejs/node/issues/47472
static
v8::MaybeLocal<v8::Module>
CompileSourceTextModule
(
Realm* realm,
v8::Local<v8::String> source_text,
v8::Local<v8::String> url,
int
line_offset,
int
column_offset,
v8::Local<v8::PrimitiveArray> host_defined_options,
std::optional<v8::ScriptCompiler::CachedData*> user_cached_data,
bool
* cache_rejected);
static
void
CreateRequiredModuleFacade
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
private:
ModuleWrap
(Realm* realm,
v8::Local<v8::Object> object,
v8::Local<v8::Module>
module
,
v8::Local<v8::String> url,
v8::Local<v8::Object> context_object,
v8::Local<v8::Value> synthetic_evaluation_step);
~ModuleWrap
()
override
;
static
void
New
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
GetModuleRequests
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
SetModuleSourceObject
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
GetModuleSourceObject
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
Link
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
Instantiate
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
Evaluate
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
EvaluateSync
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
GetNamespace
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
GetStatus
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
GetError
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
HasAsyncGraph
(v8::Local<v8::Name> property,
const
v8::PropertyCallbackInfo<v8::Value>& args);
static
void
SetImportModuleDynamicallyCallback
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
SetImportMetaResolveInitializer
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
SetInitializeImportMetaObjectCallback
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
v8::MaybeLocal<v8::Value>
SyntheticModuleEvaluationStepsCallback
(
v8::Local<v8::Context> context, v8::Local<v8::Module>
module
);
static
void
SetSyntheticExport
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
void
CreateCachedData
(
const
v8::FunctionCallbackInfo<v8::Value>& args);
static
v8::MaybeLocal<v8::Module>
ResolveModuleCallback
(
v8::Local<v8::Context> context,
size_t
module_request_index,
v8::Local<v8::Module> referrer);
static
v8::MaybeLocal<v8::Object>
ResolveSourceCallback
(
v8::Local<v8::Context> context,
size_t
module_request_index,
v8::Local<v8::Module> referrer);
static
ModuleWrap*
GetFromModule
(node::Environment*, v8::Local<v8::Module>);
//
This method may throw a JavaScript exception, so the return type is
//
wrapped in a Maybe.
static
v8::Maybe<ModuleWrap*>
ResolveModule
(v8::Local<v8::Context> context,
size_t
module_request_index,
v8::Local<v8::Module> referrer);
std::string url_;
v8::Global<v8::Module> module_;
contextify::ContextifyContext* contextify_context_ =
nullptr
;
bool
synthetic_ =
false
;
bool
linked_ =
false
;
//
This depends on the module to be instantiated so it begins with a
//
nullopt value.
std::optional<
bool
> has_async_graph_ = std::
nullopt
;
int
module_hash_;
//
Corresponds to the ModuleWrap* of the wrappers in kLinkedRequestsSlot.
//
These are populated during Link(), and are only valid after that as
//
convenient shortcuts, but do not hold the ModuleWraps alive. The actual
//
strong references come from the array in kLinkedRequestsSlot.
std::vector<ModuleWrap*> linked_module_wraps_;
};
}
//
namespace loader
}
//
namespace node
#endif
//
defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif
//
SRC_MODULE_WRAP_H_
You can’t perform that action at this time.