Skip to content

Commit

Permalink
fix: napi_is_buffer(Uint8Array) should return true (#129)
Browse files Browse the repository at this point in the history
* fix: napi_is_buffer(Uint8Array) should return `true`

* fix: napi_get_buffer_info should handle DataView
  • Loading branch information
toyobayashi authored Oct 12, 2024
1 parent df9dd83 commit 34e2a22
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/emnapi/src/value/convert2c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ export function napi_get_buffer_info (
$CHECK_ARG!(envObject, buffer)
const handle = emnapiCtx.handleStore.get(buffer)!
$RETURN_STATUS_IF_FALSE!(envObject, handle.isBuffer(emnapiCtx.feature.Buffer), napi_status.napi_invalid_arg)
if (handle.isDataView()) {
return napi_get_dataview_info(env, buffer, length, data, 0, 0)
}
return napi_get_typedarray_info(env, buffer, 0, length, data, 0, 0)
}

Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/Handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Handle<S> {
}

public isBuffer (BufferConstructor?: BufferCtor): boolean {
if (ArrayBuffer.isView(this.value)) return true
BufferConstructor ??= _Buffer
return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value)
}
Expand Down

0 comments on commit 34e2a22

Please sign in to comment.