1
+ #include " node_trace_events.h"
1
2
#include " base_object-inl.h"
2
3
#include " env-inl.h"
3
4
#include " memory_tracker-inl.h"
@@ -20,11 +21,14 @@ using v8::Context;
20
21
using v8::Function;
21
22
using v8::FunctionCallbackInfo;
22
23
using v8::FunctionTemplate;
24
+ using v8::HandleScope;
23
25
using v8::Isolate;
24
26
using v8::Local;
25
27
using v8::NewStringType;
26
28
using v8::Object;
29
+ using v8::ObjectTemplate;
27
30
using v8::String;
31
+ using v8::Uint8Array;
28
32
using v8::Value;
29
33
30
34
class NodeCategorySet : public BaseObject {
@@ -165,9 +169,97 @@ void NodeCategorySet::RegisterExternalReferences(
165
169
registry->Register (NodeCategorySet::Disable);
166
170
}
167
171
172
+ namespace trace_events {
173
+
174
+ void BindingData::MemoryInfo (MemoryTracker* tracker) const {}
175
+
176
+ BindingData::BindingData (Realm* realm, v8::Local<v8::Object> object)
177
+ : SnapshotableObject(realm, object, type_int) {
178
+ // Get the pointer of the memory for the flag that
179
+ // store if trace is enabled for http the pointer will
180
+ // always be the same and if the category does not exist
181
+ // it creates:
182
+ // https://github.com/nodejs/node/blob/6bbf2a57fcf33266c5859497f8cc32e1389a358a/deps/v8/src/libplatform/tracing/tracing-controller.cc#L322-L342
183
+ auto p = const_cast <uint8_t *>(
184
+ TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED (" node.http" ));
185
+
186
+ // NO_OP deleter
187
+ // the idea of this chunk of code is to construct
188
+ auto nop = [](void *, size_t , void *) {};
189
+ auto bs = v8::ArrayBuffer::NewBackingStore (p, 1 , nop, nullptr );
190
+ auto ab = v8::ArrayBuffer::New (realm->isolate (), std::move (bs));
191
+ v8::Local<Uint8Array> u8 = v8::Uint8Array::New (ab, 0 , 1 );
192
+
193
+ object
194
+ ->Set (realm->context (),
195
+ FIXED_ONE_BYTE_STRING (realm->isolate (), " tracingCategories" ),
196
+ u8)
197
+ .Check ();
198
+ }
199
+
200
+ bool BindingData::PrepareForSerialization (v8::Local<v8::Context> context,
201
+ v8::SnapshotCreator* creator) {
202
+ return true ;
203
+ }
204
+
205
+ InternalFieldInfoBase* BindingData::Serialize (int index) {
206
+ DCHECK_EQ (index , BaseObject::kEmbedderType );
207
+ InternalFieldInfo* info =
208
+ InternalFieldInfoBase::New<InternalFieldInfo>(type ());
209
+ return info;
210
+ }
211
+
212
+ void BindingData::Deserialize (v8::Local<v8::Context> context,
213
+ v8::Local<v8::Object> holder,
214
+ int index,
215
+ InternalFieldInfoBase* info) {
216
+ DCHECK_EQ (index , BaseObject::kEmbedderType );
217
+ v8::HandleScope scope (context->GetIsolate ());
218
+ Realm* realm = Realm::GetCurrent (context);
219
+ BindingData* binding = realm->AddBindingData <BindingData>(context, holder);
220
+ CHECK_NOT_NULL (binding);
221
+ }
222
+
223
+ void BindingData::CreatePerIsolateProperties (IsolateData* isolate_data,
224
+ Local<ObjectTemplate> ctor) {}
225
+
226
+ void BindingData::CreatePerContextProperties (Local<Object> target,
227
+ Local<Value> unused,
228
+ Local<Context> context,
229
+ void * priv) {
230
+ Realm* realm = Realm::GetCurrent (context);
231
+ realm->AddBindingData <BindingData>(context, target);
232
+ }
233
+
234
+ void BindingData::RegisterExternalReferences (
235
+ ExternalReferenceRegistry* registry) {}
236
+
237
+ static void CreatePerIsolateProperties (IsolateData* isolate_data,
238
+ Local<ObjectTemplate> ctor) {
239
+ BindingData::CreatePerIsolateProperties (isolate_data, ctor);
240
+ }
241
+
242
+ static void CreatePerContextProperties (Local<Object> target,
243
+ Local<Value> unused,
244
+ Local<Context> context,
245
+ void * priv) {
246
+ BindingData::CreatePerContextProperties (target, unused, context, priv);
247
+
248
+ NodeCategorySet::Initialize (target, unused, context, priv);
249
+ }
250
+
251
+ void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
252
+ NodeCategorySet::RegisterExternalReferences (registry);
253
+ BindingData::RegisterExternalReferences (registry);
254
+ }
255
+
256
+ } // namespace trace_events
257
+
168
258
} // namespace node
169
259
170
- NODE_BINDING_CONTEXT_AWARE_INTERNAL (trace_events,
171
- node::NodeCategorySet::Initialize)
172
- NODE_BINDING_EXTERNAL_REFERENCE(
173
- trace_events, node::NodeCategorySet::RegisterExternalReferences)
260
+ NODE_BINDING_CONTEXT_AWARE_INTERNAL (
261
+ trace_events, node::trace_events::CreatePerContextProperties)
262
+ NODE_BINDING_PER_ISOLATE_INIT(trace_events,
263
+ node::trace_events::CreatePerIsolateProperties)
264
+ NODE_BINDING_EXTERNAL_REFERENCE(trace_events,
265
+ node::trace_events::RegisterExternalReferences)
0 commit comments