Skip to content

Commit

Permalink
fix: respect user specified Buffer (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed May 14, 2024
1 parent 4304d7a commit b3f71d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/emnapi/src/value-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export function napi_is_buffer (env: napi_env, value: napi_value, result: Pointe
const h = emnapiCtx.handleStore.get(value)!
from64('result')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const r = h.isBuffer() ? 1 : 0
const r = h.isBuffer(emnapiCtx.feature.Buffer) ? 1 : 0
makeSetValue('result', 0, 'r', 'i8')
return envObject.clearLastError()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/emnapi/src/value/convert2c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function napi_get_buffer_info (
const envObject: Env = $CHECK_ENV_NOT_IN_GC!(env)
$CHECK_ARG!(envObject, buffer)
const handle = emnapiCtx.handleStore.get(buffer)!
$RETURN_STATUS_IF_FALSE!(envObject, handle.isBuffer(), napi_status.napi_invalid_arg)
$RETURN_STATUS_IF_FALSE!(envObject, handle.isBuffer(emnapiCtx.feature.Buffer), napi_status.napi_invalid_arg)
return napi_get_typedarray_info(env, buffer, 0, length, data, 0, 0)
}

Expand Down
5 changes: 3 additions & 2 deletions packages/runtime/src/Handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export class Handle<S> {
return (ArrayBuffer.isView(this.value)) && !(this.value instanceof DataView)
}

public isBuffer (): boolean {
return typeof _Buffer === 'function' && _Buffer.isBuffer(this.value)
public isBuffer (BufferConstructor?: BufferCtor): boolean {
BufferConstructor ??= _Buffer
return typeof BufferConstructor === 'function' && BufferConstructor.isBuffer(this.value)
}

public isDataView (): boolean {
Expand Down

0 comments on commit b3f71d2

Please sign in to comment.