• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "node.h"
2 #include "v8.h"
3 #include "v8-profiler.h"
4 
5 namespace {
6 
Test(const v8::FunctionCallbackInfo<v8::Value> & args)7 inline 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 
Initialize(v8::Local<v8::Object> binding)19 inline 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 
29 NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
30 
31 }  // anonymous namespace
32