Skip to content

Commit

Permalink
test: make cctest fixture use node::NewIsolate
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
danbev committed Jun 27, 2018
1 parent 4f67c6f commit d6f7a32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 1 addition & 2 deletions test/cctest/node_test_fixture.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "node_test_fixture.h"

ArrayBufferUniquePtr NodeTestFixture::allocator{nullptr, nullptr};
uv_loop_t NodeTestFixture::current_loop;
std::unique_ptr<node::NodePlatform> NodeTestFixture::platform;
std::unique_ptr<v8::ArrayBuffer::Allocator> NodeTestFixture::allocator;
std::unique_ptr<v8::TracingController> NodeTestFixture::tracing_controller;
v8::Isolate::CreateParams NodeTestFixture::params;
11 changes: 6 additions & 5 deletions test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ struct Argv {
int nr_args_;
};

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

class NodeTestFixture : public ::testing::Test {
protected:
static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator;
static ArrayBufferUniquePtr allocator;
static std::unique_ptr<v8::TracingController> tracing_controller;
static std::unique_ptr<node::NodePlatform> platform;
static v8::Isolate::CreateParams params;
static uv_loop_t current_loop;
v8::Isolate* isolate_;

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

virtual void SetUp() {
isolate_ = v8::Isolate::New(params);
allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(),
&node::FreeArrayBufferAllocator);
isolate_ = NewIsolate(allocator.get());
CHECK_NE(isolate_, nullptr);
}

Expand Down

0 comments on commit d6f7a32

Please sign in to comment.