From dd8527b305d3242ac24eae8749c0c5f4fdb88606 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 28 Nov 2017 08:45:35 +0100 Subject: [PATCH 1/4] test: use v8 Default Allocator in cctest fixture This commit updates the node_test_fixture to use v8::ArrayBuffer::Allocator::NewDefaultAllocator() and removes the custom allocator. --- test/cctest/node_test_fixture.h | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index 890fe9049994e9..d9f96692311657 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -9,21 +9,6 @@ #include "v8.h" #include "libplatform/libplatform.h" -class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: - virtual void* Allocate(size_t length) { - return AllocateUninitialized(length); - } - - virtual void* AllocateUninitialized(size_t length) { - return calloc(length, 1); - } - - virtual void Free(void* data, size_t) { - free(data); - } -}; - struct Argv { public: Argv() : Argv({"node", "-p", "process.version"}) {} @@ -77,7 +62,6 @@ class NodeTestFixture : public ::testing::Test { protected: v8::Isolate::CreateParams params_; - ArrayBufferAllocator allocator_; v8::Isolate* isolate_; ~NodeTestFixture() { @@ -89,7 +73,8 @@ class NodeTestFixture : public ::testing::Test { platform_ = new node::NodePlatform(8, nullptr); v8::V8::InitializePlatform(platform_); v8::V8::Initialize(); - params_.array_buffer_allocator = &allocator_; + params_.array_buffer_allocator = + v8::ArrayBuffer::Allocator::NewDefaultAllocator(); isolate_ = v8::Isolate::New(params_); } From 36d984a53abee48a6dffc3ebddb255e43721ae65 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 29 Nov 2017 10:44:48 +0100 Subject: [PATCH 2/4] squash: delete allocator in TearDown --- test/cctest/node_test_fixture.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index d9f96692311657..0f6c77ff623ca0 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -73,8 +73,8 @@ class NodeTestFixture : public ::testing::Test { platform_ = new node::NodePlatform(8, nullptr); v8::V8::InitializePlatform(platform_); v8::V8::Initialize(); - params_.array_buffer_allocator = - v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + params_.array_buffer_allocator = allocator_; isolate_ = v8::Isolate::New(params_); } @@ -85,6 +85,7 @@ class NodeTestFixture : public ::testing::Test { uv_run(¤t_loop, UV_RUN_ONCE); } v8::V8::ShutdownPlatform(); + delete allocator_; delete platform_; platform_ = nullptr; CHECK_EQ(0, uv_loop_close(¤t_loop)); @@ -92,6 +93,7 @@ class NodeTestFixture : public ::testing::Test { private: node::NodePlatform* platform_ = nullptr; + v8::ArrayBuffer::Allocator* allocator_ = nullptr; }; #endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_ From 4bfc1b7c9367f064d2c7deb0da86503286a17bfa Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 29 Nov 2017 14:29:07 +0100 Subject: [PATCH 3/4] squash: make allocator a unique_ptr --- test/cctest/node_test_fixture.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index 0f6c77ff623ca0..bbc46986ebe922 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -73,8 +73,7 @@ class NodeTestFixture : public ::testing::Test { platform_ = new node::NodePlatform(8, nullptr); v8::V8::InitializePlatform(platform_); v8::V8::Initialize(); - allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); - params_.array_buffer_allocator = allocator_; + params_.array_buffer_allocator = allocator_.get(); isolate_ = v8::Isolate::New(params_); } @@ -85,7 +84,6 @@ class NodeTestFixture : public ::testing::Test { uv_run(¤t_loop, UV_RUN_ONCE); } v8::V8::ShutdownPlatform(); - delete allocator_; delete platform_; platform_ = nullptr; CHECK_EQ(0, uv_loop_close(¤t_loop)); @@ -93,7 +91,8 @@ class NodeTestFixture : public ::testing::Test { private: node::NodePlatform* platform_ = nullptr; - v8::ArrayBuffer::Allocator* allocator_ = nullptr; + std::unique_ptr allocator_{ + v8::ArrayBuffer::Allocator::NewDefaultAllocator()}; }; #endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_ From 815f61e8b9e511e4fe26a92043604e5bd7ca97ad Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 30 Nov 2017 07:46:03 +0100 Subject: [PATCH 4/4] squash: make CreateParams stack-allocated --- test/cctest/node_test_fixture.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index bbc46986ebe922..d5be613c0bd105 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -61,7 +61,6 @@ class NodeTestFixture : public ::testing::Test { node::MultiIsolatePlatform* Platform() const { return platform_; } protected: - v8::Isolate::CreateParams params_; v8::Isolate* isolate_; ~NodeTestFixture() { @@ -73,6 +72,7 @@ class NodeTestFixture : public ::testing::Test { platform_ = new node::NodePlatform(8, nullptr); v8::V8::InitializePlatform(platform_); v8::V8::Initialize(); + v8::Isolate::CreateParams params_; params_.array_buffer_allocator = allocator_.get(); isolate_ = v8::Isolate::New(params_); }