@emnapi/core
Advanced tools
@@ -166,2 +166,11 @@ import type { Context } from '@emnapi/runtime'; | ||
| emnapi: { | ||
| /** | ||
| * Synchronize data between the wasm memory and an ArrayBuffer / view. | ||
| * | ||
| * Note: when a non-shared wasm memory has grown, a view over the | ||
| * detached old buffer is re-created over the current buffer through the | ||
| * intrinsic base-class constructor, so for view inputs the returned view | ||
| * may be a base-class instance (e.g. `Uint8Array` or `DataView`) | ||
| * instead of the subclass that was passed in. | ||
| */ | ||
| syncMemory<T extends ArrayBuffer | ArrayBufferView> ( | ||
@@ -172,3 +181,3 @@ js_to_wasm: boolean, | ||
| len?: number | ||
| ): T | ||
| ): T extends ArrayBufferView ? ArrayBufferView : T | ||
| getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo | ||
@@ -175,0 +184,0 @@ addSendListener (worker: any): boolean |
@@ -166,2 +166,11 @@ import type { Context } from '@emnapi/runtime'; | ||
| emnapi: { | ||
| /** | ||
| * Synchronize data between the wasm memory and an ArrayBuffer / view. | ||
| * | ||
| * Note: when a non-shared wasm memory has grown, a view over the | ||
| * detached old buffer is re-created over the current buffer through the | ||
| * intrinsic base-class constructor, so for view inputs the returned view | ||
| * may be a base-class instance (e.g. `Uint8Array` or `DataView`) | ||
| * instead of the subclass that was passed in. | ||
| */ | ||
| syncMemory<T extends ArrayBuffer | ArrayBufferView> ( | ||
@@ -172,3 +181,3 @@ js_to_wasm: boolean, | ||
| len?: number | ||
| ): T | ||
| ): T extends ArrayBufferView ? ArrayBufferView : T | ||
| getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo | ||
@@ -175,0 +184,0 @@ addSendListener (worker: any): boolean |
@@ -198,2 +198,17 @@ //#region src/emnapi/async-work.js | ||
| }, | ||
| /** | ||
| * When another thread grows the shared WebAssembly.Memory, this agent's | ||
| * cached `wasmMemory.buffer` may still have the old shorter length | ||
| * (V8 refreshes it lazily). If a pointer derived from shared memory lies | ||
| * beyond the cached length, `wasmMemory.grow(0)` forces the agent to | ||
| * observe the current memory size and refreshes the buffer. | ||
| */ | ||
| ensureBufferFor(end) { | ||
| let buffer = emscripten_runtime.wasmMemory.buffer; | ||
| if (end > buffer.byteLength) { | ||
| emscripten_runtime.wasmMemory.grow(0); | ||
| buffer = emscripten_runtime.wasmMemory.buffer; | ||
| } | ||
| return buffer; | ||
| }, | ||
| init() { | ||
@@ -253,3 +268,3 @@ emnapiAWMT.pool = []; | ||
| const addr = emnapiAWMT.globalAddress; | ||
| new Uint8Array(emscripten_runtime.wasmMemory.buffer, addr, size).fill(0); | ||
| new Uint8Array(emnapiAWMT.ensureBufferFor(addr + size), addr, size).fill(0); | ||
| emnapiAWMT.queueInit(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.q); | ||
@@ -293,4 +308,4 @@ emnapiAWMT.queueInit(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.exit_message); | ||
| index >>>= 0; | ||
| const view = new DataView(emscripten_runtime.wasmMemory.buffer); | ||
| const tidOffset = 20; | ||
| const view = new DataView(emnapiAWMT.ensureBufferFor(index + tidOffset + 4)); | ||
| const tid = view.getInt32(index + tidOffset, true); | ||
@@ -304,20 +319,25 @@ worker = emscripten_runtime.PThread.pthreads[tid]; | ||
| getResource(work) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| return HEAP_DATA_VIEW.getUint32(work + emnapiAWMT.offset.resource, true); | ||
| emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.resource + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.resource, true); | ||
| }, | ||
| getExecute(work) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| return HEAP_DATA_VIEW.getUint32(work + emnapiAWMT.offset.execute, true); | ||
| emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.execute + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.execute, true); | ||
| }, | ||
| getComplete(work) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| return HEAP_DATA_VIEW.getUint32(work + emnapiAWMT.offset.complete, true); | ||
| emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.complete + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.complete, true); | ||
| }, | ||
| getEnv(work) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| return HEAP_DATA_VIEW.getUint32(work + emnapiAWMT.offset.env, true); | ||
| emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.env + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.env, true); | ||
| }, | ||
| getData(work) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| return HEAP_DATA_VIEW.getUint32(work + emnapiAWMT.offset.data, true); | ||
| emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.data + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.data, true); | ||
| }, | ||
@@ -329,3 +349,3 @@ getMutex() { | ||
| const isBrowserMain = typeof window !== 'undefined' && typeof document !== 'undefined' && !emscripten_runtime.ENVIRONMENT_IS_NODE; | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1); | ||
| if (isBrowserMain) { | ||
@@ -350,3 +370,3 @@ while (true) { | ||
| unlock() { | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1); | ||
| const oldValue = Atomics.compareExchange(i32a, 0, 10, 0); | ||
@@ -375,3 +395,3 @@ if (oldValue !== 10) { | ||
| wait() { | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1); | ||
| const value = Atomics.load(i32a, 0); | ||
@@ -383,3 +403,3 @@ mutex.unlock(); | ||
| signal() { | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1); | ||
| Atomics.add(i32a, 0, 1); | ||
@@ -392,26 +412,31 @@ Atomics.notify(i32a, 0, 1); | ||
| queueInit(q) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setUint32(q, q, true); | ||
| HEAP_DATA_VIEW.setUint32(q + 4, q, true); | ||
| emnapiAWMT.ensureBufferFor(q + 4 + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setUint32(q, q, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(q + 4, q, true); | ||
| }, | ||
| queueInsertTail(h, q) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setUint32(q, h, true); | ||
| const tempValue = HEAP_DATA_VIEW.getUint32(h + 4, true); | ||
| HEAP_DATA_VIEW.setUint32(q + 4, tempValue, true); | ||
| const qprev = HEAP_DATA_VIEW.getUint32(q + 4, true); | ||
| HEAP_DATA_VIEW.setUint32(qprev, q, true); | ||
| HEAP_DATA_VIEW.setUint32(h + 4, q, true); | ||
| emnapiAWMT.ensureBufferFor(h + 4 + 4); | ||
| emnapiAWMT.ensureBufferFor(q + 4 + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setUint32(q, h, true); | ||
| const tempValue = GET_HEAP_DATA_VIEW().getUint32(h + 4, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(q + 4, tempValue, true); | ||
| const qprev = GET_HEAP_DATA_VIEW().getUint32(q + 4, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(qprev, q, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(h + 4, q, true); | ||
| }, | ||
| queueRemove(q) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| const qprev = HEAP_DATA_VIEW.getUint32(q + 4, true); | ||
| const qnext = HEAP_DATA_VIEW.getUint32(q, true); | ||
| HEAP_DATA_VIEW.setUint32(qprev, qnext, true); | ||
| HEAP_DATA_VIEW.setUint32(qnext + 4, qprev, true); | ||
| emnapiAWMT.ensureBufferFor(q + 4 + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| const qprev = GET_HEAP_DATA_VIEW().getUint32(q + 4, true); | ||
| const qnext = GET_HEAP_DATA_VIEW().getUint32(q, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(qprev, qnext, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(qnext + 4, qprev, true); | ||
| }, | ||
| queueEmpty(q) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| emnapiAWMT.ensureBufferFor(q + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| // eslint-disable-next-line eqeqeq | ||
| return q == HEAP_DATA_VIEW.getUint32(q, true); | ||
| return q == GET_HEAP_DATA_VIEW().getUint32(q, true); | ||
| }, | ||
@@ -429,3 +454,3 @@ scheduleWork: function (work) { | ||
| emnapiCtx.increaseWaitingRequestCounter(); | ||
| const statusBuffer = new Int32Array(emscripten_runtime.wasmMemory.buffer, work + emnapiAWMT.offset.status, 1); | ||
| const statusBuffer = new Int32Array(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4), work + emnapiAWMT.offset.status, 1); | ||
| Atomics.store(statusBuffer, 0, 0 /* AsyncWorkStatus.Pending */); | ||
@@ -444,4 +469,5 @@ const mutex = emnapiAWMT.getMutex(); | ||
| } | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| if (HEAP_DATA_VIEW.getUint32(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.idle_threads, true) > 0) { | ||
| emnapiAWMT.ensureBufferFor(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.idle_threads + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| if (GET_HEAP_DATA_VIEW().getUint32(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.idle_threads, true) > 0) { | ||
| cond.signal(); | ||
@@ -454,4 +480,5 @@ } | ||
| emnapiAWMT.getMutex().execute(() => { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| cancelled = !emnapiAWMT.queueEmpty(work + emnapiAWMT.offset.queue) && HEAP_DATA_VIEW.getInt32(work + emnapiAWMT.offset.status, true) !== 2 /* AsyncWorkStatus.Completed */; | ||
| emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| cancelled = !emnapiAWMT.queueEmpty(work + emnapiAWMT.offset.queue) && GET_HEAP_DATA_VIEW().getInt32(work + emnapiAWMT.offset.status, true) !== 2 /* AsyncWorkStatus.Completed */; | ||
| if (cancelled) { | ||
@@ -464,3 +491,3 @@ emnapiAWMT.queueRemove(work + emnapiAWMT.offset.queue); | ||
| } | ||
| if (Atomics.compareExchange(new Int32Array(emscripten_runtime.wasmMemory.buffer, work + emnapiAWMT.offset.status, 1), 0, 0 /* AsyncWorkStatus.Pending */, 1 /* AsyncWorkStatus.Cancelled */) !== 0 /* AsyncWorkStatus.Pending */) { | ||
| if (Atomics.compareExchange(new Int32Array(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4), work + emnapiAWMT.offset.status, 1), 0, 0 /* AsyncWorkStatus.Pending */, 1 /* AsyncWorkStatus.Cancelled */) !== 0 /* AsyncWorkStatus.Pending */) { | ||
| return 9 /* napi_status.napi_generic_failure */; | ||
@@ -493,3 +520,3 @@ } | ||
| const resourceObject = emnapiCtx.jsValueFromNapiValue(resource_value); | ||
| const view = new DataView(emscripten_runtime.wasmMemory.buffer); | ||
| const view = new DataView(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.trigger_async_id + 8)); | ||
| const asyncId = view.getFloat64(work + emnapiAWMT.offset.async_id, true); | ||
@@ -537,4 +564,4 @@ const triggerAsyncId = view.getFloat64(work + emnapiAWMT.offset.trigger_async_id, true); | ||
| result >>>= 0; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setUint32(result, id, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setUint32(result, id, true); | ||
| return envObject.clearLastError(); | ||
@@ -566,16 +593,16 @@ } | ||
| aw >>>= 0; | ||
| new Uint8Array(emscripten_runtime.wasmMemory.buffer).subarray(aw, aw + sizeofAW).fill(0); | ||
| new Uint8Array(emnapiAWMT.ensureBufferFor(aw + sizeofAW)).subarray(aw, aw + sizeofAW).fill(0); | ||
| const s = emnapiCtx.napiValueFromJsValue(resourceObject); | ||
| const resourceRef = emnapiCtx.createReference(envObject, s, 1, 1 /* ReferenceOwnership.kUserland */); | ||
| const resource_ = resourceRef.id; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setUint32(aw, resource_, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setUint32(aw, resource_, true); | ||
| _emnapi_node_emit_async_init(s, resource_name, -1, aw + emnapiAWMT.offset.async_id); | ||
| HEAP_DATA_VIEW.setUint32(aw + emnapiAWMT.offset.env, env, true); | ||
| HEAP_DATA_VIEW.setUint32(aw + emnapiAWMT.offset.execute, execute, true); | ||
| HEAP_DATA_VIEW.setUint32(aw + emnapiAWMT.offset.complete, complete, true); | ||
| HEAP_DATA_VIEW.setUint32(aw + emnapiAWMT.offset.data, data, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.env, env, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.execute, execute, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.complete, complete, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.data, data, true); | ||
| emnapiAWMT.queueInit(aw + emnapiAWMT.offset.queue); | ||
| result >>>= 0; | ||
| HEAP_DATA_VIEW.setUint32(result, aw, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(result, aw, true); | ||
| return envObject.clearLastError(); | ||
@@ -609,3 +636,3 @@ }; | ||
| if (emnapiNodeBinding) { | ||
| const view = new DataView(emscripten_runtime.wasmMemory.buffer); | ||
| const view = new DataView(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.trigger_async_id + 8)); | ||
| const asyncId = view.getFloat64(work + emnapiAWMT.offset.async_id, true); | ||
@@ -676,10 +703,11 @@ const triggerAsyncId = view.getFloat64(work + emnapiAWMT.offset.trigger_async_id, true); | ||
| const workerQueueAddr = globalAddress + emnapiAWMT.globalOffset.q; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| for (;;) { | ||
| emnapiAWMT.ensureBufferFor(workerQueueAddr + 4); | ||
| while (emnapiAWMT.queueEmpty(workerQueueAddr)) { | ||
| Atomics.add(new Int32Array(emscripten_runtime.wasmMemory.buffer, idleThreadsAddr, 1), 0, 1); | ||
| Atomics.add(new Int32Array(emnapiAWMT.ensureBufferFor(idleThreadsAddr + 4), idleThreadsAddr, 1), 0, 1); | ||
| cond.wait(); | ||
| Atomics.sub(new Int32Array(emscripten_runtime.wasmMemory.buffer, idleThreadsAddr, 1), 0, 1); | ||
| Atomics.sub(new Int32Array(emnapiAWMT.ensureBufferFor(idleThreadsAddr + 4), idleThreadsAddr, 1), 0, 1); | ||
| } | ||
| const q = HEAP_DATA_VIEW.getUint32(workerQueueAddr, true); | ||
| const q = GET_HEAP_DATA_VIEW().getUint32(workerQueueAddr, true); | ||
| if (q === exitMessageAddr) { | ||
@@ -694,3 +722,3 @@ cond.signal(); | ||
| mutex.unlock(); | ||
| const statusBuffer = new Int32Array(emscripten_runtime.wasmMemory.buffer, work + emnapiAWMT.offset.status, 1); | ||
| const statusBuffer = new Int32Array(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4), work + emnapiAWMT.offset.status, 1); | ||
| if (Atomics.load(statusBuffer, 0) === 1 /* AsyncWorkStatus.Cancelled */) { | ||
@@ -697,0 +725,0 @@ emscripten_runtime.abort('unreachable'); |
@@ -103,3 +103,3 @@ //#region src/emnapi/threadsafe-function.js | ||
| const pendng = payload.tsfn + emnapiTSFN.offset.async_pending; | ||
| if (Atomics.load(new Int32Array(emscripten_runtime.wasmMemory.buffer), pendng >>> 2) !== 0) { | ||
| if (Atomics.load(new Int32Array(emnapiTSFN.ensureBufferFor(pendng + 4)), pendng >>> 2) !== 0) { | ||
| emnapiTSFN.enqueue(payload.tsfn); | ||
@@ -128,2 +128,17 @@ } | ||
| }, | ||
| /** | ||
| * When another thread grows the shared WebAssembly.Memory, this agent's | ||
| * cached `wasmMemory.buffer` may still have the old shorter length | ||
| * (V8 refreshes it lazily). If a pointer derived from shared memory lies | ||
| * beyond the cached length, `wasmMemory.grow(0)` forces the agent to | ||
| * observe the current memory size and refreshes the buffer. | ||
| */ | ||
| ensureBufferFor(end) { | ||
| let buffer = emscripten_runtime.wasmMemory.buffer; | ||
| if (end > buffer.byteLength) { | ||
| emscripten_runtime.wasmMemory.grow(0); | ||
| buffer = emscripten_runtime.wasmMemory.buffer; | ||
| } | ||
| return buffer; | ||
| }, | ||
| initQueue(func) { | ||
@@ -135,3 +150,3 @@ const size = 2 * 4; | ||
| queue >>>= 0; | ||
| new Uint8Array(emscripten_runtime.wasmMemory.buffer, queue, size).fill(0); | ||
| new Uint8Array(emnapiTSFN.ensureBufferFor(queue + size), queue, size).fill(0); | ||
| emnapiTSFN.storeSizeTypeValue(func + emnapiTSFN.offset.queue, queue, false); | ||
@@ -242,3 +257,3 @@ return true; | ||
| const isBrowserMain = typeof window !== 'undefined' && typeof document !== 'undefined' && !emscripten_runtime.ENVIRONMENT_IS_NODE; | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1); | ||
| if (isBrowserMain) { | ||
@@ -266,3 +281,3 @@ while (true) { | ||
| const fn = (): void => { | ||
| const i32a = new Int32Array(wasmMemory.buffer, index, 1) | ||
| const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1) | ||
| const oldValue = Atomics.compareExchange(i32a, 0, 0, 10) | ||
@@ -279,3 +294,3 @@ if (oldValue === 0) { | ||
| unlock() { | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1); | ||
| const oldValue = Atomics.compareExchange(i32a, 0, 10, 0); | ||
@@ -314,3 +329,3 @@ if (oldValue !== 10) { | ||
| wait() { | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1); | ||
| const value = Atomics.load(i32a, 0); | ||
@@ -322,3 +337,3 @@ mutex.unlock(); | ||
| /* waitAsync () { | ||
| const i32a = new Int32Array(wasmMemory.buffer, index, 1) | ||
| const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1) | ||
| const value = Atomics.load(i32a, 0) | ||
@@ -334,3 +349,3 @@ mutex.unlock() | ||
| signal() { | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer, index, 1); | ||
| const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1); | ||
| Atomics.add(i32a, 0, 1); | ||
@@ -348,3 +363,3 @@ Atomics.notify(i32a, 0, 1); | ||
| let arr, index; | ||
| arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4)); | ||
| index = (func + offset) >>> 2; | ||
@@ -356,3 +371,3 @@ Atomics.add(arr, index, 1); | ||
| let arr, index; | ||
| arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4)); | ||
| index = (func + offset) >>> 2; | ||
@@ -367,3 +382,3 @@ Atomics.sub(arr, index, 1); | ||
| let arr, index; | ||
| arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4)); | ||
| index = (func + offset) >>> 2; | ||
@@ -375,3 +390,3 @@ Atomics.add(arr, index, 1); | ||
| let arr, index; | ||
| arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4)); | ||
| index = (func + offset) >>> 2; | ||
@@ -381,15 +396,15 @@ Atomics.sub(arr, index, 1); | ||
| getState(func) { | ||
| return Atomics.load(new Int32Array(emscripten_runtime.wasmMemory.buffer), (func + emnapiTSFN.offset.state) >>> 2); | ||
| return Atomics.load(new Int32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.state + 4)), (func + emnapiTSFN.offset.state) >>> 2); | ||
| }, | ||
| setState(func, value) { | ||
| Atomics.store(new Int32Array(emscripten_runtime.wasmMemory.buffer), (func + emnapiTSFN.offset.state) >>> 2, value); | ||
| Atomics.store(new Int32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.state + 4)), (func + emnapiTSFN.offset.state) >>> 2, value); | ||
| }, | ||
| getHandlesClosing(func) { | ||
| return Atomics.load(new Int8Array(emscripten_runtime.wasmMemory.buffer), (func + emnapiTSFN.offset.handles_closing)); | ||
| return Atomics.load(new Int8Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.handles_closing + 1)), (func + emnapiTSFN.offset.handles_closing)); | ||
| }, | ||
| setHandlesClosing(func, value) { | ||
| Atomics.store(new Int8Array(emscripten_runtime.wasmMemory.buffer), (func + emnapiTSFN.offset.handles_closing), value); | ||
| Atomics.store(new Int8Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.handles_closing + 1)), (func + emnapiTSFN.offset.handles_closing), value); | ||
| }, | ||
| getDispatchState(func) { | ||
| return Atomics.load(new Uint32Array(emscripten_runtime.wasmMemory.buffer), (func + emnapiTSFN.offset.dispatch_state) >>> 2); | ||
| return Atomics.load(new Uint32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.dispatch_state + 4)), (func + emnapiTSFN.offset.dispatch_state) >>> 2); | ||
| }, | ||
@@ -424,3 +439,3 @@ getContext(func) { | ||
| if (unsigned) { | ||
| arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Uint32Array(emnapiTSFN.ensureBufferFor(offset + 4)); | ||
| ret = Atomics.load(arr, offset >>> 2); | ||
@@ -430,3 +445,3 @@ return ret; | ||
| else { | ||
| arr = new Int32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Int32Array(emnapiTSFN.ensureBufferFor(offset + 4)); | ||
| ret = Atomics.load(arr, offset >>> 2); | ||
@@ -439,3 +454,3 @@ return ret; | ||
| if (unsigned) { | ||
| arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Uint32Array(emnapiTSFN.ensureBufferFor(offset + 4)); | ||
| Atomics.store(arr, offset >>> 2, value); | ||
@@ -445,3 +460,3 @@ return undefined; | ||
| else { | ||
| arr = new Int32Array(emscripten_runtime.wasmMemory.buffer); | ||
| arr = new Int32Array(emnapiTSFN.ensureBufferFor(offset + 4)); | ||
| Atomics.store(arr, offset >>> 2, value >>> 0); | ||
@@ -462,8 +477,10 @@ return undefined; | ||
| emnapiCtx.getRef(resource).dispose(); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setInt8(func + emnapiTSFN.offset.is_some, 0, true); | ||
| emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.is_some + 1); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setInt8(func + emnapiTSFN.offset.is_some, 0, true); | ||
| emnapiCtx.removeCleanupHook(envObject, emnapiTSFN.cleanup, func); | ||
| envObject.unref(); | ||
| const asyncRefOffset = (func + emnapiTSFN.offset.async_ref) >>> 2; | ||
| const arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| const asyncRefAddress = func + emnapiTSFN.offset.async_ref; | ||
| const asyncRefOffset = asyncRefAddress >>> 2; | ||
| const arr = new Uint32Array(emnapiTSFN.ensureBufferFor(asyncRefAddress + 4)); | ||
| if (Atomics.load(arr, asyncRefOffset) > 0) { | ||
@@ -475,3 +492,3 @@ Atomics.store(arr, asyncRefOffset, 0); | ||
| if (emnapiNodeBinding) { | ||
| const view = new DataView(emscripten_runtime.wasmMemory.buffer); | ||
| const view = new DataView(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.trigger_async_id + 8)); | ||
| const asyncId = view.getFloat64(func + emnapiTSFN.offset.async_id, true); | ||
@@ -537,3 +554,3 @@ const triggerAsyncId = view.getFloat64(func + emnapiTSFN.offset.trigger_async_id, true); | ||
| const resourceObject = emnapiCtx.jsValueFromNapiValue(resource_value); | ||
| const view = new DataView(emscripten_runtime.wasmMemory.buffer); | ||
| const view = new DataView(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.trigger_async_id + 8)); | ||
| const asyncId = view.getFloat64(func + emnapiTSFN.offset.async_id, true); | ||
@@ -576,3 +593,3 @@ const triggerAsyncId = view.getFloat64(func + emnapiTSFN.offset.trigger_async_id, true); | ||
| emnapiTSFN.setHandlesClosing(func, 1); | ||
| Atomics.store(new Int32Array(emscripten_runtime.wasmMemory.buffer), (func + emnapiTSFN.offset.async_pending) >>> 2, 1); | ||
| Atomics.store(new Int32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.async_pending + 4)), (func + emnapiTSFN.offset.async_pending) >>> 2, 1); | ||
| emnapiCtx.features.setImmediate(() => { | ||
@@ -647,3 +664,3 @@ emnapiTSFN.finalize(func); | ||
| const resourceObject = emnapiCtx.jsValueFromNapiValue(resource_value); | ||
| const view = new DataView(emscripten_runtime.wasmMemory.buffer); | ||
| const view = new DataView(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.trigger_async_id + 8)); | ||
| emnapiNodeBinding.node.makeCallback(resourceObject, f, [], { | ||
@@ -667,8 +684,20 @@ asyncId: view.getFloat64(func + emnapiTSFN.offset.async_id, true), | ||
| let iterations_left = 1000; | ||
| const ui32a = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| const index = (func + emnapiTSFN.offset.dispatch_state) >>> 2; | ||
| const dispatchStateAddress = func + emnapiTSFN.offset.dispatch_state; | ||
| const index = dispatchStateAddress >>> 2; | ||
| while (has_more && --iterations_left !== 0) { | ||
| Atomics.store(ui32a, index, 1); | ||
| has_more = emnapiTSFN.dispatchOne(func); | ||
| if (Atomics.exchange(ui32a, index, 0) !== 1) { | ||
| Atomics.store(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), index, 1); | ||
| try { | ||
| has_more = emnapiTSFN.dispatchOne(func); | ||
| } | ||
| catch (err) { | ||
| // A throwing callback must not leave dispatch_state marked as | ||
| // dispatching, or every later send() would be swallowed. Re-arm | ||
| // the state and schedule another drain before rethrowing. | ||
| if (emnapiTSFN._liveSet.has(func)) { | ||
| Atomics.exchange(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), index, 0); | ||
| emnapiTSFN.send(func); | ||
| } | ||
| throw err; | ||
| } | ||
| if (Atomics.exchange(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), index, 0) !== 1) { | ||
| has_more = true; | ||
@@ -688,4 +717,5 @@ } | ||
| const scheduled = func + emnapiTSFN.offset.async_u_fd; | ||
| const i32a = new Int32Array(emscripten_runtime.wasmMemory.buffer); | ||
| if (Atomics.exchange(i32a, scheduled >>> 2, 1) !== 0) { | ||
| const end = Math.max(pending, scheduled) + 4; | ||
| const state = () => new Int32Array(emnapiTSFN.ensureBufferFor(end)); | ||
| if (Atomics.exchange(state(), scheduled >>> 2, 1) !== 0) { | ||
| return; | ||
@@ -701,18 +731,19 @@ } | ||
| } | ||
| if (Atomics.load(i32a, pending >>> 2) === 0) { | ||
| Atomics.store(i32a, scheduled >>> 2, 0); | ||
| if (Atomics.load(state(), pending >>> 2) === 0) { | ||
| Atomics.store(state(), scheduled >>> 2, 0); | ||
| return; | ||
| } | ||
| emnapiCtx.features.setImmediate(() => { | ||
| // After destroy(), the func address is freed. Skip the atomics | ||
| // on that address entirely to avoid use-after-free (JS-side | ||
| // lifecycle check must run before touching the state words). | ||
| if (!emnapiTSFN._liveSet.has(func)) { | ||
| return; | ||
| } | ||
| try { | ||
| // Consume the coalesced wakeup once, then let dispatch() observe any | ||
| // queue mutations through dispatch_state like the C implementation. | ||
| if (Atomics.exchange(i32a, pending >>> 2, 0) === 0) { | ||
| if (Atomics.exchange(state(), pending >>> 2, 0) === 0) { | ||
| return; | ||
| } | ||
| // After destroy(), the func address is freed. Skip dispatch | ||
| // to avoid use-after-free (JS-side lifecycle check). | ||
| if (!emnapiTSFN._liveSet.has(func)) { | ||
| return; | ||
| } | ||
| emnapiTSFN.dispatch(func); | ||
@@ -724,4 +755,4 @@ } | ||
| if (emnapiTSFN._liveSet.has(func)) { | ||
| Atomics.store(i32a, scheduled >>> 2, 0); | ||
| if (Atomics.load(i32a, pending >>> 2) !== 0) { | ||
| Atomics.store(state(), scheduled >>> 2, 0); | ||
| if (Atomics.load(state(), pending >>> 2) !== 0) { | ||
| emnapiTSFN.enqueue(func); | ||
@@ -735,3 +766,4 @@ } | ||
| send(func) { | ||
| const current_state = Atomics.or(new Uint32Array(emscripten_runtime.wasmMemory.buffer), (func + emnapiTSFN.offset.dispatch_state) >>> 2, 1 << 1); | ||
| const dispatchStateAddress = func + emnapiTSFN.offset.dispatch_state; | ||
| const current_state = Atomics.or(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), dispatchStateAddress >>> 2, 1 << 1); | ||
| if ((current_state & 1) === 1) { | ||
@@ -743,6 +775,6 @@ return; | ||
| // work in the TSFN queue and let the existing drain pick it up. | ||
| if (Atomics.load(new Int32Array(emscripten_runtime.wasmMemory.buffer), pendng >>> 2) !== 0) { | ||
| if (Atomics.load(new Int32Array(emnapiTSFN.ensureBufferFor(pendng + 4)), pendng >>> 2) !== 0) { | ||
| return; | ||
| } | ||
| if (Atomics.exchange(new Int32Array(emscripten_runtime.wasmMemory.buffer), pendng >>> 2, 1) === 0) { | ||
| if (Atomics.exchange(new Int32Array(emnapiTSFN.ensureBufferFor(pendng + 4)), pendng >>> 2, 1) === 0) { | ||
| if ((typeof emscripten_runtime.ENVIRONMENT_IS_PTHREAD !== 'undefined') && emscripten_runtime.ENVIRONMENT_IS_PTHREAD) { | ||
@@ -834,7 +866,7 @@ // Worker threads only post a wakeup token. Main-thread draining is | ||
| tsfn >>>= 0; | ||
| new Uint8Array(emscripten_runtime.wasmMemory.buffer).subarray(tsfn, tsfn + sizeofTSFN).fill(0); | ||
| new Uint8Array(emnapiTSFN.ensureBufferFor(tsfn + sizeofTSFN)).subarray(tsfn, tsfn + sizeofTSFN).fill(0); | ||
| const resourceRef = emnapiCtx.createReference(envObject, resource, 1, 1 /* ReferenceOwnership.kUserland */); | ||
| const resource_ = resourceRef.id; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.resource, resource_, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.resource, resource_, true); | ||
| if (!emnapiTSFN.initQueue(tsfn)) { | ||
@@ -846,11 +878,11 @@ emscripten_runtime._free(tsfn); | ||
| __emnapi_node_emit_async_init(resource, resource_name, -1, tsfn + emnapiTSFN.offset.async_id); | ||
| HEAP_DATA_VIEW.setInt8(tsfn + emnapiTSFN.offset.is_some, 1, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.thread_count, initial_thread_count, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.context, context, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.max_queue_size, max_queue_size, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.ref, ref, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.env, env, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.finalize_data, thread_finalize_data, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.finalize_cb, thread_finalize_cb, true); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.call_js_cb, call_js_cb, true); | ||
| GET_HEAP_DATA_VIEW().setInt8(tsfn + emnapiTSFN.offset.is_some, 1, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.thread_count, initial_thread_count, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.context, context, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.max_queue_size, max_queue_size, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.ref, ref, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.env, env, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.finalize_data, thread_finalize_data, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.finalize_cb, thread_finalize_cb, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.call_js_cb, call_js_cb, true); | ||
| emnapiCtx.addCleanupHook(envObject, emnapiTSFN.cleanup, tsfn); | ||
@@ -861,5 +893,5 @@ emnapiTSFN._liveSet.add(tsfn); | ||
| emnapiCtx.increaseWaitingRequestCounter(); | ||
| HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.async_ref, 1, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.async_ref, 1, true); | ||
| result >>>= 0; | ||
| HEAP_DATA_VIEW.setUint32(result, tsfn, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(result, tsfn, true); | ||
| return envObject.clearLastError(); | ||
@@ -876,4 +908,4 @@ } | ||
| const context = emnapiTSFN.getContext(func); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setUint32(result, context, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setUint32(result, context, true); | ||
| return 0 /* napi_status.napi_ok */; | ||
@@ -954,4 +986,5 @@ } | ||
| func >>>= 0; | ||
| const asyncRefOffset = (func + emnapiTSFN.offset.async_ref) >>> 2; | ||
| const arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| const asyncRefAddress = func + emnapiTSFN.offset.async_ref; | ||
| const asyncRefOffset = asyncRefAddress >>> 2; | ||
| const arr = new Uint32Array(emnapiTSFN.ensureBufferFor(asyncRefAddress + 4)); | ||
| const currentValue = Atomics.load(arr, asyncRefOffset); | ||
@@ -977,4 +1010,5 @@ if (currentValue > 0) { | ||
| func >>>= 0; | ||
| const asyncRefOffset = (func + emnapiTSFN.offset.async_ref) >>> 2; | ||
| const arr = new Uint32Array(emscripten_runtime.wasmMemory.buffer); | ||
| const asyncRefAddress = func + emnapiTSFN.offset.async_ref; | ||
| const asyncRefOffset = asyncRefAddress >>> 2; | ||
| const arr = new Uint32Array(emnapiTSFN.ensureBufferFor(asyncRefAddress + 4)); | ||
| const currentValue = Atomics.load(arr, asyncRefOffset); | ||
@@ -981,0 +1015,0 @@ if (!currentValue) { |
+29
-29
@@ -158,7 +158,7 @@ //#region src/emnapi/v8.js | ||
| try { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| if (emnapiCtx.features.Reflect) { | ||
| const argList = Array(argc); | ||
| for (i = 0; i < argc; i++) { | ||
| const argVal = HEAP_DATA_VIEW.getUint32(argv + i * 4, true); | ||
| const argVal = GET_HEAP_DATA_VIEW().getUint32(argv + i * 4, true); | ||
| argList[i] = emnapiCtx.jsValueFromNapiValue(argVal); | ||
@@ -172,3 +172,3 @@ } | ||
| for (i = 0; i < argc; i++) { | ||
| const argVal = HEAP_DATA_VIEW.getUint32(argv + i * 4, true); | ||
| const argVal = GET_HEAP_DATA_VIEW().getUint32(argv + i * 4, true); | ||
| args[i + 1] = emnapiCtx.jsValueFromNapiValue(argVal); | ||
@@ -200,5 +200,5 @@ } | ||
| const argList = Array(argc); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| for (i = 0; i < argc; i++) { | ||
| const argVal = HEAP_DATA_VIEW.getUint32(argv + i * 4, true); | ||
| const argVal = GET_HEAP_DATA_VIEW().getUint32(argv + i * 4, true); | ||
| argList[i] = emnapiCtx.jsValueFromNapiValue(argVal); | ||
@@ -411,4 +411,4 @@ } | ||
| out >>>= 0; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setBigInt64(out, BigInt(v), true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setBigInt64(out, BigInt(v), true); | ||
| } | ||
@@ -479,4 +479,4 @@ /** | ||
| const v = r ? 1 : 0; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setInt32(success, v, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setInt32(success, v, true); | ||
| } | ||
@@ -574,4 +574,4 @@ return 0; | ||
| const vv = 1; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setInt32(success, vv, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setInt32(success, vv, true); | ||
| } | ||
@@ -599,4 +599,4 @@ return 0; | ||
| if (has) { | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setInt32(has, v, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setInt32(has, v, true); | ||
| } | ||
@@ -643,4 +643,4 @@ return 0; | ||
| const vv = r ? 1 : 0; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setInt32(success, vv, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setInt32(success, vv, true); | ||
| } | ||
@@ -830,6 +830,6 @@ return 0; | ||
| const jsValue = emnapiCtx.jsValueFromNapiValue(str); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| if (jsValue === undefined || typeof jsValue !== 'string') { | ||
| if (nchars_ref) { | ||
| HEAP_DATA_VIEW.setInt32(nchars_ref, 0, true); | ||
| GET_HEAP_DATA_VIEW().setInt32(nchars_ref, 0, true); | ||
| } | ||
@@ -840,3 +840,3 @@ return 0; | ||
| if (nchars_ref) { | ||
| HEAP_DATA_VIEW.setInt32(nchars_ref, written, true); | ||
| GET_HEAP_DATA_VIEW().setInt32(nchars_ref, written, true); | ||
| } | ||
@@ -859,7 +859,7 @@ return written; | ||
| argv >>>= 0; | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| if (argv) { | ||
| if (!argc) | ||
| return 1; | ||
| let argcValue = HEAP_DATA_VIEW.getUint32(argc, true); | ||
| let argcValue = GET_HEAP_DATA_VIEW().getUint32(argc, true); | ||
| argcValue >>>= 0; | ||
@@ -871,7 +871,7 @@ const len = cbinfoValue.args.length; | ||
| const argVal = emnapiCtx.napiValueFromJsValue(cbinfoValue.args[i]); | ||
| HEAP_DATA_VIEW.setUint32(argv + i * 4, argVal, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(argv + i * 4, argVal, true); | ||
| } | ||
| if (i < argcValue) { | ||
| for (; i < argcValue; i++) { | ||
| HEAP_DATA_VIEW.setUint32(argv + i * 4, 1, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(argv + i * 4, 1, true); | ||
| } | ||
@@ -881,3 +881,3 @@ } | ||
| if (argc) { | ||
| HEAP_DATA_VIEW.setUint32(argc, cbinfoValue.args.length, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(argc, cbinfoValue.args.length, true); | ||
| } | ||
@@ -887,3 +887,3 @@ if (this_arg) { | ||
| const v = emnapiCtx.napiValueFromJsValue(cbinfoValue.thiz); | ||
| HEAP_DATA_VIEW.setUint32(this_arg, v, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(this_arg, v, true); | ||
| } | ||
@@ -893,3 +893,3 @@ if (data) { | ||
| const localData = emnapiCtx.napiValueFromJsValue(cbinfoValue.data); | ||
| HEAP_DATA_VIEW.setUint32(data, localData, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(data, localData, true); | ||
| } | ||
@@ -1037,7 +1037,7 @@ return 0; | ||
| const holder = emnapiCtx.napiValueFromJsValue(cbinfoValue.holder); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer); | ||
| HEAP_DATA_VIEW.setUint32(args + 1 * 4, holder, true); | ||
| HEAP_DATA_VIEW.setUint32(args + 6 * 4, thiz, true); | ||
| var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : (HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer)); | ||
| GET_HEAP_DATA_VIEW().setUint32(args + 1 * 4, holder, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(args + 6 * 4, thiz, true); | ||
| const localData = emnapiCtx.napiValueFromJsValue(cbinfoValue.data); | ||
| HEAP_DATA_VIEW.setUint32(args + 5 * 4, localData, true); | ||
| GET_HEAP_DATA_VIEW().setUint32(args + 5 * 4, localData, true); | ||
| } | ||
@@ -1044,0 +1044,0 @@ /** |
+2
-2
| { | ||
| "name": "@emnapi/core", | ||
| "version": "2.0.0-alpha.2", | ||
| "version": "2.0.0-alpha.3", | ||
| "description": "emnapi core", | ||
@@ -20,3 +20,3 @@ "type": "module", | ||
| "dependencies": { | ||
| "@emnapi/wasi-threads": "2.0.0", | ||
| "@emnapi/wasi-threads": "2.0.1", | ||
| "tslib": "^2.4.0" | ||
@@ -23,0 +23,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
868749
9.46%19071
2.78%1
-50%+ Added
- Removed
Updated