/src/node/src/node_realm.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "node_realm.h" |
2 | | #include "env-inl.h" |
3 | | |
4 | | #include "memory_tracker-inl.h" |
5 | | #include "node_builtins.h" |
6 | | #include "node_process.h" |
7 | | #include "util.h" |
8 | | |
9 | | namespace node { |
10 | | |
11 | | using v8::Context; |
12 | | using v8::EscapableHandleScope; |
13 | | using v8::HandleScope; |
14 | | using v8::Local; |
15 | | using v8::MaybeLocal; |
16 | | using v8::Object; |
17 | | using v8::SnapshotCreator; |
18 | | using v8::String; |
19 | | using v8::Value; |
20 | | |
21 | | Realm::Realm(Environment* env, v8::Local<v8::Context> context, Kind kind) |
22 | 127k | : env_(env), isolate_(context->GetIsolate()), kind_(kind) { |
23 | 127k | context_.Reset(isolate_, context); |
24 | 127k | env->AssignToContext(context, this, ContextInfo("")); |
25 | 127k | } |
26 | | |
27 | 127k | Realm::~Realm() { |
28 | 127k | CHECK_EQ(base_object_count_, 0); |
29 | 127k | } |
30 | | |
31 | 0 | void Realm::MemoryInfo(MemoryTracker* tracker) const { |
32 | 0 | #define V(PropertyName, TypeName) \ |
33 | 0 | tracker->TrackField(#PropertyName, PropertyName()); |
34 | 0 | PER_REALM_STRONG_PERSISTENT_VALUES(V) |
35 | 0 | #undef V |
36 | |
|
37 | 0 | tracker->TrackField("cleanup_queue", cleanup_queue_); |
38 | 0 | tracker->TrackField("builtins_with_cache", builtins_with_cache); |
39 | 0 | tracker->TrackField("builtins_without_cache", builtins_without_cache); |
40 | 0 | } |
41 | | |
42 | 127k | void Realm::CreateProperties() { |
43 | 127k | HandleScope handle_scope(isolate_); |
44 | 127k | Local<Context> ctx = context(); |
45 | | |
46 | | // Store primordials setup by the per-context script in the environment. |
47 | 127k | Local<Object> per_context_bindings = |
48 | 127k | GetPerContextExports(ctx).ToLocalChecked(); |
49 | 127k | Local<Value> primordials = |
50 | 127k | per_context_bindings->Get(ctx, env_->primordials_string()) |
51 | 127k | .ToLocalChecked(); |
52 | 127k | CHECK(primordials->IsObject()); |
53 | 127k | set_primordials(primordials.As<Object>()); |
54 | | |
55 | 127k | Local<String> prototype_string = |
56 | 127k | FIXED_ONE_BYTE_STRING(isolate(), "prototype"); |
57 | | |
58 | 127k | #define V(EnvPropertyName, PrimordialsPropertyName) \ |
59 | 509k | { \ |
60 | 509k | Local<Value> ctor = \ |
61 | 509k | primordials.As<Object>() \ |
62 | 509k | ->Get(ctx, \ |
63 | 509k | FIXED_ONE_BYTE_STRING(isolate(), PrimordialsPropertyName)) \ |
64 | 509k | .ToLocalChecked(); \ |
65 | 509k | CHECK(ctor->IsObject()); \ |
66 | 509k | Local<Value> prototype = \ |
67 | 509k | ctor.As<Object>()->Get(ctx, prototype_string).ToLocalChecked(); \ |
68 | 509k | CHECK(prototype->IsObject()); \ |
69 | 509k | set_##EnvPropertyName(prototype.As<Object>()); \ |
70 | 509k | } |
71 | | |
72 | 254k | V(primordials_safe_map_prototype_object, "SafeMap"); |
73 | 254k | V(primordials_safe_set_prototype_object, "SafeSet"); |
74 | 254k | V(primordials_safe_weak_map_prototype_object, "SafeWeakMap"); |
75 | 254k | V(primordials_safe_weak_set_prototype_object, "SafeWeakSet"); |
76 | 254k | #undef V |
77 | | |
78 | | // TODO(legendecas): some methods probably doesn't need to be created with |
79 | | // process. Distinguish them and create process object only in the principal |
80 | | // realm. |
81 | 254k | Local<Object> process_object = |
82 | 254k | node::CreateProcessObject(this).FromMaybe(Local<Object>()); |
83 | 254k | set_process_object(process_object); |
84 | 254k | } |
85 | | |
86 | 0 | RealmSerializeInfo Realm::Serialize(SnapshotCreator* creator) { |
87 | 0 | RealmSerializeInfo info; |
88 | 0 | Local<Context> ctx = context(); |
89 | | |
90 | | // Currently all modules are compiled without cache in builtin snapshot |
91 | | // builder. |
92 | 0 | info.builtins = std::vector<std::string>(builtins_without_cache.begin(), |
93 | 0 | builtins_without_cache.end()); |
94 | |
|
95 | 0 | uint32_t id = 0; |
96 | 0 | #define V(PropertyName, TypeName) \ |
97 | 0 | do { \ |
98 | 0 | Local<TypeName> field = PropertyName(); \ |
99 | 0 | if (!field.IsEmpty()) { \ |
100 | 0 | size_t index = creator->AddData(ctx, field); \ |
101 | 0 | info.persistent_values.push_back({#PropertyName, id, index}); \ |
102 | 0 | } \ |
103 | 0 | id++; \ |
104 | 0 | } while (0); |
105 | 0 | PER_REALM_STRONG_PERSISTENT_VALUES(V) |
106 | 0 | #undef V |
107 | | |
108 | | // Do this after other creator->AddData() calls so that Snapshotable objects |
109 | | // can use 0 to indicate that a SnapshotIndex is invalid. |
110 | 0 | SerializeSnapshotableObjects(this, creator, &info); |
111 | |
|
112 | 0 | info.context = creator->AddData(ctx, ctx); |
113 | 0 | return info; |
114 | 0 | } |
115 | | |
116 | 0 | void Realm::DeserializeProperties(const RealmSerializeInfo* info) { |
117 | 0 | Local<Context> ctx = context(); |
118 | |
|
119 | 0 | builtins_in_snapshot = info->builtins; |
120 | |
|
121 | 0 | const std::vector<PropInfo>& values = info->persistent_values; |
122 | 0 | size_t i = 0; // index to the array |
123 | 0 | uint32_t id = 0; |
124 | 0 | #define V(PropertyName, TypeName) \ |
125 | 0 | do { \ |
126 | 0 | if (values.size() > i && id == values[i].id) { \ |
127 | 0 | const PropInfo& d = values[i]; \ |
128 | 0 | DCHECK_EQ(d.name, #PropertyName); \ |
129 | 0 | MaybeLocal<TypeName> maybe_field = \ |
130 | 0 | ctx->GetDataFromSnapshotOnce<TypeName>(d.index); \ |
131 | 0 | Local<TypeName> field; \ |
132 | 0 | if (!maybe_field.ToLocal(&field)) { \ |
133 | 0 | fprintf(stderr, \ |
134 | 0 | "Failed to deserialize realm value " #PropertyName "\n"); \ |
135 | 0 | } \ |
136 | 0 | set_##PropertyName(field); \ |
137 | 0 | i++; \ |
138 | 0 | } \ |
139 | 0 | id++; \ |
140 | 0 | } while (0); |
141 | |
|
142 | 0 | PER_REALM_STRONG_PERSISTENT_VALUES(V); |
143 | 0 | #undef V |
144 | |
|
145 | 0 | MaybeLocal<Context> maybe_ctx_from_snapshot = |
146 | 0 | ctx->GetDataFromSnapshotOnce<Context>(info->context); |
147 | 0 | Local<Context> ctx_from_snapshot; |
148 | 0 | if (!maybe_ctx_from_snapshot.ToLocal(&ctx_from_snapshot)) { |
149 | 0 | fprintf(stderr, |
150 | 0 | "Failed to deserialize context back reference from the snapshot\n"); |
151 | 0 | } |
152 | 0 | CHECK_EQ(ctx_from_snapshot, ctx); |
153 | | |
154 | 0 | DoneBootstrapping(); |
155 | 0 | } |
156 | | |
157 | 891k | MaybeLocal<Value> Realm::ExecuteBootstrapper(const char* id) { |
158 | 891k | EscapableHandleScope scope(isolate()); |
159 | 891k | Local<Context> ctx = context(); |
160 | 891k | MaybeLocal<Value> result = |
161 | 891k | env()->builtin_loader()->CompileAndCall(ctx, id, this); |
162 | | |
163 | | // If there was an error during bootstrap, it must be unrecoverable |
164 | | // (e.g. max call stack exceeded). Clear the stack so that the |
165 | | // AsyncCallbackScope destructor doesn't fail on the id check. |
166 | | // There are only two ways to have a stack size > 1: 1) the user manually |
167 | | // called MakeCallback or 2) user awaited during bootstrap, which triggered |
168 | | // _tickCallback(). |
169 | 891k | if (result.IsEmpty()) { |
170 | 0 | env()->async_hooks()->clear_async_id_stack(); |
171 | 0 | } |
172 | | |
173 | 891k | return scope.EscapeMaybe(result); |
174 | 891k | } |
175 | | |
176 | 127k | MaybeLocal<Value> Realm::RunBootstrapping() { |
177 | 127k | EscapableHandleScope scope(isolate_); |
178 | | |
179 | 127k | CHECK(!has_run_bootstrapping_code()); |
180 | | |
181 | 127k | Local<Value> result; |
182 | 127k | if (!ExecuteBootstrapper("internal/bootstrap/realm").ToLocal(&result) || |
183 | 127k | !BootstrapRealm().ToLocal(&result)) { |
184 | 0 | return MaybeLocal<Value>(); |
185 | 0 | } |
186 | | |
187 | 127k | DoneBootstrapping(); |
188 | | |
189 | 127k | return scope.Escape(result); |
190 | 127k | } |
191 | | |
192 | 127k | void Realm::DoneBootstrapping() { |
193 | | // Make sure that no request or handle is created during bootstrap - |
194 | | // if necessary those should be done in pre-execution. |
195 | | // Usually, doing so would trigger the checks present in the ReqWrap and |
196 | | // HandleWrap classes, so this is only a consistency check. |
197 | | |
198 | | // TODO(legendecas): track req_wrap and handle_wrap by realms instead of |
199 | | // environments. |
200 | 127k | if (kind_ == kPrincipal) { |
201 | 127k | CHECK(env_->req_wrap_queue()->IsEmpty()); |
202 | 127k | CHECK(env_->handle_wrap_queue()->IsEmpty()); |
203 | 127k | } |
204 | | |
205 | 127k | has_run_bootstrapping_code_ = true; |
206 | | |
207 | | // This adjusts the return value of base_object_created_after_bootstrap() so |
208 | | // that tests that check the count do not have to account for internally |
209 | | // created BaseObjects. |
210 | 127k | base_object_created_by_bootstrap_ = base_object_count_; |
211 | 127k | } |
212 | | |
213 | 127k | void Realm::RunCleanup() { |
214 | 127k | TRACE_EVENT0(TRACING_CATEGORY_NODE1(realm), "RunCleanup"); |
215 | 1.65M | for (size_t i = 0; i < binding_data_store_.size(); ++i) { |
216 | 1.52M | binding_data_store_[i].reset(); |
217 | 1.52M | } |
218 | 127k | cleanup_queue_.Drain(); |
219 | 127k | } |
220 | | |
221 | 0 | void Realm::PrintInfoForSnapshot() { |
222 | 0 | fprintf(stderr, "Realm = %p\n", this); |
223 | 0 | fprintf(stderr, "BaseObjects of the Realm:\n"); |
224 | 0 | size_t i = 0; |
225 | 0 | ForEachBaseObject([&](BaseObject* obj) { |
226 | 0 | std::cerr << "#" << i++ << " " << obj << ": " << obj->MemoryInfoName() |
227 | 0 | << "\n"; |
228 | 0 | }); |
229 | |
|
230 | 0 | fprintf(stderr, "\nBuiltins without cache:\n"); |
231 | 0 | for (const auto& s : builtins_without_cache) { |
232 | 0 | fprintf(stderr, "%s\n", s.c_str()); |
233 | 0 | } |
234 | 0 | fprintf(stderr, "\nBuiltins with cache:\n"); |
235 | 0 | for (const auto& s : builtins_with_cache) { |
236 | 0 | fprintf(stderr, "%s\n", s.c_str()); |
237 | 0 | } |
238 | 0 | fprintf(stderr, "\nStatic bindings (need to be registered):\n"); |
239 | 0 | for (const auto mod : internal_bindings) { |
240 | 0 | fprintf(stderr, "%s:%s\n", mod->nm_filename, mod->nm_modname); |
241 | 0 | } |
242 | |
|
243 | 0 | fprintf(stderr, "End of the Realm.\n"); |
244 | 0 | } |
245 | | |
246 | 0 | void Realm::VerifyNoStrongBaseObjects() { |
247 | | // When a process exits cleanly, i.e. because the event loop ends up without |
248 | | // things to wait for, the Node.js objects that are left on the heap should |
249 | | // be: |
250 | | // |
251 | | // 1. weak, i.e. ready for garbage collection once no longer referenced, or |
252 | | // 2. detached, i.e. scheduled for destruction once no longer referenced, or |
253 | | // 3. an unrefed libuv handle, i.e. does not keep the event loop alive, or |
254 | | // 4. an inactive libuv handle (essentially the same here) |
255 | | // |
256 | | // There are a few exceptions to this rule, but generally, if there are |
257 | | // C++-backed Node.js objects on the heap that do not fall into the above |
258 | | // categories, we may be looking at a potential memory leak. Most likely, |
259 | | // the cause is a missing MakeWeak() call on the corresponding object. |
260 | | // |
261 | | // In order to avoid this kind of problem, we check the list of BaseObjects |
262 | | // for these criteria. Currently, we only do so when explicitly instructed to |
263 | | // or when in debug mode (where --verify-base-objects is always-on). |
264 | | |
265 | | // TODO(legendecas): introduce per-realm options. |
266 | 0 | if (!env()->options()->verify_base_objects) return; |
267 | | |
268 | 0 | ForEachBaseObject([](BaseObject* obj) { |
269 | 0 | if (obj->IsNotIndicativeOfMemoryLeakAtExit()) return; |
270 | 0 | fprintf(stderr, |
271 | 0 | "Found bad BaseObject during clean exit: %s\n", |
272 | 0 | obj->MemoryInfoName()); |
273 | 0 | fflush(stderr); |
274 | 0 | ABORT(); |
275 | 0 | }); |
276 | 0 | } |
277 | | |
278 | 28.0M | v8::Local<v8::Context> Realm::context() const { |
279 | 28.0M | return PersistentToLocal::Strong(context_); |
280 | 28.0M | } |
281 | | |
282 | | // Per-realm strong value accessors. The per-realm values should avoid being |
283 | | // accessed across realms. |
284 | | #define V(PropertyName, TypeName) \ |
285 | 4.26M | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ |
286 | 4.26M | return PersistentToLocal::Strong(PropertyName##_); \ |
287 | 4.26M | } \ node::PrincipalRealm::async_hooks_after_function() const Line | Count | Source | 285 | 2 | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 2 | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 2 | } \ |
node::PrincipalRealm::async_hooks_before_function() const Line | Count | Source | 285 | 2 | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 2 | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 2 | } \ |
node::PrincipalRealm::async_hooks_callback_trampoline() const Line | Count | Source | 285 | 6.40k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 6.40k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 6.40k | } \ |
Unexecuted instantiation: node::PrincipalRealm::async_hooks_binding() const Unexecuted instantiation: node::PrincipalRealm::async_hooks_destroy_function() const node::PrincipalRealm::async_hooks_init_function() const Line | Count | Source | 285 | 127k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 127k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 127k | } \ |
Unexecuted instantiation: node::PrincipalRealm::async_hooks_promise_resolve_function() const node::PrincipalRealm::buffer_prototype_object() const Line | Count | Source | 285 | 7.59k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 7.59k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 7.59k | } \ |
Unexecuted instantiation: node::PrincipalRealm::crypto_key_object_constructor() const Unexecuted instantiation: node::PrincipalRealm::crypto_key_object_private_constructor() const Unexecuted instantiation: node::PrincipalRealm::crypto_key_object_public_constructor() const Unexecuted instantiation: node::PrincipalRealm::crypto_key_object_secret_constructor() const Unexecuted instantiation: node::PrincipalRealm::domexception_function() const node::PrincipalRealm::enhance_fatal_stack_after_inspector() const Line | Count | Source | 285 | 84.1k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 84.1k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 84.1k | } \ |
node::PrincipalRealm::enhance_fatal_stack_before_inspector() const Line | Count | Source | 285 | 84.1k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 84.1k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 84.1k | } \ |
Unexecuted instantiation: node::PrincipalRealm::get_source_map_error_source() const Unexecuted instantiation: node::PrincipalRealm::host_import_module_dynamically_callback() const Unexecuted instantiation: node::PrincipalRealm::host_initialize_import_meta_object_callback() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_altsvc_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_error_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_frame_error_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_goaway_data_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_headers_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_origin_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_ping_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_priority_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_settings_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_stream_close_function() const Unexecuted instantiation: node::PrincipalRealm::http2session_on_stream_trailers_function() const node::PrincipalRealm::internal_binding_loader() const Line | Count | Source | 285 | 763k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 763k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 763k | } \ |
Unexecuted instantiation: node::PrincipalRealm::immediate_callback_function() const Unexecuted instantiation: node::PrincipalRealm::inspector_console_extension_installer() const Unexecuted instantiation: node::PrincipalRealm::inspector_disable_async_hooks() const Unexecuted instantiation: node::PrincipalRealm::inspector_enable_async_hooks() const Unexecuted instantiation: node::PrincipalRealm::maybe_cache_generated_source_map() const Unexecuted instantiation: node::PrincipalRealm::messaging_deserialize_create_object() const Unexecuted instantiation: node::PrincipalRealm::message_port() const node::PrincipalRealm::builtin_module_require() const Line | Count | Source | 285 | 763k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 763k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 763k | } \ |
Unexecuted instantiation: node::PrincipalRealm::performance_entry_callback() const node::PrincipalRealm::prepare_stack_trace_callback() const Line | Count | Source | 285 | 158k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 158k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 158k | } \ |
node::PrincipalRealm::process_object() const Line | Count | Source | 285 | 1.11M | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 1.11M | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 1.11M | } \ |
Unexecuted instantiation: node::PrincipalRealm::process_emit_warning_sync() const node::PrincipalRealm::primordials() const Line | Count | Source | 285 | 891k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 891k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 891k | } \ |
node::PrincipalRealm::primordials_safe_map_prototype_object() const Line | Count | Source | 285 | 254k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 254k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 254k | } \ |
Unexecuted instantiation: node::PrincipalRealm::primordials_safe_set_prototype_object() const Unexecuted instantiation: node::PrincipalRealm::primordials_safe_weak_map_prototype_object() const Unexecuted instantiation: node::PrincipalRealm::primordials_safe_weak_set_prototype_object() const Unexecuted instantiation: node::PrincipalRealm::promise_hook_handler() const Unexecuted instantiation: node::PrincipalRealm::promise_reject_callback() const Unexecuted instantiation: node::PrincipalRealm::snapshot_serialize_callback() const Unexecuted instantiation: node::PrincipalRealm::snapshot_deserialize_callback() const Unexecuted instantiation: node::PrincipalRealm::snapshot_deserialize_main() const Unexecuted instantiation: node::PrincipalRealm::source_map_cache_getter() const node::PrincipalRealm::tick_callback_function() const Line | Count | Source | 285 | 8.60k | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 8.60k | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 8.60k | } \ |
Unexecuted instantiation: node::PrincipalRealm::timers_callback_function() const node::PrincipalRealm::tls_wrap_constructor_function() const Line | Count | Source | 285 | 810 | v8::Local<TypeName> PrincipalRealm::PropertyName() const { \ | 286 | 810 | return PersistentToLocal::Strong(PropertyName##_); \ | 287 | 810 | } \ |
Unexecuted instantiation: node::PrincipalRealm::trace_category_state_function() const Unexecuted instantiation: node::PrincipalRealm::udp_constructor_function() const Unexecuted instantiation: node::PrincipalRealm::url_constructor_function() const Unexecuted instantiation: node::PrincipalRealm::wasm_streaming_compilation_impl() const Unexecuted instantiation: node::PrincipalRealm::wasm_streaming_object_constructor() const |
288 | 4.95M | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ |
289 | 4.95M | DCHECK_IMPLIES(!value.IsEmpty(), \ |
290 | 4.95M | isolate()->GetCurrentContext() == context()); \ |
291 | 4.95M | PropertyName##_.Reset(isolate(), value); \ |
292 | 4.95M | } node::PrincipalRealm::set_async_hooks_after_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 254k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 254k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 254k | isolate()->GetCurrentContext() == context()); \ | 291 | 254k | PropertyName##_.Reset(isolate(), value); \ | 292 | 254k | } |
node::PrincipalRealm::set_async_hooks_before_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 254k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 254k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 254k | isolate()->GetCurrentContext() == context()); \ | 291 | 254k | PropertyName##_.Reset(isolate(), value); \ | 292 | 254k | } |
node::PrincipalRealm::set_async_hooks_callback_trampoline(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_async_hooks_binding(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_async_hooks_destroy_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 254k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 254k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 254k | isolate()->GetCurrentContext() == context()); \ | 291 | 254k | PropertyName##_.Reset(isolate(), value); \ | 292 | 254k | } |
node::PrincipalRealm::set_async_hooks_init_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 254k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 254k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 254k | isolate()->GetCurrentContext() == context()); \ | 291 | 254k | PropertyName##_.Reset(isolate(), value); \ | 292 | 254k | } |
node::PrincipalRealm::set_async_hooks_promise_resolve_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 254k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 254k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 254k | isolate()->GetCurrentContext() == context()); \ | 291 | 254k | PropertyName##_.Reset(isolate(), value); \ | 292 | 254k | } |
node::PrincipalRealm::set_buffer_prototype_object(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
Unexecuted instantiation: node::PrincipalRealm::set_crypto_key_object_constructor(v8::Local<v8::Function>) node::PrincipalRealm::set_crypto_key_object_private_constructor(v8::Local<v8::Function>) Line | Count | Source | 288 | 8.21k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 8.21k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 8.21k | isolate()->GetCurrentContext() == context()); \ | 291 | 8.21k | PropertyName##_.Reset(isolate(), value); \ | 292 | 8.21k | } |
node::PrincipalRealm::set_crypto_key_object_public_constructor(v8::Local<v8::Function>) Line | Count | Source | 288 | 8.21k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 8.21k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 8.21k | isolate()->GetCurrentContext() == context()); \ | 291 | 8.21k | PropertyName##_.Reset(isolate(), value); \ | 292 | 8.21k | } |
node::PrincipalRealm::set_crypto_key_object_secret_constructor(v8::Local<v8::Function>) Line | Count | Source | 288 | 8.21k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 8.21k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 8.21k | isolate()->GetCurrentContext() == context()); \ | 291 | 8.21k | PropertyName##_.Reset(isolate(), value); \ | 292 | 8.21k | } |
Unexecuted instantiation: node::PrincipalRealm::set_domexception_function(v8::Local<v8::Function>) node::PrincipalRealm::set_enhance_fatal_stack_after_inspector(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_enhance_fatal_stack_before_inspector(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
Unexecuted instantiation: node::PrincipalRealm::set_get_source_map_error_source(v8::Local<v8::Function>) node::PrincipalRealm::set_host_import_module_dynamically_callback(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_host_initialize_import_meta_object_callback(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_altsvc_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_error_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_frame_error_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_goaway_data_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_headers_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_origin_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_ping_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_priority_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_settings_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_stream_close_function(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_http2session_on_stream_trailers_function(v8::Local<v8::Function>) node::PrincipalRealm::set_internal_binding_loader(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_immediate_callback_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_inspector_console_extension_installer(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_inspector_disable_async_hooks(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_inspector_enable_async_hooks(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_maybe_cache_generated_source_map(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_messaging_deserialize_create_object(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
Unexecuted instantiation: node::PrincipalRealm::set_message_port(v8::Local<v8::Object>) node::PrincipalRealm::set_builtin_module_require(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_performance_entry_callback(v8::Local<v8::Function>) Line | Count | Source | 288 | 86.3k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 86.3k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 86.3k | isolate()->GetCurrentContext() == context()); \ | 291 | 86.3k | PropertyName##_.Reset(isolate(), value); \ | 292 | 86.3k | } |
node::PrincipalRealm::set_prepare_stack_trace_callback(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_process_object(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_process_emit_warning_sync(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_primordials(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_primordials_safe_map_prototype_object(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_primordials_safe_set_prototype_object(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_primordials_safe_weak_map_prototype_object(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_primordials_safe_weak_set_prototype_object(v8::Local<v8::Object>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
Unexecuted instantiation: node::PrincipalRealm::set_promise_hook_handler(v8::Local<v8::Function>) node::PrincipalRealm::set_promise_reject_callback(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
Unexecuted instantiation: node::PrincipalRealm::set_snapshot_serialize_callback(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_snapshot_deserialize_callback(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_snapshot_deserialize_main(v8::Local<v8::Function>) Unexecuted instantiation: node::PrincipalRealm::set_source_map_cache_getter(v8::Local<v8::Function>) node::PrincipalRealm::set_tick_callback_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_timers_callback_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_tls_wrap_constructor_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 810 | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 810 | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 810 | isolate()->GetCurrentContext() == context()); \ | 291 | 810 | PropertyName##_.Reset(isolate(), value); \ | 292 | 810 | } |
node::PrincipalRealm::set_trace_category_state_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
node::PrincipalRealm::set_udp_constructor_function(v8::Local<v8::Function>) Line | Count | Source | 288 | 814 | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 814 | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 814 | isolate()->GetCurrentContext() == context()); \ | 291 | 814 | PropertyName##_.Reset(isolate(), value); \ | 292 | 814 | } |
Unexecuted instantiation: node::PrincipalRealm::set_url_constructor_function(v8::Local<v8::Function>) node::PrincipalRealm::set_wasm_streaming_compilation_impl(v8::Local<v8::Function>) Line | Count | Source | 288 | 127k | void PrincipalRealm::set_##PropertyName(v8::Local<TypeName> value) { \ | 289 | 127k | DCHECK_IMPLIES(!value.IsEmpty(), \ | 290 | 127k | isolate()->GetCurrentContext() == context()); \ | 291 | 127k | PropertyName##_.Reset(isolate(), value); \ | 292 | 127k | } |
Unexecuted instantiation: node::PrincipalRealm::set_wasm_streaming_object_constructor(v8::Local<v8::Function>) |
293 | | PER_REALM_STRONG_PERSISTENT_VALUES(V) |
294 | | #undef V |
295 | | |
296 | | PrincipalRealm::PrincipalRealm(Environment* env, |
297 | | v8::Local<v8::Context> context, |
298 | | const RealmSerializeInfo* realm_info) |
299 | 127k | : Realm(env, context, kPrincipal) { |
300 | | // Create properties if not deserializing from snapshot. |
301 | | // Or the properties are deserialized with DeserializeProperties() when the |
302 | | // env drained the deserialize requests. |
303 | 127k | if (realm_info == nullptr) { |
304 | 127k | CreateProperties(); |
305 | 127k | } |
306 | 127k | } |
307 | | |
308 | 127k | PrincipalRealm::~PrincipalRealm() { |
309 | 127k | DCHECK(!context_.IsEmpty()); |
310 | | |
311 | 127k | HandleScope handle_scope(isolate()); |
312 | 127k | env_->UnassignFromContext(context()); |
313 | 127k | } |
314 | | |
315 | 127k | MaybeLocal<Value> PrincipalRealm::BootstrapRealm() { |
316 | 127k | HandleScope scope(isolate_); |
317 | | |
318 | 127k | if (ExecuteBootstrapper("internal/bootstrap/node").IsEmpty()) { |
319 | 0 | return MaybeLocal<Value>(); |
320 | 0 | } |
321 | | |
322 | 127k | if (!env_->no_browser_globals()) { |
323 | 127k | if (ExecuteBootstrapper("internal/bootstrap/web/exposed-wildcard") |
324 | 127k | .IsEmpty() || |
325 | 127k | ExecuteBootstrapper("internal/bootstrap/web/exposed-window-or-worker") |
326 | 127k | .IsEmpty()) { |
327 | 0 | return MaybeLocal<Value>(); |
328 | 0 | } |
329 | 127k | } |
330 | | |
331 | | // TODO(joyeecheung): skip these in the snapshot building for workers. |
332 | 127k | auto thread_switch_id = |
333 | 127k | env_->is_main_thread() ? "internal/bootstrap/switches/is_main_thread" |
334 | 127k | : "internal/bootstrap/switches/is_not_main_thread"; |
335 | 127k | if (ExecuteBootstrapper(thread_switch_id).IsEmpty()) { |
336 | 0 | return MaybeLocal<Value>(); |
337 | 0 | } |
338 | | |
339 | 127k | auto process_state_switch_id = |
340 | 127k | env_->owns_process_state() |
341 | 127k | ? "internal/bootstrap/switches/does_own_process_state" |
342 | 127k | : "internal/bootstrap/switches/does_not_own_process_state"; |
343 | 127k | if (ExecuteBootstrapper(process_state_switch_id).IsEmpty()) { |
344 | 0 | return MaybeLocal<Value>(); |
345 | 0 | } |
346 | | |
347 | | // Setup process.env proxy. |
348 | 127k | Local<String> env_string = FIXED_ONE_BYTE_STRING(isolate_, "env"); |
349 | 127k | Local<Object> env_proxy; |
350 | 127k | if (!isolate_data()->env_proxy_template()->NewInstance(context()).ToLocal( |
351 | 127k | &env_proxy) || |
352 | 127k | process_object()->Set(context(), env_string, env_proxy).IsNothing()) { |
353 | 0 | return MaybeLocal<Value>(); |
354 | 0 | } |
355 | | |
356 | 127k | return v8::True(isolate_); |
357 | 127k | } |
358 | | |
359 | | } // namespace node |