Skip to content

Commit 1a4e4e7

Browse files
committed
fix wasm64 test
1 parent 6b56760 commit 1a4e4e7

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

packages/emnapi/src/core/async-work.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,16 @@ export var napi_create_async_work = singleThreadAsyncWork
270270
$CHECK_ARG!(envObject, resource_name)
271271

272272
const sizeofAW = emnapiAWMT.offset.end
273-
const aw = _malloc(to64('sizeofAW'))
273+
let aw = _malloc(to64('sizeofAW') as size_t)
274274
if (!aw) return envObject.setLastError(napi_status.napi_generic_failure)
275-
new Uint8Array(wasmMemory.buffer).subarray(aw, aw + sizeofAW).fill(0)
275+
from64('aw')
276+
new Uint8Array(wasmMemory.buffer).subarray(aw as number, aw as number + sizeofAW).fill(0)
276277
const s = emnapiCtx.napiValueFromJsValue(resourceObject)
277278
const resourceRef = emnapiCtx.createReference(envObject, s, 1, ReferenceOwnership.kUserland as any)
278279

279280
const resource_ = resourceRef.id
280281
makeSetValue('aw', 0, 'resource_', '*')
281-
_emnapi_node_emit_async_init(s, resource_name, -1, aw + emnapiAWMT.offset.async_id)
282+
_emnapi_node_emit_async_init(s, resource_name, -1, aw as number + emnapiAWMT.offset.async_id)
282283
makeSetValue('aw', 'emnapiAWMT.offset.env', 'env', '*')
283284
makeSetValue('aw', 'emnapiAWMT.offset.execute', 'execute', '*')
284285
makeSetValue('aw', 'emnapiAWMT.offset.complete', 'complete', '*')

packages/emnapi/src/core/init.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export var wasmMemory: WebAssembly.Memory
4141

4242
export var wasmTable: WebAssembly.Table
4343

44-
export var _malloc: any
45-
export var _free: any
44+
export var _malloc: (size: size_t) => void_p
45+
export var _free: (ptr: void_p) => void
4646

4747
export function abort (msg?: string): never {
4848
if (typeof WebAssembly.RuntimeError === 'function') {
@@ -91,8 +91,8 @@ export var napiModule: INapiModule = {
9191
wasmTable = table
9292
if (typeof exports.malloc !== 'function') throw new TypeError('malloc is not exported')
9393
if (typeof exports.free !== 'function') throw new TypeError('free is not exported')
94-
_malloc = exports.malloc
95-
_free = exports.free
94+
_malloc = exports.malloc as (size: size_t) => void_p
95+
_free = exports.free as (ptr: void_p) => void
9696

9797
if (!napiModule.childThread) {
9898
// main thread only

packages/emnapi/src/memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const emnapiExternalMemory: {
9090
return info
9191
}
9292

93-
const pointer = _malloc(to64('arrayBuffer.byteLength'))
93+
let pointer = _malloc(to64('arrayBuffer.byteLength'))
9494
if (!pointer) throw new Error('Out of memory')
9595
from64('pointer')
9696
new Uint8Array(wasmMemory.buffer).set(new Uint8Array(arrayBuffer), pointer as number)

packages/emnapi/src/threadsafe-function.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const emnapiTSFN = {
8282
},
8383
initQueue (func: number): boolean {
8484
const size = 2 * POINTER_SIZE
85-
const queue = _malloc(to64('size'))
85+
let queue = _malloc(to64('size'))
8686
if (!queue) return false
8787
from64('queue')
8888
new Uint8Array(wasmMemory.buffer, queue as number, size).fill(0)
@@ -101,7 +101,7 @@ export const emnapiTSFN = {
101101
const tail = emnapiTSFN.loadSizeTypeValue(queue + POINTER_SIZE, false)
102102

103103
const size = 2 * POINTER_SIZE
104-
const node = _malloc(to64('size'))
104+
let node = _malloc(to64('size'))
105105
if (!node) throw new Error('OOM')
106106
from64('node')
107107
emnapiTSFN.storeSizeTypeValue(node as number, data, false)
@@ -705,7 +705,7 @@ export function napi_create_threadsafe_function (
705705

706706
// tsfn create
707707
const sizeofTSFN = emnapiTSFN.offset.end
708-
const tsfn = _malloc(to64('sizeofTSFN'))
708+
let tsfn = _malloc(to64('sizeofTSFN'))
709709
if (!tsfn) return envObject.setLastError(napi_status.napi_generic_failure)
710710
from64('tsfn')
711711
new Uint8Array(wasmMemory.buffer).subarray(tsfn as number, tsfn as number + sizeofTSFN).fill(0)

0 commit comments

Comments
 (0)