Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use v8 Default Allocator in cctest fixture #17366

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 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 @@ -76,8 +61,6 @@ class NodeTestFixture : public ::testing::Test {
node::MultiIsolatePlatform* Platform() const { return platform_; }

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

~NodeTestFixture() {
Expand All @@ -89,7 +72,8 @@ class NodeTestFixture : public ::testing::Test {
platform_ = new node::NodePlatform(8, nullptr);
v8::V8::InitializePlatform(platform_);
v8::V8::Initialize();
params_.array_buffer_allocator = &allocator_;
v8::Isolate::CreateParams params_;
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_