11cb0ef41Sopenharmony_ci#include "node.h"
21cb0ef41Sopenharmony_ci#include "v8.h"
31cb0ef41Sopenharmony_ci#include "v8-profiler.h"
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cinamespace {
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciinline void Test(const v8::FunctionCallbackInfo<v8::Value>& args) {
81cb0ef41Sopenharmony_ci  v8::Isolate* const isolate = args.GetIsolate();
91cb0ef41Sopenharmony_ci  const v8::HeapSnapshot* const heap_snapshot =
101cb0ef41Sopenharmony_ci      isolate->GetHeapProfiler()->TakeHeapSnapshot();
111cb0ef41Sopenharmony_ci  struct : public v8::OutputStream {
121cb0ef41Sopenharmony_ci    WriteResult WriteAsciiChunk(char*, int) override { return kContinue; }
131cb0ef41Sopenharmony_ci    void EndOfStream() override {}
141cb0ef41Sopenharmony_ci  } output_stream;
151cb0ef41Sopenharmony_ci  heap_snapshot->Serialize(&output_stream, v8::HeapSnapshot::kJSON);
161cb0ef41Sopenharmony_ci  const_cast<v8::HeapSnapshot*>(heap_snapshot)->Delete();
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciinline void Initialize(v8::Local<v8::Object> binding) {
201cb0ef41Sopenharmony_ci  v8::Isolate* const isolate = binding->GetIsolate();
211cb0ef41Sopenharmony_ci  v8::Local<v8::Context> context = isolate->GetCurrentContext();
221cb0ef41Sopenharmony_ci  binding->Set(context, v8::String::NewFromUtf8(
231cb0ef41Sopenharmony_ci        isolate, "test").ToLocalChecked(),
241cb0ef41Sopenharmony_ci               v8::FunctionTemplate::New(isolate, Test)
251cb0ef41Sopenharmony_ci                   ->GetFunction(context)
261cb0ef41Sopenharmony_ci                   .ToLocalChecked()).FromJust();
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciNODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci}  // anonymous namespace
32