Skip to content

Commit

Permalink
fix napi_get_value_string_utf8 size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Dec 5, 2021
1 parent a11547a commit 3e731f3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/typings/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare function UTF8ToString (ptr: const_char_p, maxRead?: number): string
declare function UTF16ToString (ptr: const_char16_t_p, maxRead?: number): string
declare function stringToUTF8 (ptr: string, outPtr: char_p, maxBytesToWrite?: number): number
declare function stringToUTF16 (ptr: string, outPtr: char16_t_p, maxBytesToWrite?: number): number
declare function lengthBytesUTF8 (str: string): number

declare const Module: any

Expand Down
5 changes: 1 addition & 4 deletions lib/value/convert2c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,7 @@ function napi_get_value_string_utf8 (env: napi_env, value: napi_value, buf: char
}
if (buf === emnapi.NULL) {
if (result === emnapi.NULL) return emnapi.napi_set_last_error(env, emnapi.napi_status.napi_invalid_arg)
const stackPtrSize = handle.value.length * 3
const stackPtr = stackAlloc(stackPtrSize)
const copied = stringToUTF8(handle.value, stackPtr, stackPtrSize)
HEAPU32[result >> 2] = copied
HEAPU32[result >> 2] = lengthBytesUTF8(handle.value)
} else if (buf_size !== 0) {
const copied = stringToUTF8(handle.value, buf, buf_size)
if (result !== emnapi.NULL) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tybys/emnapi",
"version": "0.6.0",
"version": "0.6.1",
"description": "Node-API implementation for Emscripten",
"main": "index.js",
"typings": "index.d.ts",
Expand Down

0 comments on commit 3e731f3

Please sign in to comment.