Skip to content

Commit

Permalink
test: use v8 Default Allocator in cctest fixture
Browse files Browse the repository at this point in the history
This commit updates the node_test_fixture to use
v8::ArrayBuffer::Allocator::NewDefaultAllocator() and removes the custom
allocator.

PR-URL: #17366
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
danbev authored and gibfahn committed Dec 20, 2017
1 parent 3c8bdd9 commit a71f214
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"}) {}
Expand Down Expand Up @@ -75,7 +60,6 @@ class NodeTestFixture : public ::testing::Test {

protected:
v8::Isolate::CreateParams params_;
ArrayBufferAllocator allocator_;
v8::Isolate* isolate_;

~NodeTestFixture() {
Expand All @@ -87,7 +71,7 @@ class NodeTestFixture : public ::testing::Test {
platform_ = new node::NodePlatform(8, &current_loop, nullptr);
v8::V8::InitializePlatform(platform_);
v8::V8::Initialize();
params_.array_buffer_allocator = &allocator_;
params_.array_buffer_allocator = allocator_.get();
isolate_ = v8::Isolate::New(params_);
}

Expand All @@ -105,6 +89,8 @@ class NodeTestFixture : public ::testing::Test {

private:
node::NodePlatform* platform_ = nullptr;
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{
v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
};

#endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_

0 comments on commit a71f214

Please sign in to comment.