Skip to content

Commit 4e90c82

Browse files
committed
test: add heap profiler add-on regression test
Add a regression test for #1827. PR-URL: #1828 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 3a1bc06 commit 4e90c82

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

test/addons/heap-profiler/binding.cc

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "node.h"
2+
#include "v8.h"
3+
#include "v8-profiler.h"
4+
5+
namespace {
6+
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(v8::String::Empty(isolate));
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+
19+
inline void Initialize(v8::Local<v8::Object> binding) {
20+
v8::Isolate* const isolate = binding->GetIsolate();
21+
binding->Set(v8::String::NewFromUtf8(isolate, "test"),
22+
v8::FunctionTemplate::New(isolate, Test)->GetFunction());
23+
}
24+
25+
NODE_MODULE(test, Initialize)
26+
27+
} // anonymous namespace

test/addons/heap-profiler/binding.gyp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ]
6+
}
7+
]
8+
}

test/addons/heap-profiler/test.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const binding = require('./build/Release/binding');
4+
5+
// Create an AsyncWrap object.
6+
const timer = setTimeout(function() {}, 1);
7+
timer.unref();
8+
9+
// Stress-test the heap profiler.
10+
binding.test();
11+
12+
clearTimeout(timer);

0 commit comments

Comments
 (0)