Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrap napi_get_array_length and napi_get_prototype with PREAMBLE #83

Merged
merged 1 commit into from
Oct 4, 2023
Merged
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
65 changes: 32 additions & 33 deletions packages/emnapi/src/value/convert2c.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function napi_get_array_length (env: napi_env, value: napi_value, result: Pointer<uint32_t>): napi_status {
$CHECK_ENV!(env)
const envObject = emnapiCtx.envStore.get(env)!
$CHECK_ARG!(envObject, value)
$CHECK_ARG!(envObject, result)
const handle = emnapiCtx.handleStore.get(value)!
if (!handle.isArray()) {
return envObject.setLastError(napi_status.napi_array_expected)
}
$from64('result')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const v = handle.value.length >>> 0
$makeSetValue('result', 0, 'v', 'u32')
return envObject.clearLastError()
return $PREAMBLE!(env, (envObject) => {
$CHECK_ARG!(envObject, value)
$CHECK_ARG!(envObject, result)
const handle = emnapiCtx.handleStore.get(value)!
if (!handle.isArray()) {
return envObject.setLastError(napi_status.napi_array_expected)
}
$from64('result')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const v = handle.value.length >>> 0
$makeSetValue('result', 0, 'v', 'u32')
return envObject.getReturnStatus()
})
}

function napi_get_arraybuffer_info (env: napi_env, arraybuffer: napi_value, data: void_pp, byte_length: Pointer<size_t>): napi_status {
Expand All @@ -38,27 +38,26 @@ function napi_get_arraybuffer_info (env: napi_env, arraybuffer: napi_value, data
}

function napi_get_prototype (env: napi_env, value: napi_value, result: Pointer<napi_value>): napi_status {
$CHECK_ENV!(env)
const envObject = emnapiCtx.envStore.get(env)!
$CHECK_ARG!(envObject, value)
$CHECK_ARG!(envObject, result)
const handle = emnapiCtx.handleStore.get(value)!
if (handle.value == null) {
envObject.tryCatch.setError(new TypeError('Cannot convert undefined or null to object'))
return envObject.setLastError(napi_status.napi_pending_exception)
}
let v: any
try {
v = handle.isObject() || handle.isFunction() ? handle.value : Object(handle.value)
} catch (_) {
return envObject.setLastError(napi_status.napi_object_expected)
}
$from64('result')
return $PREAMBLE!(env, (envObject) => {
$CHECK_ARG!(envObject, value)
$CHECK_ARG!(envObject, result)
const handle = emnapiCtx.handleStore.get(value)!
if (handle.value == null) {
throw new TypeError('Cannot convert undefined or null to object')
}
let v: any
try {
v = handle.isObject() || handle.isFunction() ? handle.value : Object(handle.value)
} catch (_) {
return envObject.setLastError(napi_status.napi_object_expected)
}
$from64('result')

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const p = envObject.ensureHandleId(Object.getPrototypeOf(v))
$makeSetValue('result', 0, 'p', '*')
return envObject.clearLastError()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const p = envObject.ensureHandleId(Object.getPrototypeOf(v))
$makeSetValue('result', 0, 'p', '*')
return envObject.getReturnStatus()
})
}

function _napi_get_typedarray_info (
Expand Down