@oxc-parser/binding-wasm32-wasi 0.127.0 → 0.128.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browser-bundle.js CHANGED
@@ -761,7 +761,7 @@ function __extends(d, b) {
761
761
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
762
762
  }
763
763
 
764
- // ../../node_modules/.pnpm/@emnapi+core@1.9.2/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js
764
+ // ../../node_modules/.pnpm/@emnapi+core@1.10.0/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js
765
765
  var _WebAssembly2 = typeof WebAssembly !== "undefined" ? WebAssembly : typeof WXWebAssembly !== "undefined" ? WXWebAssembly : void 0;
766
766
  function validateImports(imports) {
767
767
  if (imports && typeof imports !== "object") {
@@ -1150,6 +1150,7 @@ function createNapiModule(options) {
1150
1150
  function _emnapi_worker_ref(pthreadPtr) {
1151
1151
  if (ENVIRONMENT_IS_PTHREAD)
1152
1152
  return;
1153
+ pthreadPtr >>>= 0;
1153
1154
  var worker = emnapiGetWorkerByPthreadPtr(pthreadPtr);
1154
1155
  if (worker && typeof worker.ref === "function") {
1155
1156
  worker.ref();
@@ -1158,6 +1159,7 @@ function createNapiModule(options) {
1158
1159
  function _emnapi_worker_unref(pthreadPtr) {
1159
1160
  if (ENVIRONMENT_IS_PTHREAD)
1160
1161
  return;
1162
+ pthreadPtr >>>= 0;
1161
1163
  var worker = emnapiGetWorkerByPthreadPtr(pthreadPtr);
1162
1164
  if (worker && typeof worker.unref === "function") {
1163
1165
  worker.unref();
@@ -1266,28 +1268,13 @@ function createNapiModule(options) {
1266
1268
  1
1267
1269
  /* napi_status.napi_invalid_arg */
1268
1270
  );
1269
- var change_in_bytes_number = Number(change_in_bytes);
1270
- if (change_in_bytes_number < 0) {
1271
- return envObject.setLastError(
1272
- 1
1273
- /* napi_status.napi_invalid_arg */
1274
- );
1275
- }
1276
- var old_size = wasmMemory.buffer.byteLength;
1277
- var new_size = old_size + change_in_bytes_number;
1278
- new_size = new_size + (65536 - new_size % 65536) % 65536;
1279
- if (wasmMemory.grow(new_size - old_size + 65535 >> 16) === -1) {
1280
- return envObject.setLastError(
1281
- 9
1282
- /* napi_status.napi_generic_failure */
1283
- );
1284
- }
1271
+ var adjusted_memory = emnapiCtx.adjustAmountOfExternalAllocatedMemory(change_in_bytes);
1285
1272
  adjusted_value >>>= 0;
1286
1273
  if (emnapiCtx.feature.supportBigInt) {
1287
1274
  var HEAP_DATA_VIEW = new DataView(wasmMemory.buffer);
1288
- HEAP_DATA_VIEW.setBigInt64(adjusted_value, BigInt(wasmMemory.buffer.byteLength), true);
1275
+ HEAP_DATA_VIEW.setBigInt64(adjusted_value, BigInt(adjusted_memory), true);
1289
1276
  } else {
1290
- $emnapiSetValueI64(adjusted_value, wasmMemory.buffer.byteLength);
1277
+ $emnapiSetValueI64(adjusted_value, Number(adjusted_memory));
1291
1278
  }
1292
1279
  return envObject.clearLastError();
1293
1280
  }
@@ -1632,6 +1619,7 @@ function createNapiModule(options) {
1632
1619
  napi_open_callback_scope
1633
1620
  });
1634
1621
  var emnapiTSFN = {
1622
+ _liveSet: {},
1635
1623
  offset: {
1636
1624
  __size__: 0,
1637
1625
  /* napi_ref */
@@ -1646,6 +1634,9 @@ function createNapiModule(options) {
1646
1634
  is_some: 0,
1647
1635
  /* void* */
1648
1636
  queue: 0,
1637
+ // Reuse uv_async_t storage as JS-side wakeup state: pending event + scheduled drain.
1638
+ async_pending: 0,
1639
+ async_u_fd: 0,
1649
1640
  /* size_t */
1650
1641
  thread_count: 0,
1651
1642
  /* int32_t */
@@ -1676,6 +1667,7 @@ function createNapiModule(options) {
1676
1667
  cond: 0
1677
1668
  },
1678
1669
  init: function() {
1670
+ emnapiTSFN._liveSet = /* @__PURE__ */ new Set();
1679
1671
  emnapiTSFN.offset.__size__ = 184;
1680
1672
  emnapiTSFN.offset.resource = 0;
1681
1673
  emnapiTSFN.offset.async_id = 8;
@@ -1683,6 +1675,8 @@ function createNapiModule(options) {
1683
1675
  emnapiTSFN.offset.queue_size = 60;
1684
1676
  emnapiTSFN.offset.is_some = 24;
1685
1677
  emnapiTSFN.offset.queue = 64;
1678
+ emnapiTSFN.offset.async_pending = 132;
1679
+ emnapiTSFN.offset.async_u_fd = 96;
1686
1680
  emnapiTSFN.offset.thread_count = 136;
1687
1681
  emnapiTSFN.offset.state = 140;
1688
1682
  emnapiTSFN.offset.dispatch_state = 144;
@@ -1721,7 +1715,10 @@ function createNapiModule(options) {
1721
1715
  var type = __emnapi__.type;
1722
1716
  var payload = __emnapi__.payload;
1723
1717
  if (type === "tsfn-send") {
1724
- emnapiTSFN.dispatch(payload.tsfn);
1718
+ var pendng = payload.tsfn + emnapiTSFN.offset.async_pending;
1719
+ if (Atomics.load(new Int32Array(wasmMemory.buffer), pendng >>> 2) !== 0) {
1720
+ emnapiTSFN.enqueue(payload.tsfn);
1721
+ }
1725
1722
  }
1726
1723
  }
1727
1724
  };
@@ -1754,6 +1751,12 @@ function createNapiModule(options) {
1754
1751
  destroyQueue: function(func) {
1755
1752
  var queue = emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.queue, false);
1756
1753
  if (queue) {
1754
+ var node = emnapiTSFN.loadSizeTypeValue(queue, false);
1755
+ while (node !== 0) {
1756
+ var next = emnapiTSFN.loadSizeTypeValue(node + 4, false);
1757
+ _free(node);
1758
+ node = next;
1759
+ }
1757
1760
  _free(queue);
1758
1761
  }
1759
1762
  },
@@ -2064,6 +2067,7 @@ function createNapiModule(options) {
2064
2067
  }
2065
2068
  },
2066
2069
  destroy: function(func) {
2070
+ emnapiTSFN._liveSet.delete(func);
2067
2071
  emnapiTSFN.destroyQueue(func);
2068
2072
  emnapiTSFN.releaseResources(func);
2069
2073
  _free(func);
@@ -2155,6 +2159,7 @@ function createNapiModule(options) {
2155
2159
  return;
2156
2160
  }
2157
2161
  emnapiTSFN.setHandlesClosing(func, 1);
2162
+ Atomics.store(new Int32Array(wasmMemory.buffer), func + emnapiTSFN.offset.async_pending >>> 2, 1);
2158
2163
  emnapiCtx.feature.setImmediate(function() {
2159
2164
  emnapiTSFN.finalize(func);
2160
2165
  });
@@ -2254,24 +2259,63 @@ function createNapiModule(options) {
2254
2259
  emnapiTSFN.send(func);
2255
2260
  }
2256
2261
  },
2262
+ enqueue: function(func) {
2263
+ var pending = func + emnapiTSFN.offset.async_pending;
2264
+ var scheduled = func + emnapiTSFN.offset.async_u_fd;
2265
+ var i32a = new Int32Array(wasmMemory.buffer);
2266
+ if (Atomics.exchange(i32a, scheduled >>> 2, 1) !== 0) {
2267
+ return;
2268
+ }
2269
+ emnapiCtx.feature.setImmediate(function() {
2270
+ if (!emnapiTSFN._liveSet.has(func)) {
2271
+ return;
2272
+ }
2273
+ if (Atomics.load(i32a, pending >>> 2) === 0) {
2274
+ Atomics.store(i32a, scheduled >>> 2, 0);
2275
+ return;
2276
+ }
2277
+ emnapiCtx.feature.setImmediate(function() {
2278
+ try {
2279
+ if (Atomics.exchange(i32a, pending >>> 2, 0) === 0) {
2280
+ return;
2281
+ }
2282
+ if (!emnapiTSFN._liveSet.has(func)) {
2283
+ return;
2284
+ }
2285
+ emnapiTSFN.dispatch(func);
2286
+ } finally {
2287
+ if (emnapiTSFN._liveSet.has(func)) {
2288
+ Atomics.store(i32a, scheduled >>> 2, 0);
2289
+ if (Atomics.load(i32a, pending >>> 2) !== 0) {
2290
+ emnapiTSFN.enqueue(func);
2291
+ }
2292
+ }
2293
+ }
2294
+ });
2295
+ });
2296
+ },
2257
2297
  send: function(func) {
2258
2298
  var current_state = Atomics.or(new Uint32Array(wasmMemory.buffer), func + emnapiTSFN.offset.dispatch_state >>> 2, 1 << 1);
2259
2299
  if ((current_state & 1) === 1) {
2260
2300
  return;
2261
2301
  }
2262
- if (typeof ENVIRONMENT_IS_PTHREAD !== "undefined" && ENVIRONMENT_IS_PTHREAD) {
2263
- postMessage({
2264
- __emnapi__: {
2265
- type: "tsfn-send",
2266
- payload: {
2267
- tsfn: func
2302
+ var pendng = func + emnapiTSFN.offset.async_pending;
2303
+ if (Atomics.load(new Int32Array(wasmMemory.buffer), pendng >>> 2) !== 0) {
2304
+ return;
2305
+ }
2306
+ if (Atomics.exchange(new Int32Array(wasmMemory.buffer), pendng >>> 2, 1) === 0) {
2307
+ if (typeof ENVIRONMENT_IS_PTHREAD !== "undefined" && ENVIRONMENT_IS_PTHREAD) {
2308
+ postMessage({
2309
+ __emnapi__: {
2310
+ type: "tsfn-send",
2311
+ payload: {
2312
+ tsfn: func
2313
+ }
2268
2314
  }
2269
- }
2270
- });
2271
- } else {
2272
- emnapiCtx.feature.setImmediate(function() {
2273
- emnapiTSFN.dispatch(func);
2274
- });
2315
+ });
2316
+ } else {
2317
+ emnapiTSFN.enqueue(func);
2318
+ }
2275
2319
  }
2276
2320
  }
2277
2321
  };
@@ -2390,6 +2434,7 @@ function createNapiModule(options) {
2390
2434
  HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.finalize_cb, thread_finalize_cb, true);
2391
2435
  HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.call_js_cb, call_js_cb, true);
2392
2436
  emnapiCtx.addCleanupHook(envObject, emnapiTSFN.cleanup, tsfn);
2437
+ emnapiTSFN._liveSet.add(tsfn);
2393
2438
  envObject.ref();
2394
2439
  emnapiCtx.increaseWaitingRequestCounter();
2395
2440
  HEAP_DATA_VIEW.setUint32(tsfn + emnapiTSFN.offset.async_ref, 1, true);
@@ -3227,7 +3272,7 @@ function createNapiModule(options) {
3227
3272
  }
3228
3273
  return view;
3229
3274
  }
3230
- var maybeOldWasmMemory = emnapiExternalMemory.isDetachedArrayBuffer(view.buffer) || typeof SharedArrayBuffer === "function" && view.buffer instanceof SharedArrayBuffer;
3275
+ var maybeOldWasmMemory = emnapiExternalMemory.isDetachedArrayBuffer(view.buffer) || emnapiExternalMemory.isSharedArrayBuffer(view.buffer);
3231
3276
  if (maybeOldWasmMemory && emnapiExternalMemory.wasmMemoryViewTable.has(view)) {
3232
3277
  var info = emnapiExternalMemory.wasmMemoryViewTable.get(view);
3233
3278
  var Ctor = info.Ctor;
@@ -3772,13 +3817,12 @@ function createNapiModule(options) {
3772
3817
  }
3773
3818
  HEAP_DATA_VIEW.setInt32(type, t, true);
3774
3819
  }
3820
+ v = emnapiExternalMemory.getOrUpdateMemoryView(v);
3775
3821
  if (length) {
3776
3822
  length >>>= 0;
3777
3823
  HEAP_DATA_VIEW.setUint32(length, v.length, true);
3778
3824
  }
3779
- var buffer;
3780
3825
  if (data || arraybuffer) {
3781
- buffer = v.buffer;
3782
3826
  if (data) {
3783
3827
  data >>>= 0;
3784
3828
  var p = emnapiExternalMemory.getViewPointer(v, true).address;
@@ -3786,7 +3830,7 @@ function createNapiModule(options) {
3786
3830
  }
3787
3831
  if (arraybuffer) {
3788
3832
  arraybuffer >>>= 0;
3789
- var ab = envObject.ensureHandleId(buffer);
3833
+ var ab = envObject.ensureHandleId(v.buffer);
3790
3834
  HEAP_DATA_VIEW.setUint32(arraybuffer, ab, true);
3791
3835
  }
3792
3836
  }
@@ -3834,15 +3878,13 @@ function createNapiModule(options) {
3834
3878
  /* napi_status.napi_invalid_arg */
3835
3879
  );
3836
3880
  }
3837
- var v = handle.value;
3881
+ var v = emnapiExternalMemory.getOrUpdateMemoryView(handle.value);
3838
3882
  var HEAP_DATA_VIEW = new DataView(wasmMemory.buffer);
3839
3883
  if (byte_length) {
3840
3884
  byte_length >>>= 0;
3841
3885
  HEAP_DATA_VIEW.setUint32(byte_length, v.byteLength, true);
3842
3886
  }
3843
- var buffer;
3844
3887
  if (data || arraybuffer) {
3845
- buffer = v.buffer;
3846
3888
  if (data) {
3847
3889
  data >>>= 0;
3848
3890
  var p = emnapiExternalMemory.getViewPointer(v, true).address;
@@ -3850,7 +3892,7 @@ function createNapiModule(options) {
3850
3892
  }
3851
3893
  if (arraybuffer) {
3852
3894
  arraybuffer >>>= 0;
3853
- var ab = envObject.ensureHandleId(buffer);
3895
+ var ab = envObject.ensureHandleId(v.buffer);
3854
3896
  HEAP_DATA_VIEW.setUint32(arraybuffer, ab, true);
3855
3897
  }
3856
3898
  }
@@ -9524,7 +9566,7 @@ function instantiateNapiModuleSync(wasmInput, options) {
9524
9566
  return loadNapiModuleImpl(loadSyncCallback, void 0, wasmInput, options);
9525
9567
  }
9526
9568
 
9527
- // ../../node_modules/.pnpm/@emnapi+runtime@1.9.2/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js
9569
+ // ../../node_modules/.pnpm/@emnapi+runtime@1.10.0/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js
9528
9570
  var externalValue = /* @__PURE__ */ new WeakMap();
9529
9571
  function isExternal(object) {
9530
9572
  return externalValue.has(object);
@@ -9669,7 +9711,7 @@ var _Buffer = typeof Buffer === "function" ? Buffer : /* @__PURE__ */ (function(
9669
9711
  }
9670
9712
  return void 0;
9671
9713
  })();
9672
- var version = "1.9.2";
9714
+ var version = "1.10.0";
9673
9715
  var NODE_API_SUPPORTED_VERSION_MAX = 10;
9674
9716
  var NAPI_VERSION_EXPERIMENTAL = 2147483647;
9675
9717
  var NODE_API_DEFAULT_MODULE_API_VERSION = 8;
@@ -10667,6 +10709,29 @@ var Store = /* @__PURE__ */ (function() {
10667
10709
  };
10668
10710
  return Store2;
10669
10711
  })();
10712
+ var kMaxReasonableBytes = BigInt(1) << BigInt(60);
10713
+ var kMinReasonableBytes = -kMaxReasonableBytes;
10714
+ var ExternalMemory = /* @__PURE__ */ (function() {
10715
+ function ExternalMemory2(onChange) {
10716
+ this.total = BigInt(0);
10717
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
10718
+ }
10719
+ ExternalMemory2.prototype.adjust = function(changeInBytes) {
10720
+ changeInBytes = BigInt(changeInBytes);
10721
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
10722
+ throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range"));
10723
+ }
10724
+ var old = this.total;
10725
+ this.total += changeInBytes;
10726
+ var amount = this.total;
10727
+ var onChange = this.onChange;
10728
+ if (changeInBytes) {
10729
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
10730
+ }
10731
+ return amount;
10732
+ };
10733
+ return ExternalMemory2;
10734
+ })();
10670
10735
  var CleanupHookCallback = /* @__PURE__ */ (function() {
10671
10736
  function CleanupHookCallback2(envObject, fn, arg, order) {
10672
10737
  this.envObject = envObject;
@@ -10748,7 +10813,7 @@ var NodejsWaitingRequestCounter = /* @__PURE__ */ (function() {
10748
10813
  return NodejsWaitingRequestCounter2;
10749
10814
  })();
10750
10815
  var Context = /* @__PURE__ */ (function() {
10751
- function Context2() {
10816
+ function Context2(options) {
10752
10817
  var _this = this;
10753
10818
  this._isStopping = false;
10754
10819
  this._canCallIntoJs = true;
@@ -10770,6 +10835,7 @@ var Context = /* @__PURE__ */ (function() {
10770
10835
  MessageChannel: _MessageChannel
10771
10836
  };
10772
10837
  this.cleanupQueue = new CleanupQueue();
10838
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
10773
10839
  if (typeof process === "object" && process !== null && typeof process.once === "function") {
10774
10840
  this.refCounter = new NodejsWaitingRequestCounter();
10775
10841
  process.once("beforeExit", function() {
@@ -10817,6 +10883,9 @@ var Context = /* @__PURE__ */ (function() {
10817
10883
  Context2.prototype.createDeferred = function(value) {
10818
10884
  return Deferred.create(this, value);
10819
10885
  };
10886
+ Context2.prototype.adjustAmountOfExternalAllocatedMemory = function(changeInBytes) {
10887
+ return this._externalMemory.adjust(changeInBytes);
10888
+ };
10820
10889
  Context2.prototype.createEnv = function(filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
10821
10890
  return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
10822
10891
  };
@@ -10893,8 +10962,8 @@ var Context = /* @__PURE__ */ (function() {
10893
10962
  return Context2;
10894
10963
  })();
10895
10964
  var defaultContext;
10896
- function createContext() {
10897
- return new Context();
10965
+ function createContext(options) {
10966
+ return new Context(options);
10898
10967
  }
10899
10968
  function getDefaultContext() {
10900
10969
  if (!defaultContext) {
@@ -13342,6 +13411,11 @@ function wasiReturnOnProcExit(rval) {
13342
13411
  throw kExitCode;
13343
13412
  }
13344
13413
 
13414
+ // ../../node_modules/.pnpm/@napi-rs+wasm-runtime@1.1.4_@emnapi+core@1.10.0_@emnapi+runtime@1.10.0/node_modules/@napi-rs/wasm-runtime/fs-proxy.js
13415
+ var RESPONSE_HEADER_SIZE = 16;
13416
+ var RESPONSE_PAYLOAD_SIZE = 10240;
13417
+ var RESPONSE_BUFFER_SIZE = RESPONSE_HEADER_SIZE + RESPONSE_PAYLOAD_SIZE;
13418
+
13345
13419
  // src-js/parser.wasi-browser.js
13346
13420
  var __wasi = new WASI({
13347
13421
  version: "preview1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxc-parser/binding-wasm32-wasi",
3
- "version": "0.127.0",
3
+ "version": "0.128.0",
4
4
  "cpu": [
5
5
  "wasm32"
6
6
  ],
@@ -41,7 +41,7 @@
41
41
  "browser": "parser.wasi-browser.js",
42
42
  "dependencies": {
43
43
  "@napi-rs/wasm-runtime": "^1.1.4",
44
- "@emnapi/core": "1.9.2",
45
- "@emnapi/runtime": "1.9.2"
44
+ "@emnapi/core": "1.10.0",
45
+ "@emnapi/runtime": "1.10.0"
46
46
  }
47
47
  }
Binary file