Skip to content

Commit ff11322

Browse files
committed
fixup! ffi: clarify detached ArrayBuffer error
Report that the ArrayBuffer is detached instead of describing its backing store as invalid. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
1 parent c9143b7 commit ff11322

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎src/ffi/data.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ void ExportBytes(const FunctionCallbackInfo<Value>& args) {
685685
args[0]->IsArrayBufferView()) {
686686
view.ReadValue(args[0]);
687687
if (view.WasDetached()) {
688-
THROW_ERR_INVALID_ARG_VALUE(env, "Invalid ArrayBufferView backing store");
688+
THROW_ERR_INVALID_ARG_VALUE(env, "ArrayBuffer is detached");
689689
return;
690690
}
691691
} else {

‎test/ffi/test-ffi-memory.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ test('ffi rejects detached array buffers and views as pointers', () => {
153153

154154
structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
155155

156+
assert.throws(() => ffi.exportArrayBuffer(arrayBuffer, 0n, 0), {
157+
code: 'ERR_INVALID_ARG_VALUE',
158+
message: 'ArrayBuffer is detached',
159+
});
160+
156161
for (const [value, rawPointerMessage, argumentMessage] of [
157162
[
158163
arrayBuffer,

0 commit comments

Comments
 (0)