Skip to content

Commit 34e2a22

Browse files
authored
fix: napi_is_buffer(Uint8Array) should return true (#129)
* fix: napi_is_buffer(Uint8Array) should return `true` * fix: napi_get_buffer_info should handle DataView
1 parent df9dd83 commit 34e2a22

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

packages/emnapi/src/value/convert2c.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ export function napi_get_buffer_info (
166166
$CHECK_ARG!(envObject, buffer)
167167
const handle = emnapiCtx.handleStore.get(buffer)!
168168
$RETURN_STATUS_IF_FALSE!(envObject, handle.isBuffer(emnapiCtx.feature.Buffer), napi_status.napi_invalid_arg)
169+
if (handle.isDataView()) {
170+
return napi_get_dataview_info(env, buffer, length, data, 0, 0)
171+
}
169172
return napi_get_typedarray_info(env, buffer, 0, length, data, 0, 0)
170173
}
171174

packages/runtime/src/Handle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class Handle<S> {
4848
}
4949

5050
public isBuffer (BufferConstructor?: BufferCtor): boolean {
51+
if (ArrayBuffer.isView(this.value)) return true
5152
BufferConstructor ??= _Buffer
5253
return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value)
5354
}

0 commit comments

Comments
 (0)