Skip to content

Commit 437bb25

Browse files
committed
src: make IsolateData store ArrayBufferAllocator
This enables us to identify whether we are using an allocator that we know more about than what the generic `ArrayBuffer::Allocator` API provides, in particular whether it is `malloc()`-compatible. PR-URL: #26207 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Backport-PR-URL: #26302 Reviewed-By: Michaël Zasso <[email protected]>
1 parent 7f08e02 commit 437bb25

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

src/api/environment.cc

+1-5
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ IsolateData* CreateIsolateData(Isolate* isolate,
115115
uv_loop_t* loop,
116116
MultiIsolatePlatform* platform,
117117
ArrayBufferAllocator* allocator) {
118-
return new IsolateData(
119-
isolate,
120-
loop,
121-
platform,
122-
allocator != nullptr ? allocator->zero_fill_field() : nullptr);
118+
return new IsolateData(isolate, loop, platform, allocator);
123119
}
124120

125121
void FreeIsolateData(IsolateData* isolate_data) {

src/env-inl.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,16 @@ inline uv_loop_t* IsolateData::event_loop() const {
4949
return event_loop_;
5050
}
5151

52-
inline uint32_t* IsolateData::zero_fill_field() const {
53-
return zero_fill_field_;
52+
inline bool IsolateData::uses_node_allocator() const {
53+
return uses_node_allocator_;
54+
}
55+
56+
inline v8::ArrayBuffer::Allocator* IsolateData::allocator() const {
57+
return allocator_;
58+
}
59+
60+
inline ArrayBufferAllocator* IsolateData::node_allocator() const {
61+
return node_allocator_;
5462
}
5563

5664
inline MultiIsolatePlatform* IsolateData::platform() const {

src/env.cc

+8-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ void* const Environment::kNodeContextTagPtr = const_cast<void*>(
7474
IsolateData::IsolateData(Isolate* isolate,
7575
uv_loop_t* event_loop,
7676
MultiIsolatePlatform* platform,
77-
uint32_t* zero_fill_field) :
78-
isolate_(isolate),
79-
event_loop_(event_loop),
80-
zero_fill_field_(zero_fill_field),
81-
platform_(platform) {
77+
ArrayBufferAllocator* node_allocator)
78+
: isolate_(isolate),
79+
event_loop_(event_loop),
80+
allocator_(isolate->GetArrayBufferAllocator()),
81+
node_allocator_(node_allocator),
82+
uses_node_allocator_(allocator_ == node_allocator_),
83+
platform_(platform) {
84+
CHECK_NOT_NULL(allocator_);
8285
if (platform_ != nullptr)
8386
platform_->RegisterIsolate(isolate_, event_loop);
8487

src/env.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,20 @@ class Environment;
392392

393393
class IsolateData {
394394
public:
395-
IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop,
395+
IsolateData(v8::Isolate* isolate,
396+
uv_loop_t* event_loop,
396397
MultiIsolatePlatform* platform = nullptr,
397-
uint32_t* zero_fill_field = nullptr);
398+
ArrayBufferAllocator* node_allocator = nullptr);
398399
~IsolateData();
399400
inline uv_loop_t* event_loop() const;
400-
inline uint32_t* zero_fill_field() const;
401401
inline MultiIsolatePlatform* platform() const;
402402
inline std::shared_ptr<PerIsolateOptions> options();
403403
inline void set_options(std::shared_ptr<PerIsolateOptions> options);
404404

405+
inline bool uses_node_allocator() const;
406+
inline v8::ArrayBuffer::Allocator* allocator() const;
407+
inline ArrayBufferAllocator* node_allocator() const;
408+
405409
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
406410
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
407411
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
@@ -434,7 +438,9 @@ class IsolateData {
434438

435439
v8::Isolate* const isolate_;
436440
uv_loop_t* const event_loop_;
437-
uint32_t* const zero_fill_field_;
441+
v8::ArrayBuffer::Allocator* const allocator_;
442+
ArrayBufferAllocator* const node_allocator_;
443+
const bool uses_node_allocator_;
438444
MultiIsolatePlatform* platform_;
439445
std::shared_ptr<PerIsolateOptions> options_;
440446

0 commit comments

Comments
 (0)