Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ffi/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ void ExportBytes(const FunctionCallbackInfo<Value>& args) {
args[0]->IsArrayBufferView()) {
view.ReadValue(args[0]);
if (view.WasDetached()) {
THROW_ERR_INVALID_ARG_VALUE(env, "Invalid ArrayBufferView backing store");
THROW_ERR_INVALID_ARG_VALUE(env, "ArrayBuffer is detached");
return;
}
} else {
Expand Down
6 changes: 6 additions & 0 deletions test/ffi/test-ffi-memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ test('ffi validates memory access arguments', () => {
assert.throws(() => ffi.exportArrayBufferView('bad', ptr, 4), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => ffi.exportArrayBufferView(new Uint8Array([1]), ptr, -1), { code: 'ERR_OUT_OF_RANGE' });
assert.throws(() => ffi.exportArrayBufferView(new Uint8Array([1, 2]), ptr, 1), { code: 'ERR_OUT_OF_RANGE' });
const detachedArrayBuffer = new ArrayBuffer(2);
structuredClone(detachedArrayBuffer, { transfer: [detachedArrayBuffer] });
assert.throws(() => ffi.exportArrayBuffer(detachedArrayBuffer, ptr, 2), {
code: 'ERR_INVALID_ARG_VALUE',
message: /ArrayBuffer is detached/,
});
assert.throws(() => ffi.toBuffer(maxPointer, 8), /pointer and length exceed the platform address range/);
assert.throws(() => ffi.toArrayBuffer(maxPointer, 8), /pointer and length exceed the platform address range/);
assert.throws(() => ffi.toBuffer(1n, bufferConstants.MAX_LENGTH + 1), { code: 'ERR_BUFFER_TOO_LARGE' });
Expand Down
Loading