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 <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
danbev authored and MylesBorins committed Dec 12, 2017
1 parent 1e34a0e commit ca81d4b
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 @@ -77,7 +62,6 @@ class NodeTestFixture : public ::testing::Test {

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

~NodeTestFixture() {
Expand All @@ -89,7 +73,7 @@ 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 = allocator_.get();
isolate_ = v8::Isolate::New(params_);
}

Expand All @@ -107,6 +91,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 ca81d4b

Please sign in to comment.