-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
Remove the direct dependency on node::Environment (which is per-context) from node::ArrayBufferAllocator (which is per-isolate.) Contexts that want to toggle the zero fill flag, now do so through a field that is owned by ArrayBufferAllocator. Better, still not great. PR-URL: #7082 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,18 +59,16 @@ Buffer.prototype.swap32 = function swap32() { | |
return swap32n.apply(this); | ||
}; | ||
|
||
const flags = bindingObj.flags; | ||
const kNoZeroFill = 0; | ||
// |binding.zeroFill| can be undefined when running inside an isolate where we | ||
// do not own the ArrayBuffer allocator. Zero fill is always on in that case. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bnoordhuis
Author
Member
|
||
const zeroFill = bindingObj.zeroFill || [0]; | ||
|
||
function createBuffer(size, noZeroFill) { | ||
flags[kNoZeroFill] = noZeroFill ? 1 : 0; | ||
try { | ||
const ui8 = new Uint8Array(size); | ||
Object.setPrototypeOf(ui8, Buffer.prototype); | ||
return ui8; | ||
} finally { | ||
flags[kNoZeroFill] = 0; | ||
} | ||
if (noZeroFill) | ||
zeroFill[0] = 0; // Reset by the runtime. | ||
const ui8 = new Uint8Array(size); | ||
Object.setPrototypeOf(ui8, Buffer.prototype); | ||
return ui8; | ||
} | ||
|
||
function createPool() { | ||
|
@bnoordhuis If we wanted to run a test that exercised the right hand side of the
||
below, how would we do that? Like, what does it mean to "not own the ArrayBuffer allocator"? Is this a test that can be performed in JS-land or not so much? /cc @oogz