Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 5538126

Browse files
addaleaxdeepak1556
authored andcommitted
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: nodejs/node#26207 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent dea1404 commit 5538126

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/env-inl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ inline uv_loop_t* IsolateData::event_loop() const {
4747
return event_loop_;
4848
}
4949

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

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

src/env.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ void* Environment::kNodeContextTagPtr = const_cast<void*>(
3636
IsolateData::IsolateData(Isolate* isolate,
3737
uv_loop_t* event_loop,
3838
MultiIsolatePlatform* platform,
39-
uint32_t* zero_fill_field) :
40-
isolate_(isolate),
41-
event_loop_(event_loop),
42-
zero_fill_field_(zero_fill_field),
43-
platform_(platform) {
39+
ArrayBufferAllocator* node_allocator)
40+
: isolate_(isolate),
41+
event_loop_(event_loop),
42+
allocator_(isolate->GetArrayBufferAllocator()),
43+
node_allocator_(node_allocator),
44+
uses_node_allocator_(allocator_ == node_allocator_),
45+
platform_(platform) {
46+
CHECK_NOT_NULL(allocator_);
4447
if (platform_ != nullptr)
4548
platform_->RegisterIsolate(isolate_, event_loop);
4649

src/env.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,19 @@ class Environment;
362362

363363
class IsolateData {
364364
public:
365-
IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop,
365+
IsolateData(v8::Isolate* isolate,
366+
uv_loop_t* event_loop,
366367
MultiIsolatePlatform* platform = nullptr,
367-
uint32_t* zero_fill_field = nullptr);
368+
ArrayBufferAllocator* node_allocator = nullptr);
368369
~IsolateData();
369370
inline uv_loop_t* event_loop() const;
370-
inline uint32_t* zero_fill_field() const;
371371
inline MultiIsolatePlatform* platform() const;
372372
inline std::shared_ptr<PerIsolateOptions> options();
373373

374+
inline bool uses_node_allocator() const;
375+
inline v8::ArrayBuffer::Allocator* allocator() const;
376+
inline ArrayBufferAllocator* node_allocator() const;
377+
374378
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
375379
#define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName)
376380
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
@@ -401,7 +405,9 @@ class IsolateData {
401405

402406
v8::Isolate* const isolate_;
403407
uv_loop_t* const event_loop_;
404-
uint32_t* const zero_fill_field_;
408+
v8::ArrayBuffer::Allocator* const allocator_;
409+
ArrayBufferAllocator* const node_allocator_;
410+
const bool uses_node_allocator_;
405411
MultiIsolatePlatform* platform_;
406412
std::shared_ptr<PerIsolateOptions> options_;
407413

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2832,7 +2832,7 @@ IsolateData* CreateIsolateData(
28322832
uv_loop_t* loop,
28332833
MultiIsolatePlatform* platform,
28342834
ArrayBufferAllocator* allocator) {
2835-
return new IsolateData(isolate, loop, platform, allocator->zero_fill_field());
2835+
return new IsolateData(isolate, loop, platform, allocator);
28362836
}
28372837

28382838

0 commit comments

Comments
 (0)