fix(napi): use create_buffer/arrary_buffer if provided data is empty
This commit is contained in:
parent
a41cc07f21
commit
5aa61c2142
6 changed files with 93 additions and 76 deletions
examples
|
@ -34,8 +34,12 @@ test('should create borrowed buffer with finalize', (t) => {
|
|||
})
|
||||
|
||||
test('should create empty borrowed buffer with finalize', (t) => {
|
||||
t.is(bindings.createEmptyBorrowedBufferWithFinalize().toString(), '')
|
||||
t.is(bindings.createEmptyBorrowedBufferWithFinalize().toString(), '')
|
||||
t.throws(() => bindings.createEmptyBorrowedBufferWithFinalize().toString(), {
|
||||
message: 'Borrowed data should not be null',
|
||||
})
|
||||
t.throws(() => bindings.createEmptyBorrowedBufferWithFinalize().toString(), {
|
||||
message: 'Borrowed data should not be null',
|
||||
})
|
||||
})
|
||||
|
||||
test('should create empty buffer', (t) => {
|
||||
|
|
|
@ -377,6 +377,16 @@ test('buffer', (t) => {
|
|||
t.is(b.toString(), '')
|
||||
})
|
||||
|
||||
test('reset empty buffer', (t) => {
|
||||
const empty = getEmptyBuffer()
|
||||
|
||||
const shared = new ArrayBuffer(0)
|
||||
const buffer = Buffer.from(shared)
|
||||
t.notThrows(() => {
|
||||
buffer.set(empty)
|
||||
})
|
||||
})
|
||||
|
||||
test('convert typedarray to vec', (t) => {
|
||||
const input = new Uint32Array([1, 2, 3, 4, 5])
|
||||
t.deepEqual(convertU32Array(input), Array.from(input))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue