Skip to content

Commit 7e10697

Browse files
danbevtargos
authored andcommitted
test: make cctest fixture use node::NewIsolate
This commit updates the gtest fixture to use node::NewIsolate instead of creating a new V8 Isolate using v8::Isolate::New. The motivation for this is that without calling node::NewIsolate the various callbacks set on the isolate, for example AddMessageListener, SetFatalErrorHandler etc, would not get set. I don't think this is the expected behaviour and I ran into this when writing a new cctest. PR-URL: #21419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 4fc05ac commit 7e10697

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

test/cctest/node_test_fixture.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "node_test_fixture.h"
22

3+
ArrayBufferUniquePtr NodeTestFixture::allocator{nullptr, nullptr};
34
uv_loop_t NodeTestFixture::current_loop;
45
std::unique_ptr<node::NodePlatform> NodeTestFixture::platform;
5-
std::unique_ptr<v8::ArrayBuffer::Allocator> NodeTestFixture::allocator;
66
std::unique_ptr<v8::TracingController> NodeTestFixture::tracing_controller;
7-
v8::Isolate::CreateParams NodeTestFixture::params;

test/cctest/node_test_fixture.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ struct Argv {
5353
int nr_args_;
5454
};
5555

56+
using ArrayBufferUniquePtr = std::unique_ptr<node::ArrayBufferAllocator,
57+
decltype(&node::FreeArrayBufferAllocator)>;
5658

5759
class NodeTestFixture : public ::testing::Test {
5860
protected:
59-
static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator;
61+
static ArrayBufferUniquePtr allocator;
6062
static std::unique_ptr<v8::TracingController> tracing_controller;
6163
static std::unique_ptr<node::NodePlatform> platform;
62-
static v8::Isolate::CreateParams params;
6364
static uv_loop_t current_loop;
6465
v8::Isolate* isolate_;
6566

@@ -68,8 +69,6 @@ class NodeTestFixture : public ::testing::Test {
6869
node::tracing::TraceEventHelper::SetTracingController(
6970
tracing_controller.get());
7071
platform.reset(new node::NodePlatform(4, nullptr));
71-
allocator.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator());
72-
params.array_buffer_allocator = allocator.get();
7372
CHECK_EQ(0, uv_loop_init(&current_loop));
7473
v8::V8::InitializePlatform(platform.get());
7574
v8::V8::Initialize();
@@ -85,7 +84,9 @@ class NodeTestFixture : public ::testing::Test {
8584
}
8685

8786
virtual void SetUp() {
88-
isolate_ = v8::Isolate::New(params);
87+
allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(),
88+
&node::FreeArrayBufferAllocator);
89+
isolate_ = NewIsolate(allocator.get());
8990
CHECK_NE(isolate_, nullptr);
9091
}
9192

0 commit comments

Comments
 (0)