@danielsimonjr/mathts-wasm 0.5.0 → 0.5.1

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/build/mathts.js CHANGED
@@ -1829,7 +1829,7 @@ async function instantiate(module, imports = {}) {
1829
1829
  ).slice();
1830
1830
  }
1831
1831
  /* mathts: typed-array write-back */
1832
- const __out = [];
1832
+ let __out = [];
1833
1833
  function __lowerTypedArray(constructor, id, align, values, track, name) {
1834
1834
  if (track & 4) __out.length = 0;
1835
1835
  if (values == null) return 0;
@@ -1923,15 +1923,30 @@ async function instantiate(module, imports = {}) {
1923
1923
  }
1924
1924
  function __abortAware(adapted) {
1925
1925
  const guarded = {};
1926
+ let depth = 0;
1927
+ let rawAllocations = false;
1926
1928
  for (const key of new Set([...Object.keys(exports), ...Object.keys(adapted)])) {
1927
1929
  const value = adapted[key];
1928
1930
  guarded[key] =
1929
1931
  typeof value === "function" && !key.startsWith("abort_")
1930
1932
  ? (...args) => {
1933
+ const previous = __out;
1934
+ __out = [];
1935
+ depth++;
1936
+ if (key === "__new" || key === "__pin") rawAllocations = true;
1931
1937
  try {
1932
- return value(...args);
1938
+ const result = value(...args);
1939
+ if (key === "heap_reset") rawAllocations = false;
1940
+ return result;
1933
1941
  } catch (error) {
1934
1942
  throw __abortError(error);
1943
+ } finally {
1944
+ __out = previous;
1945
+ if (--depth === 0 && Object.hasOwn(adapted, key)
1946
+ && !rawAllocations && refcounts.size === 0
1947
+ && typeof exports.heap_reset === "function") {
1948
+ exports.heap_reset();
1949
+ }
1935
1950
  }
1936
1951
  }
1937
1952
  : value;