Closed
Description
The new API is present in V8 7.9, so we can already migrate to it:
Lines 5007 to 5043 in b551c65
| /** | |
| * Create a new ArrayBuffer with an existing backing store. | |
| * The created array keeps a reference to the backing store until the array | |
| * is garbage collected. Note that the IsExternal bit does not affect this | |
| * reference from the array to the backing store. | |
| * | |
| * In future IsExternal bit will be removed. Until then the bit is set as | |
| * follows. If the backing store does not own the underlying buffer, then | |
| * the array is created in externalized state. Otherwise, the array is created | |
| * in internalized state. In the latter case the array can be transitioned | |
| * to the externalized state using Externalize(backing_store). | |
| */ | |
| static Local<ArrayBuffer> New(Isolate* isolate, | |
| std::shared_ptr<BackingStore> backing_store); | |
| /** | |
| * Returns a new standalone BackingStore that is allocated using the array | |
| * buffer allocator of the isolate. The result can be later passed to | |
| * ArrayBuffer::New. | |
| * | |
| * If the allocator returns nullptr, then the function may cause GCs in the | |
| * given isolate and re-try the allocation. If GCs do not help, then the | |
| * function will crash with an out-of-memory error. | |
| */ | |
| static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate, | |
| size_t byte_length); | |
| /** | |
| * Returns a new standalone BackingStore that takes over the ownership of | |
| * the given buffer. The destructor of the BackingStore invokes the given | |
| * deleter callback. | |
| * | |
| * The result can be later passed to ArrayBuffer::New. The raw pointer | |
| * to the buffer must not be passed again to any V8 API function. | |
| */ | |
| static std::unique_ptr<BackingStore> NewBackingStore( | |
| void* data, size_t byte_length, BackingStoreDeleterCallback deleter, | |
| void* deleter_data); |
There is an upstream issue to gather feedback: v8:9908.
Reacted by Anna Henningsen and Linz
Activity
thangktran commentedon Nov 18, 2019
I would like to work on this issue.
addaleax commentedon Nov 18, 2019
@thangktran Cool! This is quite C++-heavy, so it helps if youβre familiar with that. I would recommend starting by looking at
ArrayBuffer::New()calls in our C++ code insrc/, picking one that usesArrayBufferCreationMode::kInternalized(thatβs the easier case), and then trying to convert it to the newArrayBuffer::NewBackingStore()-based API.If you have any questions or need help getting started, feel free to comment here, or ask the
#node-devchannel on Freenode IRC (or to ping me there).thangktran commentedon Nov 18, 2019
@addaleax Thank you for your suggestion.
thangktran commentedon Nov 25, 2019
EDIT: I figured it out. I'll test it and keep you update.
thangktran commentedon Nov 30, 2019
There appears to be a bug in v8.
I've reported to them https://bugs.chromium.org/p/v8/issues/detail?id=9908
addaleax commentedon Nov 30, 2019
@thangktran Yeah, thanks for reporting that π