Skip to content

Commit 77205b7

Browse files
danbevgibfahn
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 ecb78e6 commit 77205b7

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"}) {}
@@ -75,7 +60,6 @@ class NodeTestFixture : public ::testing::Test {
7560

7661
protected:
7762
v8::Isolate::CreateParams params_;
78-
ArrayBufferAllocator allocator_;
7963
v8::Isolate* isolate_;
8064

8165
~NodeTestFixture() {
@@ -87,7 +71,7 @@ class NodeTestFixture : public ::testing::Test {
8771
platform_ = new node::NodePlatform(8, &current_loop, nullptr);
8872
v8::V8::InitializePlatform(platform_);
8973
v8::V8::Initialize();
90-
params_.array_buffer_allocator = &allocator_;
74+
params_.array_buffer_allocator = allocator_.get();
9175
isolate_ = v8::Isolate::New(params_);
9276
}
9377

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

10690
private:
10791
node::NodePlatform* platform_ = nullptr;
92+
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{
93+
v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
10894
};
10995

11096
#endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_

0 commit comments

Comments
 (0)