Skip to content

Commit ca81d4b

Browse files
danbevMylesBorins
authored andcommitted
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. 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]>
1 parent 1e34a0e commit ca81d4b

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

test/cctest/node_test_fixture.h

+3-17
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@
99
#include "v8.h"
1010
#include "libplatform/libplatform.h"
1111

12-
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
13-
public:
14-
virtual void* Allocate(size_t length) {
15-
return AllocateUninitialized(length);
16-
}
17-
18-
virtual void* AllocateUninitialized(size_t length) {
19-
return calloc(length, 1);
20-
}
21-
22-
virtual void Free(void* data, size_t) {
23-
free(data);
24-
}
25-
};
26-
2712
struct Argv {
2813
public:
2914
Argv() : Argv({"node", "-p", "process.version"}) {}
@@ -77,7 +62,6 @@ class NodeTestFixture : public ::testing::Test {
7762

7863
protected:
7964
v8::Isolate::CreateParams params_;
80-
ArrayBufferAllocator allocator_;
8165
v8::Isolate* isolate_;
8266

8367
~NodeTestFixture() {
@@ -89,7 +73,7 @@ class NodeTestFixture : public ::testing::Test {
8973
platform_ = new node::NodePlatform(8, nullptr);
9074
v8::V8::InitializePlatform(platform_);
9175
v8::V8::Initialize();
92-
params_.array_buffer_allocator = &allocator_;
76+
params_.array_buffer_allocator = allocator_.get();
9377
isolate_ = v8::Isolate::New(params_);
9478
}
9579

@@ -107,6 +91,8 @@ class NodeTestFixture : public ::testing::Test {
10791

10892
private:
10993
node::NodePlatform* platform_ = nullptr;
94+
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{
95+
v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
11096
};
11197

11298
#endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_

0 commit comments

Comments
 (0)