src,lib: expose getCategoryEnabledBuffer to use on node.http · nodejs/node@31fdb88
@@ -16,6 +16,8 @@ namespace node {
1616class ExternalReferenceRegistry;
17171818using v8::Array;
19+using v8::ArrayBuffer;
20+using v8::BackingStore;
1921using v8::Context;
2022using v8::Function;
2123using v8::FunctionCallbackInfo;
@@ -25,6 +27,7 @@ using v8::Local;
2527using v8::NewStringType;
2628using v8::Object;
2729using v8::String;
30+using v8::Uint8Array;
2831using v8::Value;
29323033class NodeCategorySet : public BaseObject {
@@ -120,6 +123,27 @@ static void SetTraceCategoryStateUpdateHandler(
120123 env->set_trace_category_state_function(args[0].As<Function>());
121124}
122125126+static void GetCategoryEnabledBuffer(const FunctionCallbackInfo<Value>& args) {
127+CHECK(args[0]->IsString());
128+129+ Isolate* isolate = args.GetIsolate();
130+ node::Utf8Value category_name(isolate, args[0]);
131+132+const uint8_t* enabled_pointer =
133+TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_name.out());
134+uint8_t* enabled_pointer_cast = const_cast<uint8_t*>(enabled_pointer);
135+136+ std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
137+ enabled_pointer_cast,
138+sizeof(*enabled_pointer_cast),
139+ [](void*, size_t, void*) {},
140+nullptr);
141+auto ab = ArrayBuffer::New(isolate, std::move(bs));
142+ v8::Local<Uint8Array> u8 = v8::Uint8Array::New(ab, 0, 1);
143+144+ args.GetReturnValue().Set(u8);
145+}
146+123147void NodeCategorySet::Initialize(Local<Object> target,
124148 Local<Value> unused,
125149 Local<Context> context,
@@ -132,6 +156,8 @@ void NodeCategorySet::Initialize(Local<Object> target,
132156 target,
133157"setTraceCategoryStateUpdateHandler",
134158 SetTraceCategoryStateUpdateHandler);
159+SetMethod(
160+ context, target, "getCategoryEnabledBuffer", GetCategoryEnabledBuffer);
135161136162 Local<FunctionTemplate> category_set =
137163NewFunctionTemplate(isolate, NodeCategorySet::New);
@@ -160,6 +186,7 @@ void NodeCategorySet::RegisterExternalReferences(
160186 ExternalReferenceRegistry* registry) {
161187 registry->Register(GetEnabledCategories);
162188 registry->Register(SetTraceCategoryStateUpdateHandler);
189+ registry->Register(GetCategoryEnabledBuffer);
163190 registry->Register(NodeCategorySet::New);
164191 registry->Register(NodeCategorySet::Enable);
165192 registry->Register(NodeCategorySet::Disable);