xref: /third_party/node/test/addons/heap-profiler/binding.cc (revision 1cb0ef41)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/addons/heap-profiler/
1#include "node.h"
2#include "v8.h"
3#include "v8-profiler.h"
4
5namespace {
6
7inline void Test(const v8::FunctionCallbackInfo<v8::Value>& args) {
8  v8::Isolate* const isolate = args.GetIsolate();
9  const v8::HeapSnapshot* const heap_snapshot =
10      isolate->GetHeapProfiler()->TakeHeapSnapshot();
11  struct : public v8::OutputStream {
12    WriteResult WriteAsciiChunk(char*, int) override { return kContinue; }
13    void EndOfStream() override {}
14  } output_stream;
15  heap_snapshot->Serialize(&output_stream, v8::HeapSnapshot::kJSON);
16  const_cast<v8::HeapSnapshot*>(heap_snapshot)->Delete();
17}
18
19inline void Initialize(v8::Local<v8::Object> binding) {
20  v8::Isolate* const isolate = binding->GetIsolate();
21  v8::Local<v8::Context> context = isolate->GetCurrentContext();
22  binding->Set(context, v8::String::NewFromUtf8(
23        isolate, "test").ToLocalChecked(),
24               v8::FunctionTemplate::New(isolate, Test)
25                   ->GetFunction(context)
26                   .ToLocalChecked()).FromJust();
27}
28
29NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
30
31}  // anonymous namespace
32

Indexes created Thu Nov 07 10:32:03 CST 2024