Skip to content

Commit 5c0e18f

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]>
1 parent 23b075d commit 5c0e18f

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

src/api/environment.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ IsolateData* CreateIsolateData(Isolate* isolate,
124124
uv_loop_t* loop,
125125
MultiIsolatePlatform* platform,
126126
ArrayBufferAllocator* allocator) {
127-
return new IsolateData(
128-
isolate,
129-
loop,
130-
platform,
131-
allocator != nullptr ? allocator->zero_fill_field() : nullptr);
127+
return new IsolateData(isolate, loop, platform, allocator);
132128
}
133129

134130
void FreeIsolateData(IsolateData* isolate_data) {

src/env-inl.h

Lines changed: 10 additions & 2 deletions
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

Lines changed: 8 additions & 5 deletions
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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,20 @@ class Environment;
394394

395395
class IsolateData {
396396
public:
397-
IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop,
397+
IsolateData(v8::Isolate* isolate,
398+
uv_loop_t* event_loop,
398399
MultiIsolatePlatform* platform = nullptr,
399-
uint32_t* zero_fill_field = nullptr);
400+
ArrayBufferAllocator* node_allocator = nullptr);
400401
~IsolateData();
401402
inline uv_loop_t* event_loop() const;
402-
inline uint32_t* zero_fill_field() const;
403403
inline MultiIsolatePlatform* platform() const;
404404
inline std::shared_ptr<PerIsolateOptions> options();
405405
inline void set_options(std::shared_ptr<PerIsolateOptions> options);
406406

407+
inline bool uses_node_allocator() const;
408+
inline v8::ArrayBuffer::Allocator* allocator() const;
409+
inline ArrayBufferAllocator* node_allocator() const;
410+
407411
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
408412
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
409413
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
@@ -436,7 +440,9 @@ class IsolateData {
436440

437441
v8::Isolate* const isolate_;
438442
uv_loop_t* const event_loop_;
439-
uint32_t* const zero_fill_field_;
443+
v8::ArrayBuffer::Allocator* const allocator_;
444+
ArrayBufferAllocator* const node_allocator_;
445+
const bool uses_node_allocator_;
440446
MultiIsolatePlatform* platform_;
441447
std::shared_ptr<PerIsolateOptions> options_;
442448

0 commit comments

Comments
 (0)