sql.js 1.10.3 → 1.12.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.
@@ -73,7 +73,7 @@ var initSqlJs = function (moduleConfig) {
73
73
  // The Module object: Our interface to the outside world. We import
74
74
  // and export values on it. There are various ways Module can be used:
75
75
  // 1. Not defined. We create it here
76
- // 2. A function parameter, function(Module) { ..generated code.. }
76
+ // 2. A function parameter, function(moduleArg) => Promise<Module>
77
77
  // 3. pre-run appended it, var Module = {}; ..generated code..
78
78
  // 4. External script tag defines var Module.
79
79
  // We need to check if Module already exists (e.g. case 3 above).
@@ -85,8 +85,32 @@ var initSqlJs = function (moduleConfig) {
85
85
  // can continue to use Module afterwards as well.
86
86
  var Module = typeof Module != 'undefined' ? Module : {};
87
87
 
88
+ // Determine the runtime environment we are in. You can customize this by
89
+ // setting the ENVIRONMENT setting at compile time (see settings.js).
90
+
91
+ // Attempt to auto-detect the environment
92
+ var ENVIRONMENT_IS_WEB = typeof window == 'object';
93
+ var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
94
+ // N.b. Electron.js environment is simultaneously a NODE-environment, but
95
+ // also a web environment.
96
+ var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
97
+ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
98
+
99
+ if (Module['ENVIRONMENT']) {
100
+ throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
101
+ }
102
+
103
+ if (ENVIRONMENT_IS_NODE) {
104
+ // `require()` is no-op in an ESM module, use `createRequire()` to construct
105
+ // the require()` function. This is only necessary for multi-environment
106
+ // builds, `-sENVIRONMENT=node` emits a static import declaration instead.
107
+ // TODO: Swap all `require()`'s with `import()`'s?
108
+
109
+ }
110
+
88
111
  // --pre-jses are emitted after the Module integration code, so that they can
89
112
  // refer to Module (if they choose; they can also define Module)
113
+ // include: /github/workspace/src/api.js
90
114
  /* global
91
115
  FS
92
116
  HEAP8
@@ -1475,6 +1499,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
1475
1499
  // export Database to Module
1476
1500
  Module.Database = Database;
1477
1501
  };
1502
+ // end include: /github/workspace/src/api.js
1478
1503
 
1479
1504
 
1480
1505
  // Sometimes an existing Module object exists with properties
@@ -1490,21 +1515,6 @@ var quit_ = (status, toThrow) => {
1490
1515
  throw toThrow;
1491
1516
  };
1492
1517
 
1493
- // Determine the runtime environment we are in. You can customize this by
1494
- // setting the ENVIRONMENT setting at compile time (see settings.js).
1495
-
1496
- // Attempt to auto-detect the environment
1497
- var ENVIRONMENT_IS_WEB = typeof window == 'object';
1498
- var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
1499
- // N.b. Electron.js environment is simultaneously a NODE-environment, but
1500
- // also a web environment.
1501
- var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
1502
- var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
1503
-
1504
- if (Module['ENVIRONMENT']) {
1505
- throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
1506
- }
1507
-
1508
1518
  // `/` should be present at the end if `scriptDirectory` is not empty
1509
1519
  var scriptDirectory = '';
1510
1520
  function locateFile(path) {
@@ -1515,9 +1525,7 @@ function locateFile(path) {
1515
1525
  }
1516
1526
 
1517
1527
  // Hooks that are implemented differently in different runtime environments.
1518
- var read_,
1519
- readAsync,
1520
- readBinary;
1528
+ var readAsync, readBinary;
1521
1529
 
1522
1530
  if (ENVIRONMENT_IS_NODE) {
1523
1531
  if (typeof process == 'undefined' || !process.release || process.release.name !== 'node') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
@@ -1530,44 +1538,31 @@ if (ENVIRONMENT_IS_NODE) {
1530
1538
  throw new Error('This emscripten-generated code requires node v16.0.0 (detected v' + nodeVersion + ')');
1531
1539
  }
1532
1540
 
1533
- // `require()` is no-op in an ESM module, use `createRequire()` to construct
1534
- // the require()` function. This is only necessary for multi-environment
1535
- // builds, `-sENVIRONMENT=node` emits a static import declaration instead.
1536
- // TODO: Swap all `require()`'s with `import()`'s?
1537
1541
  // These modules will usually be used on Node.js. Load them eagerly to avoid
1538
1542
  // the complexity of lazy-loading.
1539
1543
  var fs = require('fs');
1540
1544
  var nodePath = require('path');
1541
1545
 
1542
- if (ENVIRONMENT_IS_WORKER) {
1543
- scriptDirectory = nodePath.dirname(scriptDirectory) + '/';
1544
- } else {
1545
- scriptDirectory = __dirname + '/';
1546
- }
1546
+ scriptDirectory = __dirname + '/';
1547
1547
 
1548
1548
  // include: node_shell_read.js
1549
- read_ = (filename, binary) => {
1549
+ readBinary = (filename) => {
1550
1550
  // We need to re-wrap `file://` strings to URLs. Normalizing isn't
1551
1551
  // necessary in that case, the path should already be absolute.
1552
1552
  filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
1553
- return fs.readFileSync(filename, binary ? undefined : 'utf8');
1554
- };
1555
-
1556
- readBinary = (filename) => {
1557
- var ret = read_(filename, true);
1558
- if (!ret.buffer) {
1559
- ret = new Uint8Array(ret);
1560
- }
1553
+ var ret = fs.readFileSync(filename);
1561
1554
  assert(ret.buffer);
1562
1555
  return ret;
1563
1556
  };
1564
1557
 
1565
- readAsync = (filename, onload, onerror, binary = true) => {
1566
- // See the comment in the `read_` function.
1558
+ readAsync = (filename, binary = true) => {
1559
+ // See the comment in the `readBinary` function.
1567
1560
  filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
1568
- fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
1569
- if (err) onerror(err);
1570
- else onload(binary ? data.buffer : data);
1561
+ return new Promise((resolve, reject) => {
1562
+ fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
1563
+ if (err) reject(err);
1564
+ else resolve(binary ? data.buffer : data);
1565
+ });
1571
1566
  });
1572
1567
  };
1573
1568
  // end include: node_shell_read.js
@@ -1586,77 +1581,11 @@ readAsync = (filename, onload, onerror, binary = true) => {
1586
1581
  throw toThrow;
1587
1582
  };
1588
1583
 
1589
- Module['inspect'] = () => '[Emscripten Module object]';
1590
-
1591
1584
  } else
1592
1585
  if (ENVIRONMENT_IS_SHELL) {
1593
1586
 
1594
1587
  if ((typeof process == 'object' && typeof require === 'function') || typeof window == 'object' || typeof importScripts == 'function') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
1595
1588
 
1596
- if (typeof read != 'undefined') {
1597
- read_ = read;
1598
- }
1599
-
1600
- readBinary = (f) => {
1601
- if (typeof readbuffer == 'function') {
1602
- return new Uint8Array(readbuffer(f));
1603
- }
1604
- let data = read(f, 'binary');
1605
- assert(typeof data == 'object');
1606
- return data;
1607
- };
1608
-
1609
- readAsync = (f, onload, onerror) => {
1610
- setTimeout(() => onload(readBinary(f)));
1611
- };
1612
-
1613
- if (typeof clearTimeout == 'undefined') {
1614
- globalThis.clearTimeout = (id) => {};
1615
- }
1616
-
1617
- if (typeof setTimeout == 'undefined') {
1618
- // spidermonkey lacks setTimeout but we use it above in readAsync.
1619
- globalThis.setTimeout = (f) => (typeof f == 'function') ? f() : abort();
1620
- }
1621
-
1622
- if (typeof scriptArgs != 'undefined') {
1623
- arguments_ = scriptArgs;
1624
- } else if (typeof arguments != 'undefined') {
1625
- arguments_ = arguments;
1626
- }
1627
-
1628
- if (typeof quit == 'function') {
1629
- quit_ = (status, toThrow) => {
1630
- // Unlike node which has process.exitCode, d8 has no such mechanism. So we
1631
- // have no way to set the exit code and then let the program exit with
1632
- // that code when it naturally stops running (say, when all setTimeouts
1633
- // have completed). For that reason, we must call `quit` - the only way to
1634
- // set the exit code - but quit also halts immediately. To increase
1635
- // consistency with node (and the web) we schedule the actual quit call
1636
- // using a setTimeout to give the current stack and any exception handlers
1637
- // a chance to run. This enables features such as addOnPostRun (which
1638
- // expected to be able to run code after main returns).
1639
- setTimeout(() => {
1640
- if (!(toThrow instanceof ExitStatus)) {
1641
- let toLog = toThrow;
1642
- if (toThrow && typeof toThrow == 'object' && toThrow.stack) {
1643
- toLog = [toThrow, toThrow.stack];
1644
- }
1645
- err(`exiting due to exception: ${toLog}`);
1646
- }
1647
- quit(status);
1648
- });
1649
- throw toThrow;
1650
- };
1651
- }
1652
-
1653
- if (typeof print != 'undefined') {
1654
- // Prefer to use print/printErr where they exist, as they usually work better.
1655
- if (typeof console == 'undefined') console = /** @type{!Console} */({});
1656
- console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
1657
- console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr != 'undefined' ? printErr : print);
1658
- }
1659
-
1660
1589
  } else
1661
1590
 
1662
1591
  // Note that this includes Node.js workers when relevant (pthreads is enabled).
@@ -1674,26 +1603,17 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
1674
1603
  // and scriptDirectory will correctly be replaced with an empty string.
1675
1604
  // If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
1676
1605
  // they are removed because they could contain a slash.
1677
- if (scriptDirectory.indexOf('blob:') !== 0) {
1678
- scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf('/')+1);
1679
- } else {
1606
+ if (scriptDirectory.startsWith('blob:')) {
1680
1607
  scriptDirectory = '';
1608
+ } else {
1609
+ scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, '').lastIndexOf('/')+1);
1681
1610
  }
1682
1611
 
1683
1612
  if (!(typeof window == 'object' || typeof importScripts == 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
1684
1613
 
1685
- // Differentiate the Web Worker from the Node Worker case, as reading must
1686
- // be done differently.
1687
1614
  {
1688
1615
  // include: web_or_worker_shell_read.js
1689
- read_ = (url) => {
1690
- var xhr = new XMLHttpRequest();
1691
- xhr.open('GET', url, false);
1692
- xhr.send(null);
1693
- return xhr.responseText;
1694
- }
1695
-
1696
- if (ENVIRONMENT_IS_WORKER) {
1616
+ if (ENVIRONMENT_IS_WORKER) {
1697
1617
  readBinary = (url) => {
1698
1618
  var xhr = new XMLHttpRequest();
1699
1619
  xhr.open('GET', url, false);
@@ -1703,21 +1623,34 @@ read_ = (url) => {
1703
1623
  };
1704
1624
  }
1705
1625
 
1706
- readAsync = (url, onload, onerror) => {
1707
- var xhr = new XMLHttpRequest();
1708
- xhr.open('GET', url, true);
1709
- xhr.responseType = 'arraybuffer';
1710
- xhr.onload = () => {
1711
- if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
1712
- onload(xhr.response);
1713
- return;
1714
- }
1715
- onerror();
1716
- };
1717
- xhr.onerror = onerror;
1718
- xhr.send(null);
1719
- }
1720
-
1626
+ readAsync = (url) => {
1627
+ // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
1628
+ // See https://github.com/github/fetch/pull/92#issuecomment-140665932
1629
+ // Cordova or Electron apps are typically loaded from a file:// url.
1630
+ // So use XHR on webview if URL is a file URL.
1631
+ if (isFileURI(url)) {
1632
+ return new Promise((reject, resolve) => {
1633
+ var xhr = new XMLHttpRequest();
1634
+ xhr.open('GET', url, true);
1635
+ xhr.responseType = 'arraybuffer';
1636
+ xhr.onload = () => {
1637
+ if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
1638
+ resolve(xhr.response);
1639
+ }
1640
+ reject(xhr.status);
1641
+ };
1642
+ xhr.onerror = reject;
1643
+ xhr.send(null);
1644
+ });
1645
+ }
1646
+ return fetch(url, { credentials: 'same-origin' })
1647
+ .then((response) => {
1648
+ if (response.ok) {
1649
+ return response.arrayBuffer();
1650
+ }
1651
+ return Promise.reject(new Error(response.status + ' : ' + response.url));
1652
+ })
1653
+ };
1721
1654
  // end include: web_or_worker_shell_read.js
1722
1655
  }
1723
1656
  } else
@@ -1731,7 +1664,7 @@ var err = Module['printErr'] || console.error.bind(console);
1731
1664
  // Merge back in the overrides
1732
1665
  Object.assign(Module, moduleOverrides);
1733
1666
  // Free the object hierarchy contained in the overrides, this lets the GC
1734
- // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
1667
+ // reclaim data used.
1735
1668
  moduleOverrides = null;
1736
1669
  checkIncomingModuleAPI();
1737
1670
 
@@ -1752,13 +1685,12 @@ assert(typeof Module['memoryInitializerPrefixURL'] == 'undefined', 'Module.memor
1752
1685
  assert(typeof Module['pthreadMainPrefixURL'] == 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
1753
1686
  assert(typeof Module['cdInitializerPrefixURL'] == 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
1754
1687
  assert(typeof Module['filePackagePrefixURL'] == 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
1755
- assert(typeof Module['read'] == 'undefined', 'Module.read option was removed (modify read_ in JS)');
1688
+ assert(typeof Module['read'] == 'undefined', 'Module.read option was removed');
1756
1689
  assert(typeof Module['readAsync'] == 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)');
1757
1690
  assert(typeof Module['readBinary'] == 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)');
1758
1691
  assert(typeof Module['setWindowTitle'] == 'undefined', 'Module.setWindowTitle option was removed (modify emscripten_set_window_title in JS)');
1759
1692
  assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
1760
1693
  legacyModuleProp('asm', 'wasmExports');
1761
- legacyModuleProp('read', 'read_');
1762
1694
  legacyModuleProp('readAsync', 'readAsync');
1763
1695
  legacyModuleProp('readBinary', 'readBinary');
1764
1696
  legacyModuleProp('setWindowTitle', 'setWindowTitle');
@@ -1772,10 +1704,10 @@ var OPFS = 'OPFS is no longer included by default; build with -lopfs.js';
1772
1704
 
1773
1705
  var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
1774
1706
 
1775
- assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable.");
1776
-
1707
+ assert(!ENVIRONMENT_IS_SHELL, 'shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.');
1777
1708
 
1778
1709
  // end include: shell.js
1710
+
1779
1711
  // include: preamble.js
1780
1712
  // === Preamble library stuff ===
1781
1713
 
@@ -1791,7 +1723,7 @@ var wasmBinary;
1791
1723
  if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];legacyModuleProp('wasmBinary', 'wasmBinary');
1792
1724
 
1793
1725
  if (typeof WebAssembly != 'object') {
1794
- abort('no native wasm support detected');
1726
+ err('no native wasm support detected');
1795
1727
  }
1796
1728
 
1797
1729
  // Wasm globals
@@ -1845,6 +1777,7 @@ var HEAP,
1845
1777
  /** @type {!Float64Array} */
1846
1778
  HEAPF64;
1847
1779
 
1780
+ // include: runtime_shared.js
1848
1781
  function updateMemoryViews() {
1849
1782
  var b = wasmMemory.buffer;
1850
1783
  Module['HEAP8'] = HEAP8 = new Int8Array(b);
@@ -1856,7 +1789,7 @@ function updateMemoryViews() {
1856
1789
  Module['HEAPF32'] = HEAPF32 = new Float32Array(b);
1857
1790
  Module['HEAPF64'] = HEAPF64 = new Float64Array(b);
1858
1791
  }
1859
-
1792
+ // end include: runtime_shared.js
1860
1793
  assert(!Module['STACK_SIZE'], 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time')
1861
1794
 
1862
1795
  assert(typeof Int32Array != 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined,
@@ -1940,7 +1873,7 @@ function initRuntime() {
1940
1873
  setStackLimits();
1941
1874
 
1942
1875
 
1943
- if (!Module["noFSInit"] && !FS.init.initialized)
1876
+ if (!Module['noFSInit'] && !FS.init.initialized)
1944
1877
  FS.init();
1945
1878
  FS.ignorePermissions = false;
1946
1879
 
@@ -2090,7 +2023,7 @@ function abort(what) {
2090
2023
  // allows this in the wasm spec.
2091
2024
 
2092
2025
  // Suppress closure compiler warning here. Closure compiler's builtin extern
2093
- // defintion for WebAssembly.RuntimeError claims it takes no arguments even
2026
+ // definition for WebAssembly.RuntimeError claims it takes no arguments even
2094
2027
  // though it can.
2095
2028
  // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
2096
2029
  /** @suppress {checkTypes} */
@@ -2120,22 +2053,28 @@ var isDataURI = (filename) => filename.startsWith(dataURIPrefix);
2120
2053
  */
2121
2054
  var isFileURI = (filename) => filename.startsWith('file://');
2122
2055
  // end include: URIUtils.js
2123
- function createExportWrapper(name) {
2124
- return function() {
2056
+ function createExportWrapper(name, nargs) {
2057
+ return (...args) => {
2125
2058
  assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
2126
2059
  var f = wasmExports[name];
2127
2060
  assert(f, `exported native function \`${name}\` not found`);
2128
- return f.apply(null, arguments);
2061
+ // Only assert for too many arguments. Too few can be valid since the missing arguments will be zero filled.
2062
+ assert(args.length <= nargs, `native function \`${name}\` called with ${args.length} args but expects ${nargs}`);
2063
+ return f(...args);
2129
2064
  };
2130
2065
  }
2131
2066
 
2132
2067
  // include: runtime_exceptions.js
2133
2068
  // end include: runtime_exceptions.js
2069
+ function findWasmBinary() {
2070
+ var f = 'sql-wasm-debug.wasm';
2071
+ if (!isDataURI(f)) {
2072
+ return locateFile(f);
2073
+ }
2074
+ return f;
2075
+ }
2076
+
2134
2077
  var wasmBinaryFile;
2135
- wasmBinaryFile = 'sql-wasm-debug.wasm';
2136
- if (!isDataURI(wasmBinaryFile)) {
2137
- wasmBinaryFile = locateFile(wasmBinaryFile);
2138
- }
2139
2078
 
2140
2079
  function getBinarySync(file) {
2141
2080
  if (file == wasmBinaryFile && wasmBinary) {
@@ -2144,33 +2083,19 @@ function getBinarySync(file) {
2144
2083
  if (readBinary) {
2145
2084
  return readBinary(file);
2146
2085
  }
2147
- throw "both async and sync fetching of the wasm failed";
2086
+ throw 'both async and sync fetching of the wasm failed';
2148
2087
  }
2149
2088
 
2150
2089
  function getBinaryPromise(binaryFile) {
2151
- // If we don't have the binary yet, try to load it asynchronously.
2152
- // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
2153
- // See https://github.com/github/fetch/pull/92#issuecomment-140665932
2154
- // Cordova or Electron apps are typically loaded from a file:// url.
2155
- // So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
2090
+ // If we don't have the binary yet, load it asynchronously using readAsync.
2156
2091
  if (!wasmBinary
2157
- && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
2158
- if (typeof fetch == 'function'
2159
- && !isFileURI(binaryFile)
2160
- ) {
2161
- return fetch(binaryFile, { credentials: 'same-origin' }).then((response) => {
2162
- if (!response['ok']) {
2163
- throw "failed to load wasm binary file at '" + binaryFile + "'";
2164
- }
2165
- return response['arrayBuffer']();
2166
- }).catch(() => getBinarySync(binaryFile));
2167
- }
2168
- else if (readAsync) {
2169
- // fetch is not available or url is file => try XHR (readAsync uses XHR internally)
2170
- return new Promise((resolve, reject) => {
2171
- readAsync(binaryFile, (response) => resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))), reject)
2172
- });
2173
- }
2092
+ ) {
2093
+ // Fetch the binary using readAsync
2094
+ return readAsync(binaryFile).then(
2095
+ (response) => new Uint8Array(/** @type{!ArrayBuffer} */(response)),
2096
+ // Fall back to getBinarySync if readAsync fails
2097
+ () => getBinarySync(binaryFile)
2098
+ );
2174
2099
  }
2175
2100
 
2176
2101
  // Otherwise, getBinarySync should be able to get it synchronously
@@ -2180,8 +2105,6 @@ function getBinaryPromise(binaryFile) {
2180
2105
  function instantiateArrayBuffer(binaryFile, imports, receiver) {
2181
2106
  return getBinaryPromise(binaryFile).then((binary) => {
2182
2107
  return WebAssembly.instantiate(binary, imports);
2183
- }).then((instance) => {
2184
- return instance;
2185
2108
  }).then(receiver, (reason) => {
2186
2109
  err(`failed to asynchronously prepare wasm: ${reason}`);
2187
2110
 
@@ -2229,14 +2152,18 @@ function instantiateAsync(binary, binaryFile, imports, callback) {
2229
2152
  return instantiateArrayBuffer(binaryFile, imports, callback);
2230
2153
  }
2231
2154
 
2232
- // Create the wasm instance.
2233
- // Receives the wasm imports, returns the exports.
2234
- function createWasm() {
2155
+ function getWasmImports() {
2235
2156
  // prepare imports
2236
- var info = {
2157
+ return {
2237
2158
  'env': wasmImports,
2238
2159
  'wasi_snapshot_preview1': wasmImports,
2239
- };
2160
+ }
2161
+ }
2162
+
2163
+ // Create the wasm instance.
2164
+ // Receives the wasm imports, returns the exports.
2165
+ function createWasm() {
2166
+ var info = getWasmImports();
2240
2167
  // Load the wasm module and create an instance of using native support in the JS engine.
2241
2168
  // handle a generated wasm instance, receiving its exports and
2242
2169
  // performing other necessary setup
@@ -2248,16 +2175,12 @@ function createWasm() {
2248
2175
 
2249
2176
  wasmMemory = wasmExports['memory'];
2250
2177
 
2251
- assert(wasmMemory, "memory not found in wasm exports");
2252
- // This assertion doesn't hold when emscripten is run in --post-link
2253
- // mode.
2254
- // TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode.
2255
- //assert(wasmMemory.buffer.byteLength === 16777216);
2178
+ assert(wasmMemory, 'memory not found in wasm exports');
2256
2179
  updateMemoryViews();
2257
2180
 
2258
2181
  wasmTable = wasmExports['__indirect_function_table'];
2259
2182
 
2260
- assert(wasmTable, "table not found in wasm exports");
2183
+ assert(wasmTable, 'table not found in wasm exports');
2261
2184
 
2262
2185
  addOnInit(wasmExports['__wasm_call_ctors']);
2263
2186
 
@@ -2289,7 +2212,6 @@ function createWasm() {
2289
2212
  // Also pthreads and wasm workers initialize the wasm instance through this
2290
2213
  // path.
2291
2214
  if (Module['instantiateWasm']) {
2292
-
2293
2215
  try {
2294
2216
  return Module['instantiateWasm'](info, receiveInstance);
2295
2217
  } catch(e) {
@@ -2298,6 +2220,8 @@ function createWasm() {
2298
2220
  }
2299
2221
  }
2300
2222
 
2223
+ if (!wasmBinaryFile) wasmBinaryFile = findWasmBinary();
2224
+
2301
2225
  instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult);
2302
2226
  return {}; // no exports yet; we'll fill them in later
2303
2227
  }
@@ -2307,12 +2231,12 @@ var tempDouble;
2307
2231
  var tempI64;
2308
2232
 
2309
2233
  // include: runtime_debug.js
2310
- function legacyModuleProp(prop, newName, incomming=true) {
2234
+ function legacyModuleProp(prop, newName, incoming=true) {
2311
2235
  if (!Object.getOwnPropertyDescriptor(Module, prop)) {
2312
2236
  Object.defineProperty(Module, prop, {
2313
2237
  configurable: true,
2314
2238
  get() {
2315
- let extra = incomming ? ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)' : '';
2239
+ let extra = incoming ? ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)' : '';
2316
2240
  abort(`\`Module.${prop}\` has been replaced by \`${newName}\`` + extra);
2317
2241
 
2318
2242
  }
@@ -2340,7 +2264,7 @@ function isExportedByForceFilesystem(name) {
2340
2264
  }
2341
2265
 
2342
2266
  function missingGlobal(sym, msg) {
2343
- if (typeof globalThis !== 'undefined') {
2267
+ if (typeof globalThis != 'undefined') {
2344
2268
  Object.defineProperty(globalThis, sym, {
2345
2269
  configurable: true,
2346
2270
  get() {
@@ -2355,7 +2279,7 @@ missingGlobal('buffer', 'Please use HEAP8.buffer or wasmMemory.buffer');
2355
2279
  missingGlobal('asm', 'Please use wasmExports instead');
2356
2280
 
2357
2281
  function missingLibrarySymbol(sym) {
2358
- if (typeof globalThis !== 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
2282
+ if (typeof globalThis != 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
2359
2283
  Object.defineProperty(globalThis, sym, {
2360
2284
  configurable: true,
2361
2285
  get() {
@@ -2378,7 +2302,7 @@ function missingLibrarySymbol(sym) {
2378
2302
  }
2379
2303
  });
2380
2304
  }
2381
- // Any symbol that is not included from the JS libary is also (by definition)
2305
+ // Any symbol that is not included from the JS library is also (by definition)
2382
2306
  // not exported on the Module object.
2383
2307
  unexportedRuntimeSymbol(sym);
2384
2308
  }
@@ -2424,16 +2348,16 @@ var checkInt53 = (value) => checkInt(value, 53, MIN_INT53, MAX_UINT53);
2424
2348
  var checkInt64 = (value) => checkInt(value, 64, MIN_INT64, MAX_UINT64);
2425
2349
 
2426
2350
  // Used by XXXXX_DEBUG settings to output debug messages.
2427
- function dbg(text) {
2351
+ function dbg(...args) {
2428
2352
  // TODO(sbc): Make this configurable somehow. Its not always convenient for
2429
2353
  // logging to show up as warnings.
2430
- console.warn.apply(console, arguments);
2354
+ console.warn(...args);
2431
2355
  }
2432
2356
  // end include: runtime_debug.js
2433
2357
  // === Body ===
2434
-
2435
2358
  // end include: preamble.js
2436
2359
 
2360
+
2437
2361
  /** @constructor */
2438
2362
  function ExitStatus(status) {
2439
2363
  this.name = 'ExitStatus';
@@ -2456,8 +2380,8 @@ function dbg(text) {
2456
2380
  function getValue(ptr, type = 'i8') {
2457
2381
  if (type.endsWith('*')) type = '*';
2458
2382
  switch (type) {
2459
- case 'i1': return HEAP8[((ptr)>>0)];
2460
- case 'i8': return HEAP8[((ptr)>>0)];
2383
+ case 'i1': return HEAP8[ptr];
2384
+ case 'i8': return HEAP8[ptr];
2461
2385
  case 'i16': return HEAP16[((ptr)>>1)];
2462
2386
  case 'i32': return HEAP32[((ptr)>>2)];
2463
2387
  case 'i64': abort('to do getValue(i64) use WASM_BIGINT');
@@ -2492,8 +2416,8 @@ function dbg(text) {
2492
2416
  function setValue(ptr, value, type = 'i8') {
2493
2417
  if (type.endsWith('*')) type = '*';
2494
2418
  switch (type) {
2495
- case 'i1': HEAP8[((ptr)>>0)] = value;checkInt8(value); break;
2496
- case 'i8': HEAP8[((ptr)>>0)] = value;checkInt8(value); break;
2419
+ case 'i1': HEAP8[ptr] = value;checkInt8(value); break;
2420
+ case 'i8': HEAP8[ptr] = value;checkInt8(value); break;
2497
2421
  case 'i16': HEAP16[((ptr)>>1)] = value;checkInt16(value); break;
2498
2422
  case 'i32': HEAP32[((ptr)>>2)] = value;checkInt32(value); break;
2499
2423
  case 'i64': abort('to do setValue(i64) use WASM_BIGINT');
@@ -2504,6 +2428,10 @@ function dbg(text) {
2504
2428
  }
2505
2429
  }
2506
2430
 
2431
+ var stackRestore = (val) => __emscripten_stack_restore(val);
2432
+
2433
+ var stackSave = () => _emscripten_stack_get_current();
2434
+
2507
2435
  var warnOnce = (text) => {
2508
2436
  warnOnce.shown ||= {};
2509
2437
  if (!warnOnce.shown[text]) {
@@ -2513,7 +2441,7 @@ function dbg(text) {
2513
2441
  }
2514
2442
  };
2515
2443
 
2516
- var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf8') : undefined;
2444
+ var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder() : undefined;
2517
2445
 
2518
2446
  /**
2519
2447
  * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
@@ -2665,10 +2593,7 @@ function dbg(text) {
2665
2593
  if (lastSlash === -1) return path;
2666
2594
  return path.substr(lastSlash+1);
2667
2595
  },
2668
- join:function() {
2669
- var paths = Array.prototype.slice.call(arguments);
2670
- return PATH.normalize(paths.join('/'));
2671
- },
2596
+ join:(...paths) => PATH.normalize(paths.join('/')),
2672
2597
  join2:(l, r) => PATH.normalize(l + '/' + r),
2673
2598
  };
2674
2599
 
@@ -2698,7 +2623,7 @@ function dbg(text) {
2698
2623
  }
2699
2624
  }
2700
2625
  // we couldn't find a proper implementation, as Math.random() is not suitable for /dev/random, see emscripten-core/emscripten/pull/7096
2701
- abort("no cryptographic support found for randomDevice. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: (array) => { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };");
2626
+ abort('no cryptographic support found for randomDevice. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: (array) => { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };');
2702
2627
  };
2703
2628
  var randomFill = (view) => {
2704
2629
  // Lazily init on the first invocation.
@@ -2708,11 +2633,11 @@ function dbg(text) {
2708
2633
 
2709
2634
 
2710
2635
  var PATH_FS = {
2711
- resolve:function() {
2636
+ resolve:(...args) => {
2712
2637
  var resolvedPath = '',
2713
2638
  resolvedAbsolute = false;
2714
- for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
2715
- var path = (i >= 0) ? arguments[i] : FS.cwd();
2639
+ for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
2640
+ var path = (i >= 0) ? args[i] : FS.cwd();
2716
2641
  // Skip empty and invalid entries
2717
2642
  if (typeof path != 'string') {
2718
2643
  throw new TypeError('Arguments to path.resolve must be strings');
@@ -2860,18 +2785,17 @@ function dbg(text) {
2860
2785
  var fd = process.stdin.fd;
2861
2786
 
2862
2787
  try {
2863
- bytesRead = fs.readSync(fd, buf);
2788
+ bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
2864
2789
  } catch(e) {
2865
- // Cross-platform differences: on Windows, reading EOF throws an exception, but on other OSes,
2866
- // reading EOF returns 0. Uniformize behavior by treating the EOF exception to return 0.
2790
+ // Cross-platform differences: on Windows, reading EOF throws an
2791
+ // exception, but on other OSes, reading EOF returns 0. Uniformize
2792
+ // behavior by treating the EOF exception to return 0.
2867
2793
  if (e.toString().includes('EOF')) bytesRead = 0;
2868
2794
  else throw e;
2869
2795
  }
2870
2796
 
2871
2797
  if (bytesRead > 0) {
2872
2798
  result = buf.slice(0, bytesRead).toString('utf-8');
2873
- } else {
2874
- result = null;
2875
2799
  }
2876
2800
  } else
2877
2801
  if (typeof window != 'undefined' &&
@@ -2881,13 +2805,8 @@ function dbg(text) {
2881
2805
  if (result !== null) {
2882
2806
  result += '\n';
2883
2807
  }
2884
- } else if (typeof readline == 'function') {
2885
- // Command line.
2886
- result = readline();
2887
- if (result !== null) {
2888
- result += '\n';
2889
- }
2890
- }
2808
+ } else
2809
+ {}
2891
2810
  if (!result) {
2892
2811
  return null;
2893
2812
  }
@@ -3236,7 +3155,6 @@ function dbg(text) {
3236
3155
  old_node.name = new_name;
3237
3156
  new_dir.contents[new_name] = old_node;
3238
3157
  new_dir.timestamp = old_node.parent.timestamp;
3239
- old_node.parent = new_dir;
3240
3158
  },
3241
3159
  unlink(parent, name) {
3242
3160
  delete parent.contents[name];
@@ -3386,17 +3304,20 @@ function dbg(text) {
3386
3304
  /** @param {boolean=} noRunDep */
3387
3305
  var asyncLoad = (url, onload, onerror, noRunDep) => {
3388
3306
  var dep = !noRunDep ? getUniqueRunDependency(`al ${url}`) : '';
3389
- readAsync(url, (arrayBuffer) => {
3390
- assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
3391
- onload(new Uint8Array(arrayBuffer));
3392
- if (dep) removeRunDependency(dep);
3393
- }, (event) => {
3394
- if (onerror) {
3395
- onerror();
3396
- } else {
3397
- throw `Loading data file "${url}" failed.`;
3307
+ readAsync(url).then(
3308
+ (arrayBuffer) => {
3309
+ assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
3310
+ onload(new Uint8Array(arrayBuffer));
3311
+ if (dep) removeRunDependency(dep);
3312
+ },
3313
+ (err) => {
3314
+ if (onerror) {
3315
+ onerror();
3316
+ } else {
3317
+ throw `Loading data file "${url}" failed.`;
3318
+ }
3398
3319
  }
3399
- });
3320
+ );
3400
3321
  if (dep) addRunDependency(dep);
3401
3322
  };
3402
3323
 
@@ -3444,7 +3365,7 @@ function dbg(text) {
3444
3365
  }
3445
3366
  addRunDependency(dep);
3446
3367
  if (typeof url == 'string') {
3447
- asyncLoad(url, (byteArray) => processData(byteArray), onerror);
3368
+ asyncLoad(url, processData, onerror);
3448
3369
  } else {
3449
3370
  processData(url);
3450
3371
  }
@@ -3476,127 +3397,11 @@ function dbg(text) {
3476
3397
 
3477
3398
 
3478
3399
 
3479
- var ERRNO_MESSAGES = {
3480
- 0:"Success",
3481
- 1:"Arg list too long",
3482
- 2:"Permission denied",
3483
- 3:"Address already in use",
3484
- 4:"Address not available",
3485
- 5:"Address family not supported by protocol family",
3486
- 6:"No more processes",
3487
- 7:"Socket already connected",
3488
- 8:"Bad file number",
3489
- 9:"Trying to read unreadable message",
3490
- 10:"Mount device busy",
3491
- 11:"Operation canceled",
3492
- 12:"No children",
3493
- 13:"Connection aborted",
3494
- 14:"Connection refused",
3495
- 15:"Connection reset by peer",
3496
- 16:"File locking deadlock error",
3497
- 17:"Destination address required",
3498
- 18:"Math arg out of domain of func",
3499
- 19:"Quota exceeded",
3500
- 20:"File exists",
3501
- 21:"Bad address",
3502
- 22:"File too large",
3503
- 23:"Host is unreachable",
3504
- 24:"Identifier removed",
3505
- 25:"Illegal byte sequence",
3506
- 26:"Connection already in progress",
3507
- 27:"Interrupted system call",
3508
- 28:"Invalid argument",
3509
- 29:"I/O error",
3510
- 30:"Socket is already connected",
3511
- 31:"Is a directory",
3512
- 32:"Too many symbolic links",
3513
- 33:"Too many open files",
3514
- 34:"Too many links",
3515
- 35:"Message too long",
3516
- 36:"Multihop attempted",
3517
- 37:"File or path name too long",
3518
- 38:"Network interface is not configured",
3519
- 39:"Connection reset by network",
3520
- 40:"Network is unreachable",
3521
- 41:"Too many open files in system",
3522
- 42:"No buffer space available",
3523
- 43:"No such device",
3524
- 44:"No such file or directory",
3525
- 45:"Exec format error",
3526
- 46:"No record locks available",
3527
- 47:"The link has been severed",
3528
- 48:"Not enough core",
3529
- 49:"No message of desired type",
3530
- 50:"Protocol not available",
3531
- 51:"No space left on device",
3532
- 52:"Function not implemented",
3533
- 53:"Socket is not connected",
3534
- 54:"Not a directory",
3535
- 55:"Directory not empty",
3536
- 56:"State not recoverable",
3537
- 57:"Socket operation on non-socket",
3538
- 59:"Not a typewriter",
3539
- 60:"No such device or address",
3540
- 61:"Value too large for defined data type",
3541
- 62:"Previous owner died",
3542
- 63:"Not super-user",
3543
- 64:"Broken pipe",
3544
- 65:"Protocol error",
3545
- 66:"Unknown protocol",
3546
- 67:"Protocol wrong type for socket",
3547
- 68:"Math result not representable",
3548
- 69:"Read only file system",
3549
- 70:"Illegal seek",
3550
- 71:"No such process",
3551
- 72:"Stale file handle",
3552
- 73:"Connection timed out",
3553
- 74:"Text file busy",
3554
- 75:"Cross-device link",
3555
- 100:"Device not a stream",
3556
- 101:"Bad font file fmt",
3557
- 102:"Invalid slot",
3558
- 103:"Invalid request code",
3559
- 104:"No anode",
3560
- 105:"Block device required",
3561
- 106:"Channel number out of range",
3562
- 107:"Level 3 halted",
3563
- 108:"Level 3 reset",
3564
- 109:"Link number out of range",
3565
- 110:"Protocol driver not attached",
3566
- 111:"No CSI structure available",
3567
- 112:"Level 2 halted",
3568
- 113:"Invalid exchange",
3569
- 114:"Invalid request descriptor",
3570
- 115:"Exchange full",
3571
- 116:"No data (for no delay io)",
3572
- 117:"Timer expired",
3573
- 118:"Out of streams resources",
3574
- 119:"Machine is not on the network",
3575
- 120:"Package not installed",
3576
- 121:"The object is remote",
3577
- 122:"Advertise error",
3578
- 123:"Srmount error",
3579
- 124:"Communication error on send",
3580
- 125:"Cross mount point (not really error)",
3581
- 126:"Given log. name not unique",
3582
- 127:"f.d. invalid for this operation",
3583
- 128:"Remote address changed",
3584
- 129:"Can access a needed shared lib",
3585
- 130:"Accessing a corrupted shared lib",
3586
- 131:".lib section in a.out corrupted",
3587
- 132:"Attempting to link in too many libs",
3588
- 133:"Attempting to exec a shared library",
3589
- 135:"Streams pipe error",
3590
- 136:"Too many users",
3591
- 137:"Socket type not supported",
3592
- 138:"Not supported",
3593
- 139:"Protocol family not supported",
3594
- 140:"Can't send after socket shutdown",
3595
- 141:"Too many references",
3596
- 142:"Host is down",
3597
- 148:"No medium (in tape drive)",
3598
- 156:"Level 2 not synchronized",
3599
- };
3400
+
3401
+
3402
+ var strError = (errno) => {
3403
+ return UTF8ToString(_strerror(errno));
3404
+ };
3600
3405
 
3601
3406
  var ERRNO_CODES = {
3602
3407
  'EPERM': 63,
@@ -3721,20 +3526,6 @@ function dbg(text) {
3721
3526
  'EOWNERDEAD': 62,
3722
3527
  'ESTRPIPE': 135,
3723
3528
  };
3724
-
3725
- var demangle = (func) => {
3726
- warnOnce('warning: build with -sDEMANGLE_SUPPORT to link in libcxxabi demangling');
3727
- return func;
3728
- };
3729
- var demangleAll = (text) => {
3730
- var regex =
3731
- /\b_Z[\w\d_]+/g;
3732
- return text.replace(regex,
3733
- function(x) {
3734
- var y = demangle(x);
3735
- return x === y ? x : (y + ' [' + x + ']');
3736
- });
3737
- };
3738
3529
  var FS = {
3739
3530
  root:null,
3740
3531
  mounts:[],
@@ -3746,11 +3537,101 @@ function dbg(text) {
3746
3537
  currentPath:"/",
3747
3538
  initialized:false,
3748
3539
  ignorePermissions:true,
3749
- ErrnoError:null,
3540
+ ErrnoError:class extends Error {
3541
+ // We set the `name` property to be able to identify `FS.ErrnoError`
3542
+ // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
3543
+ // - when using PROXYFS, an error can come from an underlying FS
3544
+ // as different FS objects have their own FS.ErrnoError each,
3545
+ // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
3546
+ // we'll use the reliable test `err.name == "ErrnoError"` instead
3547
+ constructor(errno) {
3548
+ super(runtimeInitialized ? strError(errno) : '');
3549
+ // TODO(sbc): Use the inline member declaration syntax once we
3550
+ // support it in acorn and closure.
3551
+ this.name = 'ErrnoError';
3552
+ this.errno = errno;
3553
+ for (var key in ERRNO_CODES) {
3554
+ if (ERRNO_CODES[key] === errno) {
3555
+ this.code = key;
3556
+ break;
3557
+ }
3558
+ }
3559
+ }
3560
+ },
3750
3561
  genericErrors:{
3751
3562
  },
3752
3563
  filesystems:null,
3753
3564
  syncFSRequests:0,
3565
+ FSStream:class {
3566
+ constructor() {
3567
+ // TODO(https://github.com/emscripten-core/emscripten/issues/21414):
3568
+ // Use inline field declarations.
3569
+ this.shared = {};
3570
+ }
3571
+ get object() {
3572
+ return this.node;
3573
+ }
3574
+ set object(val) {
3575
+ this.node = val;
3576
+ }
3577
+ get isRead() {
3578
+ return (this.flags & 2097155) !== 1;
3579
+ }
3580
+ get isWrite() {
3581
+ return (this.flags & 2097155) !== 0;
3582
+ }
3583
+ get isAppend() {
3584
+ return (this.flags & 1024);
3585
+ }
3586
+ get flags() {
3587
+ return this.shared.flags;
3588
+ }
3589
+ set flags(val) {
3590
+ this.shared.flags = val;
3591
+ }
3592
+ get position() {
3593
+ return this.shared.position;
3594
+ }
3595
+ set position(val) {
3596
+ this.shared.position = val;
3597
+ }
3598
+ },
3599
+ FSNode:class {
3600
+ constructor(parent, name, mode, rdev) {
3601
+ if (!parent) {
3602
+ parent = this; // root node sets parent to itself
3603
+ }
3604
+ this.parent = parent;
3605
+ this.mount = parent.mount;
3606
+ this.mounted = null;
3607
+ this.id = FS.nextInode++;
3608
+ this.name = name;
3609
+ this.mode = mode;
3610
+ this.node_ops = {};
3611
+ this.stream_ops = {};
3612
+ this.rdev = rdev;
3613
+ this.readMode = 292/*292*/ | 73/*73*/;
3614
+ this.writeMode = 146/*146*/;
3615
+ }
3616
+ get read() {
3617
+ return (this.mode & this.readMode) === this.readMode;
3618
+ }
3619
+ set read(val) {
3620
+ val ? this.mode |= this.readMode : this.mode &= ~this.readMode;
3621
+ }
3622
+ get write() {
3623
+ return (this.mode & this.writeMode) === this.writeMode;
3624
+ }
3625
+ set write(val) {
3626
+ val ? this.mode |= this.writeMode : this.mode &= ~this.writeMode;
3627
+ }
3628
+ get isFolder() {
3629
+ return FS.isDir(this.mode);
3630
+ }
3631
+ get isDevice() {
3632
+ return FS.isChrdev(this.mode);
3633
+ }
3634
+ },
3754
3635
  lookupPath(path, opts = {}) {
3755
3636
  path = PATH_FS.resolve(path);
3756
3637
 
@@ -3853,7 +3734,7 @@ function dbg(text) {
3853
3734
  lookupNode(parent, name) {
3854
3735
  var errCode = FS.mayLookup(parent);
3855
3736
  if (errCode) {
3856
- throw new FS.ErrnoError(errCode, parent);
3737
+ throw new FS.ErrnoError(errCode);
3857
3738
  }
3858
3739
  var hash = FS.hashName(parent.id, name);
3859
3740
  for (var node = FS.nameTable[hash]; node; node = node.name_next) {
@@ -3925,6 +3806,7 @@ function dbg(text) {
3925
3806
  return 0;
3926
3807
  },
3927
3808
  mayLookup(dir) {
3809
+ if (!FS.isDir(dir.mode)) return 54;
3928
3810
  var errCode = FS.nodePermissions(dir, 'x');
3929
3811
  if (errCode) return errCode;
3930
3812
  if (!dir.node_ops.lookup) return 2;
@@ -3995,44 +3877,8 @@ function dbg(text) {
3995
3877
  },
3996
3878
  getStream:(fd) => FS.streams[fd],
3997
3879
  createStream(stream, fd = -1) {
3998
- if (!FS.FSStream) {
3999
- FS.FSStream = /** @constructor */ function() {
4000
- this.shared = { };
4001
- };
4002
- FS.FSStream.prototype = {};
4003
- Object.defineProperties(FS.FSStream.prototype, {
4004
- object: {
4005
- /** @this {FS.FSStream} */
4006
- get() { return this.node; },
4007
- /** @this {FS.FSStream} */
4008
- set(val) { this.node = val; }
4009
- },
4010
- isRead: {
4011
- /** @this {FS.FSStream} */
4012
- get() { return (this.flags & 2097155) !== 1; }
4013
- },
4014
- isWrite: {
4015
- /** @this {FS.FSStream} */
4016
- get() { return (this.flags & 2097155) !== 0; }
4017
- },
4018
- isAppend: {
4019
- /** @this {FS.FSStream} */
4020
- get() { return (this.flags & 1024); }
4021
- },
4022
- flags: {
4023
- /** @this {FS.FSStream} */
4024
- get() { return this.shared.flags; },
4025
- /** @this {FS.FSStream} */
4026
- set(val) { this.shared.flags = val; },
4027
- },
4028
- position : {
4029
- /** @this {FS.FSStream} */
4030
- get() { return this.shared.position; },
4031
- /** @this {FS.FSStream} */
4032
- set(val) { this.shared.position = val; },
4033
- },
4034
- });
4035
- }
3880
+ assert(fd >= -1);
3881
+
4036
3882
  // clone it, so we can return an instance of FSStream
4037
3883
  stream = Object.assign(new FS.FSStream(), stream);
4038
3884
  if (fd == -1) {
@@ -4045,6 +3891,11 @@ function dbg(text) {
4045
3891
  closeStream(fd) {
4046
3892
  FS.streams[fd] = null;
4047
3893
  },
3894
+ dupStream(origStream, fd = -1) {
3895
+ var stream = FS.createStream(origStream, fd);
3896
+ stream.stream_ops?.dup?.(stream);
3897
+ return stream;
3898
+ },
4048
3899
  chrdev_stream_ops:{
4049
3900
  open(stream) {
4050
3901
  var device = FS.getDevice(stream.node.rdev);
@@ -4073,7 +3924,7 @@ function dbg(text) {
4073
3924
 
4074
3925
  mounts.push(m);
4075
3926
 
4076
- check.push.apply(check, m.mounts);
3927
+ check.push(...m.mounts);
4077
3928
  }
4078
3929
 
4079
3930
  return mounts;
@@ -4286,7 +4137,7 @@ function dbg(text) {
4286
4137
  // parents must exist
4287
4138
  var lookup, old_dir, new_dir;
4288
4139
 
4289
- // let the errors from non existant directories percolate up
4140
+ // let the errors from non existent directories percolate up
4290
4141
  lookup = FS.lookupPath(old_path, { parent: true });
4291
4142
  old_dir = lookup.node;
4292
4143
  lookup = FS.lookupPath(new_path, { parent: true });
@@ -4352,6 +4203,9 @@ function dbg(text) {
4352
4203
  // do the underlying fs rename
4353
4204
  try {
4354
4205
  old_dir.node_ops.rename(old_node, new_dir, new_name);
4206
+ // update old node (we do this here to avoid each backend
4207
+ // needing to)
4208
+ old_node.parent = new_dir;
4355
4209
  } catch (e) {
4356
4210
  throw e;
4357
4211
  } finally {
@@ -4529,8 +4383,8 @@ function dbg(text) {
4529
4383
  throw new FS.ErrnoError(44);
4530
4384
  }
4531
4385
  flags = typeof flags == 'string' ? FS_modeStringToFlags(flags) : flags;
4532
- mode = typeof mode == 'undefined' ? 438 /* 0666 */ : mode;
4533
4386
  if ((flags & 64)) {
4387
+ mode = typeof mode == 'undefined' ? 438 /* 0666 */ : mode;
4534
4388
  mode = (mode & 4095) | 32768;
4535
4389
  } else {
4536
4390
  mode = 0;
@@ -4750,7 +4604,6 @@ function dbg(text) {
4750
4604
  }
4751
4605
  return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
4752
4606
  },
4753
- munmap:(stream) => 0,
4754
4607
  ioctl(stream, cmd, arg) {
4755
4608
  if (!stream.stream_ops.ioctl) {
4756
4609
  throw new FS.ErrnoError(59);
@@ -4902,47 +4755,12 @@ function dbg(text) {
4902
4755
  assert(stdout.fd === 1, `invalid handle for stdout (${stdout.fd})`);
4903
4756
  assert(stderr.fd === 2, `invalid handle for stderr (${stderr.fd})`);
4904
4757
  },
4905
- ensureErrnoError() {
4906
- if (FS.ErrnoError) return;
4907
- FS.ErrnoError = /** @this{Object} */ function ErrnoError(errno, node) {
4908
- // We set the `name` property to be able to identify `FS.ErrnoError`
4909
- // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
4910
- // - when using PROXYFS, an error can come from an underlying FS
4911
- // as different FS objects have their own FS.ErrnoError each,
4912
- // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
4913
- // we'll use the reliable test `err.name == "ErrnoError"` instead
4914
- this.name = 'ErrnoError';
4915
- this.node = node;
4916
- this.setErrno = /** @this{Object} */ function(errno) {
4917
- this.errno = errno;
4918
- for (var key in ERRNO_CODES) {
4919
- if (ERRNO_CODES[key] === errno) {
4920
- this.code = key;
4921
- break;
4922
- }
4923
- }
4924
- };
4925
- this.setErrno(errno);
4926
- this.message = ERRNO_MESSAGES[errno];
4927
-
4928
- // Try to get a maximally helpful stack trace. On Node.js, getting Error.stack
4929
- // now ensures it shows what we want.
4930
- if (this.stack) {
4931
- // Define the stack property for Node.js 4, which otherwise errors on the next line.
4932
- Object.defineProperty(this, "stack", { value: (new Error).stack, writable: true });
4933
- this.stack = demangleAll(this.stack);
4934
- }
4935
- };
4936
- FS.ErrnoError.prototype = new Error();
4937
- FS.ErrnoError.prototype.constructor = FS.ErrnoError;
4758
+ staticInit() {
4938
4759
  // Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
4939
4760
  [44].forEach((code) => {
4940
4761
  FS.genericErrors[code] = new FS.ErrnoError(code);
4941
4762
  FS.genericErrors[code].stack = '<generic error, no stack>';
4942
4763
  });
4943
- },
4944
- staticInit() {
4945
- FS.ensureErrnoError();
4946
4764
 
4947
4765
  FS.nameTable = new Array(4096);
4948
4766
 
@@ -4960,8 +4778,6 @@ function dbg(text) {
4960
4778
  assert(!FS.init.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)');
4961
4779
  FS.init.initialized = true;
4962
4780
 
4963
- FS.ensureErrnoError();
4964
-
4965
4781
  // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
4966
4782
  Module['stdin'] = input || Module['stdin'];
4967
4783
  Module['stdout'] = output || Module['stdout'];
@@ -5118,122 +4934,113 @@ function dbg(text) {
5118
4934
  if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
5119
4935
  if (typeof XMLHttpRequest != 'undefined') {
5120
4936
  throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
5121
- } else if (read_) {
5122
- // Command-line.
4937
+ } else { // Command-line.
5123
4938
  try {
5124
- // WARNING: Can't read binary files in V8's d8 or tracemonkey's js, as
5125
- // read() will try to parse UTF8.
5126
- obj.contents = intArrayFromString(read_(obj.url), true);
4939
+ obj.contents = readBinary(obj.url);
5127
4940
  obj.usedBytes = obj.contents.length;
5128
4941
  } catch (e) {
5129
4942
  throw new FS.ErrnoError(29);
5130
4943
  }
5131
- } else {
5132
- throw new Error('Cannot load without read() or XMLHttpRequest.');
5133
4944
  }
5134
4945
  },
5135
4946
  createLazyFile(parent, name, url, canRead, canWrite) {
5136
- // Lazy chunked Uint8Array (implements get and length from Uint8Array). Actual getting is abstracted away for eventual reuse.
5137
- /** @constructor */
5138
- function LazyUint8Array() {
5139
- this.lengthKnown = false;
5140
- this.chunks = []; // Loaded chunks. Index is the chunk number
5141
- }
5142
- LazyUint8Array.prototype.get = /** @this{Object} */ function LazyUint8Array_get(idx) {
5143
- if (idx > this.length-1 || idx < 0) {
5144
- return undefined;
4947
+ // Lazy chunked Uint8Array (implements get and length from Uint8Array).
4948
+ // Actual getting is abstracted away for eventual reuse.
4949
+ class LazyUint8Array {
4950
+ constructor() {
4951
+ this.lengthKnown = false;
4952
+ this.chunks = []; // Loaded chunks. Index is the chunk number
5145
4953
  }
5146
- var chunkOffset = idx % this.chunkSize;
5147
- var chunkNum = (idx / this.chunkSize)|0;
5148
- return this.getter(chunkNum)[chunkOffset];
5149
- };
5150
- LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
5151
- this.getter = getter;
5152
- };
5153
- LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
5154
- // Find length
5155
- var xhr = new XMLHttpRequest();
5156
- xhr.open('HEAD', url, false);
5157
- xhr.send(null);
5158
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
5159
- var datalength = Number(xhr.getResponseHeader("Content-length"));
5160
- var header;
5161
- var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
5162
- var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
5163
-
5164
- var chunkSize = 1024*1024; // Chunk size in bytes
5165
-
5166
- if (!hasByteServing) chunkSize = datalength;
5167
-
5168
- // Function to get a range from the remote URL.
5169
- var doXHR = (from, to) => {
5170
- if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
5171
- if (to > datalength-1) throw new Error("only " + datalength + " bytes available! programmer error!");
5172
-
5173
- // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
4954
+ get(idx) {
4955
+ if (idx > this.length-1 || idx < 0) {
4956
+ return undefined;
4957
+ }
4958
+ var chunkOffset = idx % this.chunkSize;
4959
+ var chunkNum = (idx / this.chunkSize)|0;
4960
+ return this.getter(chunkNum)[chunkOffset];
4961
+ }
4962
+ setDataGetter(getter) {
4963
+ this.getter = getter;
4964
+ }
4965
+ cacheLength() {
4966
+ // Find length
5174
4967
  var xhr = new XMLHttpRequest();
5175
- xhr.open('GET', url, false);
5176
- if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
4968
+ xhr.open('HEAD', url, false);
4969
+ xhr.send(null);
4970
+ if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
4971
+ var datalength = Number(xhr.getResponseHeader("Content-length"));
4972
+ var header;
4973
+ var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
4974
+ var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
4975
+
4976
+ var chunkSize = 1024*1024; // Chunk size in bytes
4977
+
4978
+ if (!hasByteServing) chunkSize = datalength;
4979
+
4980
+ // Function to get a range from the remote URL.
4981
+ var doXHR = (from, to) => {
4982
+ if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
4983
+ if (to > datalength-1) throw new Error("only " + datalength + " bytes available! programmer error!");
5177
4984
 
5178
- // Some hints to the browser that we want binary data.
5179
- xhr.responseType = 'arraybuffer';
5180
- if (xhr.overrideMimeType) {
5181
- xhr.overrideMimeType('text/plain; charset=x-user-defined');
4985
+ // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
4986
+ var xhr = new XMLHttpRequest();
4987
+ xhr.open('GET', url, false);
4988
+ if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
4989
+
4990
+ // Some hints to the browser that we want binary data.
4991
+ xhr.responseType = 'arraybuffer';
4992
+ if (xhr.overrideMimeType) {
4993
+ xhr.overrideMimeType('text/plain; charset=x-user-defined');
4994
+ }
4995
+
4996
+ xhr.send(null);
4997
+ if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
4998
+ if (xhr.response !== undefined) {
4999
+ return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
5000
+ }
5001
+ return intArrayFromString(xhr.responseText || '', true);
5002
+ };
5003
+ var lazyArray = this;
5004
+ lazyArray.setDataGetter((chunkNum) => {
5005
+ var start = chunkNum * chunkSize;
5006
+ var end = (chunkNum+1) * chunkSize - 1; // including this byte
5007
+ end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
5008
+ if (typeof lazyArray.chunks[chunkNum] == 'undefined') {
5009
+ lazyArray.chunks[chunkNum] = doXHR(start, end);
5010
+ }
5011
+ if (typeof lazyArray.chunks[chunkNum] == 'undefined') throw new Error('doXHR failed!');
5012
+ return lazyArray.chunks[chunkNum];
5013
+ });
5014
+
5015
+ if (usesGzip || !datalength) {
5016
+ // if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
5017
+ chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file
5018
+ datalength = this.getter(0).length;
5019
+ chunkSize = datalength;
5020
+ out("LazyFiles on gzip forces download of the whole file when length is accessed");
5182
5021
  }
5183
5022
 
5184
- xhr.send(null);
5185
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
5186
- if (xhr.response !== undefined) {
5187
- return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
5023
+ this._length = datalength;
5024
+ this._chunkSize = chunkSize;
5025
+ this.lengthKnown = true;
5026
+ }
5027
+ get length() {
5028
+ if (!this.lengthKnown) {
5029
+ this.cacheLength();
5188
5030
  }
5189
- return intArrayFromString(xhr.responseText || '', true);
5190
- };
5191
- var lazyArray = this;
5192
- lazyArray.setDataGetter((chunkNum) => {
5193
- var start = chunkNum * chunkSize;
5194
- var end = (chunkNum+1) * chunkSize - 1; // including this byte
5195
- end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
5196
- if (typeof lazyArray.chunks[chunkNum] == 'undefined') {
5197
- lazyArray.chunks[chunkNum] = doXHR(start, end);
5031
+ return this._length;
5032
+ }
5033
+ get chunkSize() {
5034
+ if (!this.lengthKnown) {
5035
+ this.cacheLength();
5198
5036
  }
5199
- if (typeof lazyArray.chunks[chunkNum] == 'undefined') throw new Error('doXHR failed!');
5200
- return lazyArray.chunks[chunkNum];
5201
- });
5202
-
5203
- if (usesGzip || !datalength) {
5204
- // if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
5205
- chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file
5206
- datalength = this.getter(0).length;
5207
- chunkSize = datalength;
5208
- out("LazyFiles on gzip forces download of the whole file when length is accessed");
5037
+ return this._chunkSize;
5209
5038
  }
5039
+ }
5210
5040
 
5211
- this._length = datalength;
5212
- this._chunkSize = chunkSize;
5213
- this.lengthKnown = true;
5214
- };
5215
5041
  if (typeof XMLHttpRequest != 'undefined') {
5216
5042
  if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
5217
5043
  var lazyArray = new LazyUint8Array();
5218
- Object.defineProperties(lazyArray, {
5219
- length: {
5220
- get: /** @this{Object} */ function() {
5221
- if (!this.lengthKnown) {
5222
- this.cacheLength();
5223
- }
5224
- return this._length;
5225
- }
5226
- },
5227
- chunkSize: {
5228
- get: /** @this{Object} */ function() {
5229
- if (!this.lengthKnown) {
5230
- this.cacheLength();
5231
- }
5232
- return this._chunkSize;
5233
- }
5234
- }
5235
- });
5236
-
5237
5044
  var properties = { isDevice: false, contents: lazyArray };
5238
5045
  } else {
5239
5046
  var properties = { isDevice: false, url: url };
@@ -5252,7 +5059,7 @@ function dbg(text) {
5252
5059
  // Add a function that defers querying the file size until it is asked the first time.
5253
5060
  Object.defineProperties(node, {
5254
5061
  usedBytes: {
5255
- get: /** @this {FSNode} */ function() { return this.contents.length; }
5062
+ get: function() { return this.contents.length; }
5256
5063
  }
5257
5064
  });
5258
5065
  // override each stream op with one that tries to force load the lazy file first
@@ -5260,9 +5067,9 @@ function dbg(text) {
5260
5067
  var keys = Object.keys(node.stream_ops);
5261
5068
  keys.forEach((key) => {
5262
5069
  var fn = node.stream_ops[key];
5263
- stream_ops[key] = function forceLoadLazyFile() {
5070
+ stream_ops[key] = (...args) => {
5264
5071
  FS.forceLoadFile(node);
5265
- return fn.apply(null, arguments);
5072
+ return fn(...args);
5266
5073
  };
5267
5074
  });
5268
5075
  function writeChunks(stream, buffer, offset, length, position) {
@@ -5343,15 +5150,7 @@ function dbg(text) {
5343
5150
  return PATH.join2(dir, path);
5344
5151
  },
5345
5152
  doStat(func, path, buf) {
5346
- try {
5347
- var stat = func(path);
5348
- } catch (e) {
5349
- if (e && e.node && PATH.normalize(path) !== PATH.normalize(FS.getPath(e.node))) {
5350
- // an error occurred while trying to look up the path; we should just report ENOTDIR
5351
- return -54;
5352
- }
5353
- throw e;
5354
- }
5153
+ var stat = func(path);
5355
5154
  HEAP32[((buf)>>2)] = stat.dev;checkInt32(stat.dev);
5356
5155
  HEAP32[(((buf)+(4))>>2)] = stat.mode;checkInt32(stat.mode);
5357
5156
  HEAPU32[(((buf)+(8))>>2)] = stat.nlink;checkInt32(stat.nlink);
@@ -5384,23 +5183,15 @@ function dbg(text) {
5384
5183
  var buffer = HEAPU8.slice(addr, addr + len);
5385
5184
  FS.msync(stream, buffer, offset, len, flags);
5386
5185
  },
5387
- varargs:undefined,
5388
- get() {
5389
- assert(SYSCALLS.varargs != undefined);
5390
- // the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
5391
- var ret = HEAP32[((+SYSCALLS.varargs)>>2)];
5392
- SYSCALLS.varargs += 4;
5393
- return ret;
5186
+ getStreamFromFD(fd) {
5187
+ var stream = FS.getStreamChecked(fd);
5188
+ return stream;
5394
5189
  },
5395
- getp() { return SYSCALLS.get() },
5190
+ varargs:undefined,
5396
5191
  getStr(ptr) {
5397
5192
  var ret = UTF8ToString(ptr);
5398
5193
  return ret;
5399
5194
  },
5400
- getStreamFromFD(fd) {
5401
- var stream = FS.getStreamChecked(fd);
5402
- return stream;
5403
- },
5404
5195
  };
5405
5196
  function ___syscall_chmod(path, mode) {
5406
5197
  try {
@@ -5465,10 +5256,16 @@ function dbg(text) {
5465
5256
  }
5466
5257
  }
5467
5258
 
5468
- var setErrNo = (value) => {
5469
- HEAP32[((___errno_location())>>2)] = value;checkInt32(value);
5470
- return value;
5471
- };
5259
+ /** @suppress {duplicate } */
5260
+ function syscallGetVarargI() {
5261
+ assert(SYSCALLS.varargs != undefined);
5262
+ // the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
5263
+ var ret = HEAP32[((+SYSCALLS.varargs)>>2)];
5264
+ SYSCALLS.varargs += 4;
5265
+ return ret;
5266
+ }
5267
+ var syscallGetVarargP = syscallGetVarargI;
5268
+
5472
5269
 
5473
5270
  function ___syscall_fcntl64(fd, cmd, varargs) {
5474
5271
  SYSCALLS.varargs = varargs;
@@ -5477,7 +5274,7 @@ function dbg(text) {
5477
5274
  var stream = SYSCALLS.getStreamFromFD(fd);
5478
5275
  switch (cmd) {
5479
5276
  case 0: {
5480
- var arg = SYSCALLS.get();
5277
+ var arg = syscallGetVarargI();
5481
5278
  if (arg < 0) {
5482
5279
  return -28;
5483
5280
  }
@@ -5485,7 +5282,7 @@ function dbg(text) {
5485
5282
  arg++;
5486
5283
  }
5487
5284
  var newStream;
5488
- newStream = FS.createStream(stream, arg);
5285
+ newStream = FS.dupStream(stream, arg);
5489
5286
  return newStream.fd;
5490
5287
  }
5491
5288
  case 1:
@@ -5494,31 +5291,22 @@ function dbg(text) {
5494
5291
  case 3:
5495
5292
  return stream.flags;
5496
5293
  case 4: {
5497
- var arg = SYSCALLS.get();
5294
+ var arg = syscallGetVarargI();
5498
5295
  stream.flags |= arg;
5499
5296
  return 0;
5500
5297
  }
5501
- case 5: {
5502
- var arg = SYSCALLS.getp();
5298
+ case 12: {
5299
+ var arg = syscallGetVarargP();
5503
5300
  var offset = 0;
5504
5301
  // We're always unlocked.
5505
5302
  HEAP16[(((arg)+(offset))>>1)] = 2;checkInt16(2);
5506
5303
  return 0;
5507
5304
  }
5508
- case 6:
5509
- case 7:
5305
+ case 13:
5306
+ case 14:
5510
5307
  return 0; // Pretend that the locking is successful.
5511
- case 16:
5512
- case 8:
5513
- return -28; // These are for sockets. We don't have them fully implemented yet.
5514
- case 9:
5515
- // musl trusts getown return values, due to a bug where they must be, as they overlap with errors. just return -1 here, so fcntl() returns that, and we set errno ourselves.
5516
- setErrNo(28);
5517
- return -1;
5518
- default: {
5519
- return -28;
5520
- }
5521
5308
  }
5309
+ return -28;
5522
5310
  } catch (e) {
5523
5311
  if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
5524
5312
  return -e.errno;
@@ -5536,14 +5324,13 @@ function dbg(text) {
5536
5324
  }
5537
5325
  }
5538
5326
 
5539
-
5540
5327
  var convertI32PairToI53Checked = (lo, hi) => {
5541
5328
  assert(lo == (lo >>> 0) || lo == (lo|0)); // lo should either be a i32 or a u32
5542
5329
  assert(hi === (hi|0)); // hi should be a i32
5543
5330
  return ((hi + 0x200000) >>> 0 < 0x400001 - !!lo) ? (lo >>> 0) + hi * 4294967296 : NaN;
5544
5331
  };
5545
5332
  function ___syscall_ftruncate64(fd,length_low, length_high) {
5546
- var length = convertI32PairToI53Checked(length_low, length_high);;
5333
+ var length = convertI32PairToI53Checked(length_low, length_high);
5547
5334
 
5548
5335
 
5549
5336
  try {
@@ -5563,7 +5350,6 @@ function dbg(text) {
5563
5350
  assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
5564
5351
  return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
5565
5352
  };
5566
-
5567
5353
  function ___syscall_getcwd(buf, size) {
5568
5354
  try {
5569
5355
 
@@ -5623,13 +5409,14 @@ function dbg(text) {
5623
5409
  }
5624
5410
  }
5625
5411
 
5412
+
5626
5413
  function ___syscall_openat(dirfd, path, flags, varargs) {
5627
5414
  SYSCALLS.varargs = varargs;
5628
5415
  try {
5629
5416
 
5630
5417
  path = SYSCALLS.getStr(path);
5631
5418
  path = SYSCALLS.calculateAt(dirfd, path);
5632
- var mode = varargs ? SYSCALLS.get() : 0;
5419
+ var mode = varargs ? syscallGetVarargI() : 0;
5633
5420
  return FS.open(path, flags, mode).fd;
5634
5421
  } catch (e) {
5635
5422
  if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
@@ -5732,9 +5519,15 @@ function dbg(text) {
5732
5519
  }
5733
5520
  }
5734
5521
 
5522
+ var __abort_js = () => {
5523
+ abort('native code called abort()');
5524
+ };
5525
+
5735
5526
  var nowIsMonotonic = 1;
5736
5527
  var __emscripten_get_now_is_monotonic = () => nowIsMonotonic;
5737
5528
 
5529
+ var __emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num);
5530
+
5738
5531
  var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
5739
5532
 
5740
5533
  var MONTH_DAYS_LEAP_CUMULATIVE = [0,31,60,91,121,152,182,213,244,274,305,335];
@@ -5749,7 +5542,7 @@ function dbg(text) {
5749
5542
  };
5750
5543
 
5751
5544
  function __localtime_js(time_low, time_high,tmPtr) {
5752
- var time = convertI32PairToI53Checked(time_low, time_high);;
5545
+ var time = convertI32PairToI53Checked(time_low, time_high);
5753
5546
 
5754
5547
 
5755
5548
  var date = new Date(time*1000);
@@ -5780,7 +5573,7 @@ function dbg(text) {
5780
5573
 
5781
5574
 
5782
5575
  function __mmap_js(len,prot,flags,fd,offset_low, offset_high,allocated,addr) {
5783
- var offset = convertI32PairToI53Checked(offset_low, offset_high);;
5576
+ var offset = convertI32PairToI53Checked(offset_low, offset_high);
5784
5577
 
5785
5578
 
5786
5579
  try {
@@ -5800,21 +5593,16 @@ function dbg(text) {
5800
5593
  }
5801
5594
 
5802
5595
 
5803
-
5804
-
5805
5596
  function __munmap_js(addr,len,prot,flags,fd,offset_low, offset_high) {
5806
- var offset = convertI32PairToI53Checked(offset_low, offset_high);;
5597
+ var offset = convertI32PairToI53Checked(offset_low, offset_high);
5807
5598
 
5808
5599
 
5809
5600
  try {
5810
5601
 
5811
- if (isNaN(offset)) return 61;
5812
5602
  var stream = SYSCALLS.getStreamFromFD(fd);
5813
5603
  if (prot & 2) {
5814
5604
  SYSCALLS.doMsync(addr, stream, len, flags, offset);
5815
5605
  }
5816
- FS.munmap(stream);
5817
- // implicitly return 0
5818
5606
  } catch (e) {
5819
5607
  if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
5820
5608
  return -e.errno;
@@ -5823,14 +5611,7 @@ function dbg(text) {
5823
5611
  }
5824
5612
 
5825
5613
 
5826
-
5827
- var stringToNewUTF8 = (str) => {
5828
- var size = lengthBytesUTF8(str) + 1;
5829
- var ret = _malloc(size);
5830
- if (ret) stringToUTF8(str, ret, size);
5831
- return ret;
5832
- };
5833
- var __tzset_js = (timezone, daylight, tzname) => {
5614
+ var __tzset_js = (timezone, daylight, std_name, dst_name) => {
5834
5615
  // TODO: Use (malleable) environment variables instead of system settings.
5835
5616
  var currentYear = new Date().getFullYear();
5836
5617
  var winter = new Date(currentYear, 0, 1);
@@ -5838,9 +5619,12 @@ function dbg(text) {
5838
5619
  var winterOffset = winter.getTimezoneOffset();
5839
5620
  var summerOffset = summer.getTimezoneOffset();
5840
5621
 
5841
- // Local standard timezone offset. Local standard time is not adjusted for daylight savings.
5842
- // This code uses the fact that getTimezoneOffset returns a greater value during Standard Time versus Daylight Saving Time (DST).
5843
- // Thus it determines the expected output during Standard Time, and it compares whether the output of the given date the same (Standard) or less (DST).
5622
+ // Local standard timezone offset. Local standard time is not adjusted for
5623
+ // daylight savings. This code uses the fact that getTimezoneOffset returns
5624
+ // a greater value during Standard Time versus Daylight Saving Time (DST).
5625
+ // Thus it determines the expected output during Standard Time, and it
5626
+ // compares whether the output of the given date the same (Standard) or less
5627
+ // (DST).
5844
5628
  var stdTimezoneOffset = Math.max(winterOffset, summerOffset);
5845
5629
 
5846
5630
  // timezone is specified as seconds west of UTC ("The external variable
@@ -5852,28 +5636,34 @@ function dbg(text) {
5852
5636
 
5853
5637
  HEAP32[((daylight)>>2)] = Number(winterOffset != summerOffset);checkInt32(Number(winterOffset != summerOffset));
5854
5638
 
5855
- function extractZone(date) {
5856
- var match = date.toTimeString().match(/\(([A-Za-z ]+)\)$/);
5857
- return match ? match[1] : "GMT";
5858
- };
5859
- var winterName = extractZone(winter);
5860
- var summerName = extractZone(summer);
5861
- var winterNamePtr = stringToNewUTF8(winterName);
5862
- var summerNamePtr = stringToNewUTF8(summerName);
5639
+ var extractZone = (timezoneOffset) => {
5640
+ // Why inverse sign?
5641
+ // Read here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
5642
+ var sign = timezoneOffset >= 0 ? "-" : "+";
5643
+
5644
+ var absOffset = Math.abs(timezoneOffset)
5645
+ var hours = String(Math.floor(absOffset / 60)).padStart(2, "0");
5646
+ var minutes = String(absOffset % 60).padStart(2, "0");
5647
+
5648
+ return `UTC${sign}${hours}${minutes}`;
5649
+ }
5650
+
5651
+ var winterName = extractZone(winterOffset);
5652
+ var summerName = extractZone(summerOffset);
5653
+ assert(winterName);
5654
+ assert(summerName);
5655
+ assert(lengthBytesUTF8(winterName) <= 16, `timezone name truncated to fit in TZNAME_MAX (${winterName})`);
5656
+ assert(lengthBytesUTF8(summerName) <= 16, `timezone name truncated to fit in TZNAME_MAX (${summerName})`);
5863
5657
  if (summerOffset < winterOffset) {
5864
5658
  // Northern hemisphere
5865
- HEAPU32[((tzname)>>2)] = winterNamePtr;checkInt32(winterNamePtr);
5866
- HEAPU32[(((tzname)+(4))>>2)] = summerNamePtr;checkInt32(summerNamePtr);
5659
+ stringToUTF8(winterName, std_name, 17);
5660
+ stringToUTF8(summerName, dst_name, 17);
5867
5661
  } else {
5868
- HEAPU32[((tzname)>>2)] = summerNamePtr;checkInt32(summerNamePtr);
5869
- HEAPU32[(((tzname)+(4))>>2)] = winterNamePtr;checkInt32(winterNamePtr);
5662
+ stringToUTF8(winterName, dst_name, 17);
5663
+ stringToUTF8(summerName, std_name, 17);
5870
5664
  }
5871
5665
  };
5872
5666
 
5873
- var _abort = () => {
5874
- abort('native code called abort()');
5875
- };
5876
-
5877
5667
  var _emscripten_date_now = () => Date.now();
5878
5668
 
5879
5669
  var getHeapMax = () =>
@@ -5891,8 +5681,6 @@ function dbg(text) {
5891
5681
  _emscripten_get_now = () => performance.now();
5892
5682
  ;
5893
5683
 
5894
- var _emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num);
5895
-
5896
5684
 
5897
5685
 
5898
5686
  var growMemory = (size) => {
@@ -6007,12 +5795,11 @@ function dbg(text) {
6007
5795
  var stringToAscii = (str, buffer) => {
6008
5796
  for (var i = 0; i < str.length; ++i) {
6009
5797
  assert(str.charCodeAt(i) === (str.charCodeAt(i) & 0xff));
6010
- HEAP8[((buffer++)>>0)] = str.charCodeAt(i);checkInt8(str.charCodeAt(i));
5798
+ HEAP8[buffer++] = str.charCodeAt(i);checkInt8(str.charCodeAt(i));
6011
5799
  }
6012
5800
  // Null-terminate the string
6013
- HEAP8[((buffer)>>0)] = 0;checkInt8(0);
5801
+ HEAP8[buffer] = 0;checkInt8(0);
6014
5802
  };
6015
-
6016
5803
  var _environ_get = (__environ, environ_buf) => {
6017
5804
  var bufSize = 0;
6018
5805
  getEnvStrings().forEach((string, i) => {
@@ -6024,7 +5811,6 @@ function dbg(text) {
6024
5811
  return 0;
6025
5812
  };
6026
5813
 
6027
-
6028
5814
  var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
6029
5815
  var strings = getEnvStrings();
6030
5816
  HEAPU32[((penviron_count)>>2)] = strings.length;checkInt32(strings.length);
@@ -6061,7 +5847,7 @@ function dbg(text) {
6061
5847
  FS.isLink(stream.mode) ? 7 :
6062
5848
  4;
6063
5849
  }
6064
- HEAP8[((pbuf)>>0)] = type;checkInt8(type);
5850
+ HEAP8[pbuf] = type;checkInt8(type);
6065
5851
  HEAP16[(((pbuf)+(2))>>1)] = flags;checkInt16(flags);
6066
5852
  (tempI64 = [rightsBase>>>0,(tempDouble = rightsBase,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((pbuf)+(8))>>2)] = tempI64[0],HEAP32[(((pbuf)+(12))>>2)] = tempI64[1]);checkInt64(rightsBase);
6067
5853
  (tempI64 = [rightsInheriting>>>0,(tempDouble = rightsInheriting,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((pbuf)+(16))>>2)] = tempI64[0],HEAP32[(((pbuf)+(20))>>2)] = tempI64[1]);checkInt64(rightsInheriting);
@@ -6083,7 +5869,7 @@ function dbg(text) {
6083
5869
  if (curr < 0) return -1;
6084
5870
  ret += curr;
6085
5871
  if (curr < len) break; // nothing more to read
6086
- if (typeof offset !== 'undefined') {
5872
+ if (typeof offset != 'undefined') {
6087
5873
  offset += curr;
6088
5874
  }
6089
5875
  }
@@ -6105,7 +5891,7 @@ function dbg(text) {
6105
5891
 
6106
5892
 
6107
5893
  function _fd_seek(fd,offset_low, offset_high,whence,newOffset) {
6108
- var offset = convertI32PairToI53Checked(offset_low, offset_high);;
5894
+ var offset = convertI32PairToI53Checked(offset_low, offset_high);
6109
5895
 
6110
5896
 
6111
5897
  try {
@@ -6147,7 +5933,7 @@ function dbg(text) {
6147
5933
  var curr = FS.write(stream, HEAP8, ptr, len, offset);
6148
5934
  if (curr < 0) return -1;
6149
5935
  ret += curr;
6150
- if (typeof offset !== 'undefined') {
5936
+ if (typeof offset != 'undefined') {
6151
5937
  offset += curr;
6152
5938
  }
6153
5939
  }
@@ -6180,6 +5966,8 @@ function dbg(text) {
6180
5966
  };
6181
5967
 
6182
5968
 
5969
+
5970
+ var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
6183
5971
  var stringToUTF8OnStack = (str) => {
6184
5972
  var size = lengthBytesUTF8(str) + 1;
6185
5973
  var ret = stackAlloc(size);
@@ -6188,6 +5976,9 @@ function dbg(text) {
6188
5976
  };
6189
5977
 
6190
5978
 
5979
+
5980
+
5981
+
6191
5982
  /**
6192
5983
  * @param {string|null=} returnType
6193
5984
  * @param {Array=} argTypes
@@ -6236,7 +6027,7 @@ function dbg(text) {
6236
6027
  }
6237
6028
  }
6238
6029
  }
6239
- var ret = func.apply(null, cArgs);
6030
+ var ret = func(...cArgs);
6240
6031
  function onDone(ret) {
6241
6032
  if (stack !== 0) stackRestore(stack);
6242
6033
  return convertReturnValue(ret);
@@ -6252,16 +6043,19 @@ function dbg(text) {
6252
6043
  * @param {Object=} opts
6253
6044
  */
6254
6045
  var cwrap = (ident, returnType, argTypes, opts) => {
6255
- return function() {
6256
- return ccall(ident, returnType, argTypes, arguments, opts);
6257
- }
6046
+ return (...args) => ccall(ident, returnType, argTypes, args, opts);
6258
6047
  };
6259
6048
 
6260
6049
 
6050
+
6051
+
6052
+
6261
6053
  var ALLOC_NORMAL = 0;
6262
6054
 
6263
6055
  var ALLOC_STACK = 1;
6264
6056
 
6057
+
6058
+
6265
6059
  var allocate = (slab, allocator) => {
6266
6060
  var ret;
6267
6061
  assert(typeof allocator == 'number', 'allocate no longer takes a type argument')
@@ -6281,6 +6075,7 @@ function dbg(text) {
6281
6075
  };
6282
6076
 
6283
6077
 
6078
+
6284
6079
  var allocateUTF8OnStack = stringToUTF8OnStack;
6285
6080
 
6286
6081
  var functionsInTableMap;
@@ -6289,6 +6084,7 @@ function dbg(text) {
6289
6084
 
6290
6085
  var wasmTableMirror = [];
6291
6086
 
6087
+ /** @type {WebAssembly.Table} */
6292
6088
  var wasmTable;
6293
6089
  var getWasmTableEntry = (funcPtr) => {
6294
6090
  var func = wasmTableMirror[funcPtr];
@@ -6296,14 +6092,14 @@ function dbg(text) {
6296
6092
  if (funcPtr >= wasmTableMirror.length) wasmTableMirror.length = funcPtr + 1;
6297
6093
  wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr);
6298
6094
  }
6299
- assert(wasmTable.get(funcPtr) == func, "JavaScript-side Wasm function table mirror is out of date!");
6095
+ assert(wasmTable.get(funcPtr) == func, 'JavaScript-side Wasm function table mirror is out of date!');
6300
6096
  return func;
6301
6097
  };
6302
6098
 
6303
6099
 
6304
6100
  var setWasmTableEntry = (idx, func) => {
6305
6101
  wasmTable.set(idx, func);
6306
- // With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overriden to return wrapped
6102
+ // With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overridden to return wrapped
6307
6103
  // functions so we need to call it here to retrieve the potential wrapper correctly
6308
6104
  // instead of just storing 'func' directly into wasmTableMirror
6309
6105
  wasmTableMirror[idx] = wasmTable.get(idx);
@@ -6400,7 +6196,7 @@ function dbg(text) {
6400
6196
  ];
6401
6197
  // Write the overall length of the type section followed by the body
6402
6198
  uleb128Encode(typeSectionBody.length, bytes);
6403
- bytes.push.apply(bytes, typeSectionBody);
6199
+ bytes.push(...typeSectionBody);
6404
6200
 
6405
6201
  // The rest of the module is static
6406
6202
  bytes.push(
@@ -6504,51 +6300,6 @@ function dbg(text) {
6504
6300
  return ret;
6505
6301
  };
6506
6302
 
6507
- var FSNode = /** @constructor */ function(parent, name, mode, rdev) {
6508
- if (!parent) {
6509
- parent = this; // root node sets parent to itself
6510
- }
6511
- this.parent = parent;
6512
- this.mount = parent.mount;
6513
- this.mounted = null;
6514
- this.id = FS.nextInode++;
6515
- this.name = name;
6516
- this.mode = mode;
6517
- this.node_ops = {};
6518
- this.stream_ops = {};
6519
- this.rdev = rdev;
6520
- };
6521
- var readMode = 292/*292*/ | 73/*73*/;
6522
- var writeMode = 146/*146*/;
6523
- Object.defineProperties(FSNode.prototype, {
6524
- read: {
6525
- get: /** @this{FSNode} */function() {
6526
- return (this.mode & readMode) === readMode;
6527
- },
6528
- set: /** @this{FSNode} */function(val) {
6529
- val ? this.mode |= readMode : this.mode &= ~readMode;
6530
- }
6531
- },
6532
- write: {
6533
- get: /** @this{FSNode} */function() {
6534
- return (this.mode & writeMode) === writeMode;
6535
- },
6536
- set: /** @this{FSNode} */function(val) {
6537
- val ? this.mode |= writeMode : this.mode &= ~writeMode;
6538
- }
6539
- },
6540
- isFolder: {
6541
- get: /** @this{FSNode} */function() {
6542
- return FS.isDir(this.mode);
6543
- }
6544
- },
6545
- isDevice: {
6546
- get: /** @this{FSNode} */function() {
6547
- return FS.isChrdev(this.mode);
6548
- }
6549
- }
6550
- });
6551
- FS.FSNode = FSNode;
6552
6303
  FS.createPreloadedFile = FS_createPreloadedFile;
6553
6304
  FS.staticInit();;
6554
6305
  function checkIncomingModuleAPI() {
@@ -6594,8 +6345,12 @@ var wasmImports = {
6594
6345
  /** @export */
6595
6346
  __syscall_utimensat: ___syscall_utimensat,
6596
6347
  /** @export */
6348
+ _abort_js: __abort_js,
6349
+ /** @export */
6597
6350
  _emscripten_get_now_is_monotonic: __emscripten_get_now_is_monotonic,
6598
6351
  /** @export */
6352
+ _emscripten_memcpy_js: __emscripten_memcpy_js,
6353
+ /** @export */
6599
6354
  _localtime_js: __localtime_js,
6600
6355
  /** @export */
6601
6356
  _mmap_js: __mmap_js,
@@ -6604,16 +6359,12 @@ var wasmImports = {
6604
6359
  /** @export */
6605
6360
  _tzset_js: __tzset_js,
6606
6361
  /** @export */
6607
- abort: _abort,
6608
- /** @export */
6609
6362
  emscripten_date_now: _emscripten_date_now,
6610
6363
  /** @export */
6611
6364
  emscripten_get_heap_max: _emscripten_get_heap_max,
6612
6365
  /** @export */
6613
6366
  emscripten_get_now: _emscripten_get_now,
6614
6367
  /** @export */
6615
- emscripten_memcpy_js: _emscripten_memcpy_js,
6616
- /** @export */
6617
6368
  emscripten_resize_heap: _emscripten_resize_heap,
6618
6369
  /** @export */
6619
6370
  environ_get: _environ_get,
@@ -6633,79 +6384,78 @@ var wasmImports = {
6633
6384
  fd_write: _fd_write
6634
6385
  };
6635
6386
  var wasmExports = createWasm();
6636
- var ___wasm_call_ctors = createExportWrapper('__wasm_call_ctors');
6637
- var _sqlite3_free = Module['_sqlite3_free'] = createExportWrapper('sqlite3_free');
6638
- var _sqlite3_value_text = Module['_sqlite3_value_text'] = createExportWrapper('sqlite3_value_text');
6639
- var ___errno_location = createExportWrapper('__errno_location');
6640
- var _sqlite3_prepare_v2 = Module['_sqlite3_prepare_v2'] = createExportWrapper('sqlite3_prepare_v2');
6641
- var _sqlite3_step = Module['_sqlite3_step'] = createExportWrapper('sqlite3_step');
6642
- var _sqlite3_reset = Module['_sqlite3_reset'] = createExportWrapper('sqlite3_reset');
6643
- var _sqlite3_exec = Module['_sqlite3_exec'] = createExportWrapper('sqlite3_exec');
6644
- var _sqlite3_finalize = Module['_sqlite3_finalize'] = createExportWrapper('sqlite3_finalize');
6645
- var _sqlite3_column_name = Module['_sqlite3_column_name'] = createExportWrapper('sqlite3_column_name');
6646
- var _sqlite3_column_text = Module['_sqlite3_column_text'] = createExportWrapper('sqlite3_column_text');
6647
- var _sqlite3_column_type = Module['_sqlite3_column_type'] = createExportWrapper('sqlite3_column_type');
6648
- var _sqlite3_errmsg = Module['_sqlite3_errmsg'] = createExportWrapper('sqlite3_errmsg');
6649
- var _sqlite3_clear_bindings = Module['_sqlite3_clear_bindings'] = createExportWrapper('sqlite3_clear_bindings');
6650
- var _sqlite3_value_blob = Module['_sqlite3_value_blob'] = createExportWrapper('sqlite3_value_blob');
6651
- var _sqlite3_value_bytes = Module['_sqlite3_value_bytes'] = createExportWrapper('sqlite3_value_bytes');
6652
- var _sqlite3_value_double = Module['_sqlite3_value_double'] = createExportWrapper('sqlite3_value_double');
6653
- var _sqlite3_value_int = Module['_sqlite3_value_int'] = createExportWrapper('sqlite3_value_int');
6654
- var _sqlite3_value_type = Module['_sqlite3_value_type'] = createExportWrapper('sqlite3_value_type');
6655
- var _sqlite3_result_blob = Module['_sqlite3_result_blob'] = createExportWrapper('sqlite3_result_blob');
6656
- var _sqlite3_result_double = Module['_sqlite3_result_double'] = createExportWrapper('sqlite3_result_double');
6657
- var _sqlite3_result_error = Module['_sqlite3_result_error'] = createExportWrapper('sqlite3_result_error');
6658
- var _sqlite3_result_int = Module['_sqlite3_result_int'] = createExportWrapper('sqlite3_result_int');
6659
- var _sqlite3_result_int64 = Module['_sqlite3_result_int64'] = createExportWrapper('sqlite3_result_int64');
6660
- var _sqlite3_result_null = Module['_sqlite3_result_null'] = createExportWrapper('sqlite3_result_null');
6661
- var _sqlite3_result_text = Module['_sqlite3_result_text'] = createExportWrapper('sqlite3_result_text');
6662
- var _sqlite3_aggregate_context = Module['_sqlite3_aggregate_context'] = createExportWrapper('sqlite3_aggregate_context');
6663
- var _sqlite3_column_count = Module['_sqlite3_column_count'] = createExportWrapper('sqlite3_column_count');
6664
- var _sqlite3_data_count = Module['_sqlite3_data_count'] = createExportWrapper('sqlite3_data_count');
6665
- var _sqlite3_column_blob = Module['_sqlite3_column_blob'] = createExportWrapper('sqlite3_column_blob');
6666
- var _sqlite3_column_bytes = Module['_sqlite3_column_bytes'] = createExportWrapper('sqlite3_column_bytes');
6667
- var _sqlite3_column_double = Module['_sqlite3_column_double'] = createExportWrapper('sqlite3_column_double');
6668
- var _sqlite3_bind_blob = Module['_sqlite3_bind_blob'] = createExportWrapper('sqlite3_bind_blob');
6669
- var _sqlite3_bind_double = Module['_sqlite3_bind_double'] = createExportWrapper('sqlite3_bind_double');
6670
- var _sqlite3_bind_int = Module['_sqlite3_bind_int'] = createExportWrapper('sqlite3_bind_int');
6671
- var _sqlite3_bind_text = Module['_sqlite3_bind_text'] = createExportWrapper('sqlite3_bind_text');
6672
- var _sqlite3_bind_parameter_index = Module['_sqlite3_bind_parameter_index'] = createExportWrapper('sqlite3_bind_parameter_index');
6673
- var _sqlite3_sql = Module['_sqlite3_sql'] = createExportWrapper('sqlite3_sql');
6674
- var _sqlite3_normalized_sql = Module['_sqlite3_normalized_sql'] = createExportWrapper('sqlite3_normalized_sql');
6675
- var _sqlite3_changes = Module['_sqlite3_changes'] = createExportWrapper('sqlite3_changes');
6676
- var _sqlite3_close_v2 = Module['_sqlite3_close_v2'] = createExportWrapper('sqlite3_close_v2');
6677
- var _sqlite3_create_function_v2 = Module['_sqlite3_create_function_v2'] = createExportWrapper('sqlite3_create_function_v2');
6678
- var _sqlite3_open = Module['_sqlite3_open'] = createExportWrapper('sqlite3_open');
6679
- var _malloc = Module['_malloc'] = createExportWrapper('malloc');
6680
- var _free = Module['_free'] = createExportWrapper('free');
6681
- var _RegisterExtensionFunctions = Module['_RegisterExtensionFunctions'] = createExportWrapper('RegisterExtensionFunctions');
6682
- var _fflush = Module['_fflush'] = createExportWrapper('fflush');
6683
- var _emscripten_builtin_memalign = createExportWrapper('emscripten_builtin_memalign');
6684
- var setTempRet0 = createExportWrapper('setTempRet0');
6387
+ var ___wasm_call_ctors = createExportWrapper('__wasm_call_ctors', 0);
6388
+ var _sqlite3_free = Module['_sqlite3_free'] = createExportWrapper('sqlite3_free', 1);
6389
+ var _sqlite3_value_text = Module['_sqlite3_value_text'] = createExportWrapper('sqlite3_value_text', 1);
6390
+ var _sqlite3_prepare_v2 = Module['_sqlite3_prepare_v2'] = createExportWrapper('sqlite3_prepare_v2', 5);
6391
+ var _sqlite3_step = Module['_sqlite3_step'] = createExportWrapper('sqlite3_step', 1);
6392
+ var _sqlite3_reset = Module['_sqlite3_reset'] = createExportWrapper('sqlite3_reset', 1);
6393
+ var _sqlite3_exec = Module['_sqlite3_exec'] = createExportWrapper('sqlite3_exec', 5);
6394
+ var _sqlite3_finalize = Module['_sqlite3_finalize'] = createExportWrapper('sqlite3_finalize', 1);
6395
+ var _sqlite3_column_name = Module['_sqlite3_column_name'] = createExportWrapper('sqlite3_column_name', 2);
6396
+ var _sqlite3_column_text = Module['_sqlite3_column_text'] = createExportWrapper('sqlite3_column_text', 2);
6397
+ var _sqlite3_column_type = Module['_sqlite3_column_type'] = createExportWrapper('sqlite3_column_type', 2);
6398
+ var _sqlite3_errmsg = Module['_sqlite3_errmsg'] = createExportWrapper('sqlite3_errmsg', 1);
6399
+ var _sqlite3_clear_bindings = Module['_sqlite3_clear_bindings'] = createExportWrapper('sqlite3_clear_bindings', 1);
6400
+ var _sqlite3_value_blob = Module['_sqlite3_value_blob'] = createExportWrapper('sqlite3_value_blob', 1);
6401
+ var _sqlite3_value_bytes = Module['_sqlite3_value_bytes'] = createExportWrapper('sqlite3_value_bytes', 1);
6402
+ var _sqlite3_value_double = Module['_sqlite3_value_double'] = createExportWrapper('sqlite3_value_double', 1);
6403
+ var _sqlite3_value_int = Module['_sqlite3_value_int'] = createExportWrapper('sqlite3_value_int', 1);
6404
+ var _sqlite3_value_type = Module['_sqlite3_value_type'] = createExportWrapper('sqlite3_value_type', 1);
6405
+ var _sqlite3_result_blob = Module['_sqlite3_result_blob'] = createExportWrapper('sqlite3_result_blob', 4);
6406
+ var _sqlite3_result_double = Module['_sqlite3_result_double'] = createExportWrapper('sqlite3_result_double', 2);
6407
+ var _sqlite3_result_error = Module['_sqlite3_result_error'] = createExportWrapper('sqlite3_result_error', 3);
6408
+ var _sqlite3_result_int = Module['_sqlite3_result_int'] = createExportWrapper('sqlite3_result_int', 2);
6409
+ var _sqlite3_result_int64 = Module['_sqlite3_result_int64'] = createExportWrapper('sqlite3_result_int64', 3);
6410
+ var _sqlite3_result_null = Module['_sqlite3_result_null'] = createExportWrapper('sqlite3_result_null', 1);
6411
+ var _sqlite3_result_text = Module['_sqlite3_result_text'] = createExportWrapper('sqlite3_result_text', 4);
6412
+ var _sqlite3_aggregate_context = Module['_sqlite3_aggregate_context'] = createExportWrapper('sqlite3_aggregate_context', 2);
6413
+ var _sqlite3_column_count = Module['_sqlite3_column_count'] = createExportWrapper('sqlite3_column_count', 1);
6414
+ var _sqlite3_data_count = Module['_sqlite3_data_count'] = createExportWrapper('sqlite3_data_count', 1);
6415
+ var _sqlite3_column_blob = Module['_sqlite3_column_blob'] = createExportWrapper('sqlite3_column_blob', 2);
6416
+ var _sqlite3_column_bytes = Module['_sqlite3_column_bytes'] = createExportWrapper('sqlite3_column_bytes', 2);
6417
+ var _sqlite3_column_double = Module['_sqlite3_column_double'] = createExportWrapper('sqlite3_column_double', 2);
6418
+ var _sqlite3_bind_blob = Module['_sqlite3_bind_blob'] = createExportWrapper('sqlite3_bind_blob', 5);
6419
+ var _sqlite3_bind_double = Module['_sqlite3_bind_double'] = createExportWrapper('sqlite3_bind_double', 3);
6420
+ var _sqlite3_bind_int = Module['_sqlite3_bind_int'] = createExportWrapper('sqlite3_bind_int', 3);
6421
+ var _sqlite3_bind_text = Module['_sqlite3_bind_text'] = createExportWrapper('sqlite3_bind_text', 5);
6422
+ var _sqlite3_bind_parameter_index = Module['_sqlite3_bind_parameter_index'] = createExportWrapper('sqlite3_bind_parameter_index', 2);
6423
+ var _sqlite3_sql = Module['_sqlite3_sql'] = createExportWrapper('sqlite3_sql', 1);
6424
+ var _sqlite3_normalized_sql = Module['_sqlite3_normalized_sql'] = createExportWrapper('sqlite3_normalized_sql', 1);
6425
+ var _sqlite3_changes = Module['_sqlite3_changes'] = createExportWrapper('sqlite3_changes', 1);
6426
+ var _sqlite3_close_v2 = Module['_sqlite3_close_v2'] = createExportWrapper('sqlite3_close_v2', 1);
6427
+ var _sqlite3_create_function_v2 = Module['_sqlite3_create_function_v2'] = createExportWrapper('sqlite3_create_function_v2', 9);
6428
+ var _sqlite3_open = Module['_sqlite3_open'] = createExportWrapper('sqlite3_open', 2);
6429
+ var _strerror = createExportWrapper('strerror', 1);
6430
+ var _malloc = Module['_malloc'] = createExportWrapper('malloc', 1);
6431
+ var _free = Module['_free'] = createExportWrapper('free', 1);
6432
+ var _RegisterExtensionFunctions = Module['_RegisterExtensionFunctions'] = createExportWrapper('RegisterExtensionFunctions', 1);
6433
+ var _fflush = createExportWrapper('fflush', 1);
6434
+ var _emscripten_builtin_memalign = createExportWrapper('emscripten_builtin_memalign', 2);
6435
+ var __emscripten_tempret_set = createExportWrapper('_emscripten_tempret_set', 1);
6685
6436
  var _emscripten_stack_init = () => (_emscripten_stack_init = wasmExports['emscripten_stack_init'])();
6686
6437
  var _emscripten_stack_get_free = () => (_emscripten_stack_get_free = wasmExports['emscripten_stack_get_free'])();
6687
6438
  var _emscripten_stack_get_base = () => (_emscripten_stack_get_base = wasmExports['emscripten_stack_get_base'])();
6688
6439
  var _emscripten_stack_get_end = () => (_emscripten_stack_get_end = wasmExports['emscripten_stack_get_end'])();
6689
- var stackSave = createExportWrapper('stackSave');
6690
- var stackRestore = createExportWrapper('stackRestore');
6691
- var stackAlloc = createExportWrapper('stackAlloc');
6440
+ var __emscripten_stack_restore = (a0) => (__emscripten_stack_restore = wasmExports['_emscripten_stack_restore'])(a0);
6441
+ var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['_emscripten_stack_alloc'])(a0);
6692
6442
  var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();
6693
- var ___set_stack_limits = Module['___set_stack_limits'] = createExportWrapper('__set_stack_limits');
6694
- var dynCall_iiiij = Module['dynCall_iiiij'] = createExportWrapper('dynCall_iiiij');
6695
- var dynCall_iij = Module['dynCall_iij'] = createExportWrapper('dynCall_iij');
6696
- var dynCall_iijii = Module['dynCall_iijii'] = createExportWrapper('dynCall_iijii');
6697
- var dynCall_iiji = Module['dynCall_iiji'] = createExportWrapper('dynCall_iiji');
6698
- var dynCall_iiiiiij = Module['dynCall_iiiiiij'] = createExportWrapper('dynCall_iiiiiij');
6699
- var dynCall_viji = Module['dynCall_viji'] = createExportWrapper('dynCall_viji');
6700
- var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji');
6443
+ var ___set_stack_limits = Module['___set_stack_limits'] = createExportWrapper('__set_stack_limits', 2);
6444
+ var dynCall_iiiij = Module['dynCall_iiiij'] = createExportWrapper('dynCall_iiiij', 6);
6445
+ var dynCall_iij = Module['dynCall_iij'] = createExportWrapper('dynCall_iij', 4);
6446
+ var dynCall_iijii = Module['dynCall_iijii'] = createExportWrapper('dynCall_iijii', 6);
6447
+ var dynCall_iiji = Module['dynCall_iiji'] = createExportWrapper('dynCall_iiji', 5);
6448
+ var dynCall_iiiiiij = Module['dynCall_iiiiiij'] = createExportWrapper('dynCall_iiiiiij', 8);
6449
+ var dynCall_viji = Module['dynCall_viji'] = createExportWrapper('dynCall_viji', 5);
6450
+ var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5);
6701
6451
 
6702
6452
 
6703
6453
  // include: postamble.js
6704
6454
  // === Auto-generated postamble setup entry stuff ===
6705
6455
 
6706
- Module['stackAlloc'] = stackAlloc;
6707
6456
  Module['stackSave'] = stackSave;
6708
6457
  Module['stackRestore'] = stackRestore;
6458
+ Module['stackAlloc'] = stackAlloc;
6709
6459
  Module['cwrap'] = cwrap;
6710
6460
  Module['addFunction'] = addFunction;
6711
6461
  Module['removeFunction'] = removeFunction;
@@ -6722,6 +6472,8 @@ var missingLibrarySymbols = [
6722
6472
  'readI53FromU64',
6723
6473
  'convertI32PairToI53',
6724
6474
  'convertU32PairToI53',
6475
+ 'getTempRet0',
6476
+ 'setTempRet0',
6725
6477
  'exitJS',
6726
6478
  'arraySum',
6727
6479
  'addDays',
@@ -6731,13 +6483,9 @@ var missingLibrarySymbols = [
6731
6483
  'inetNtop6',
6732
6484
  'readSockaddr',
6733
6485
  'writeSockaddr',
6734
- 'getHostByName',
6735
- 'getCallstack',
6736
6486
  'emscriptenLog',
6737
- 'convertPCtoSourceLocation',
6738
6487
  'readEmAsmArgs',
6739
6488
  'jstoi_q',
6740
- 'jstoi_s',
6741
6489
  'listenOnce',
6742
6490
  'autoResumeAudioContext',
6743
6491
  'dynCallLegacy',
@@ -6750,7 +6498,6 @@ var missingLibrarySymbols = [
6750
6498
  'callUserCallback',
6751
6499
  'maybeExit',
6752
6500
  'asmjsMangle',
6753
- 'handleAllocatorInit',
6754
6501
  'HandleAllocator',
6755
6502
  'getNativeTypeSize',
6756
6503
  'STACK_SIZE',
@@ -6770,10 +6517,10 @@ var missingLibrarySymbols = [
6770
6517
  'UTF32ToString',
6771
6518
  'stringToUTF32',
6772
6519
  'lengthBytesUTF32',
6520
+ 'stringToNewUTF8',
6773
6521
  'registerKeyEventCallback',
6774
6522
  'maybeCStringToJsString',
6775
6523
  'findEventTarget',
6776
- 'findCanvasEventTarget',
6777
6524
  'getBoundingClientRect',
6778
6525
  'fillMouseEventData',
6779
6526
  'registerMouseEventCallback',
@@ -6806,7 +6553,6 @@ var missingLibrarySymbols = [
6806
6553
  'registerTouchEventCallback',
6807
6554
  'fillGamepadEventData',
6808
6555
  'registerGamepadEventCallback',
6809
- 'disableGamepadApiIfItThrows',
6810
6556
  'registerBeforeUnloadEventCallback',
6811
6557
  'fillBatteryEventData',
6812
6558
  'battery',
@@ -6814,7 +6560,8 @@ var missingLibrarySymbols = [
6814
6560
  'setCanvasElementSize',
6815
6561
  'getCanvasElementSize',
6816
6562
  'jsStackTrace',
6817
- 'stackTrace',
6563
+ 'getCallstack',
6564
+ 'convertPCtoSourceLocation',
6818
6565
  'checkWasiClock',
6819
6566
  'wasiRightsToMuslOFlags',
6820
6567
  'wasiOFlagsToMuslOFlags',
@@ -6837,7 +6584,7 @@ var missingLibrarySymbols = [
6837
6584
  'FS_mkdirTree',
6838
6585
  '_setNetworkCallback',
6839
6586
  'heapObjectForWebGLType',
6840
- 'heapAccessShiftForWebGLHeap',
6587
+ 'toTypedArrayIndex',
6841
6588
  'webgl_enable_ANGLE_instanced_arrays',
6842
6589
  'webgl_enable_OES_vertex_array_object',
6843
6590
  'webgl_enable_WEBGL_draw_buffers',
@@ -6846,7 +6593,6 @@ var missingLibrarySymbols = [
6846
6593
  'computeUnpackAlignedImageSize',
6847
6594
  'colorChannelsInGlTextureFormat',
6848
6595
  'emscriptenWebGLGetTexPixelData',
6849
- '__glGenObject',
6850
6596
  'emscriptenWebGLGetUniform',
6851
6597
  'webglGetUniformLocation',
6852
6598
  'webglPrepareUniformLocationsBeforeFirstUse',
@@ -6856,11 +6602,11 @@ var missingLibrarySymbols = [
6856
6602
  'writeGLArray',
6857
6603
  'registerWebGlEventCallback',
6858
6604
  'runAndAbortIfError',
6859
- 'SDL_unicode',
6860
- 'SDL_ttfContext',
6861
- 'SDL_audio',
6862
6605
  'writeStringToMemory',
6863
6606
  'writeAsciiToMemory',
6607
+ 'setErrNo',
6608
+ 'demangle',
6609
+ 'stackTrace',
6864
6610
  ];
6865
6611
  missingLibrarySymbols.forEach(missingLibrarySymbol)
6866
6612
 
@@ -6873,20 +6619,12 @@ var unexportedSymbols = [
6873
6619
  'addOnPostRun',
6874
6620
  'addRunDependency',
6875
6621
  'removeRunDependency',
6876
- 'FS_createFolder',
6877
- 'FS_createPath',
6878
- 'FS_createLazyFile',
6879
- 'FS_createLink',
6880
- 'FS_createDevice',
6881
- 'FS_readFile',
6882
6622
  'out',
6883
6623
  'err',
6884
6624
  'callMain',
6885
6625
  'abort',
6886
6626
  'wasmMemory',
6887
6627
  'wasmExports',
6888
- 'getTempRet0',
6889
- 'setTempRet0',
6890
6628
  'writeStackCookie',
6891
6629
  'checkStackCookie',
6892
6630
  'readI53FromI64',
@@ -6904,8 +6642,7 @@ var unexportedSymbols = [
6904
6642
  'isLeapYear',
6905
6643
  'ydayFromDate',
6906
6644
  'ERRNO_CODES',
6907
- 'ERRNO_MESSAGES',
6908
- 'setErrNo',
6645
+ 'strError',
6909
6646
  'DNS',
6910
6647
  'Protocols',
6911
6648
  'Sockets',
@@ -6913,8 +6650,8 @@ var unexportedSymbols = [
6913
6650
  'randomFill',
6914
6651
  'timers',
6915
6652
  'warnOnce',
6916
- 'UNWIND_CACHE',
6917
6653
  'readEmAsmArgsArray',
6654
+ 'jstoi_s',
6918
6655
  'getExecutableName',
6919
6656
  'asyncLoad',
6920
6657
  'alignMemory',
@@ -6944,15 +6681,14 @@ var unexportedSymbols = [
6944
6681
  'intArrayFromString',
6945
6682
  'stringToAscii',
6946
6683
  'UTF16Decoder',
6947
- 'stringToNewUTF8',
6948
6684
  'stringToUTF8OnStack',
6949
6685
  'writeArrayToMemory',
6950
6686
  'JSEvents',
6951
6687
  'specialHTMLTargets',
6688
+ 'findCanvasEventTarget',
6952
6689
  'currentFullscreenStrategy',
6953
6690
  'restoreOldWindowedStyle',
6954
- 'demangle',
6955
- 'demangleAll',
6691
+ 'UNWIND_CACHE',
6956
6692
  'ExitStatus',
6957
6693
  'getEnvStrings',
6958
6694
  'doReadv',
@@ -6962,6 +6698,7 @@ var unexportedSymbols = [
6962
6698
  'exceptionLast',
6963
6699
  'exceptionCaught',
6964
6700
  'Browser',
6701
+ 'getPreloadedImageData__data',
6965
6702
  'wget',
6966
6703
  'SYSCALLS',
6967
6704
  'preloadPlugins',
@@ -6970,8 +6707,12 @@ var unexportedSymbols = [
6970
6707
  'FS_getMode',
6971
6708
  'FS_stdin_getChar_buffer',
6972
6709
  'FS_stdin_getChar',
6710
+ 'FS_createPath',
6711
+ 'FS_createDevice',
6712
+ 'FS_readFile',
6973
6713
  'FS',
6974
6714
  'FS_createDataFile',
6715
+ 'FS_createLazyFile',
6975
6716
  'MEMFS',
6976
6717
  'TTY',
6977
6718
  'PIPEFS',
@@ -6980,7 +6721,6 @@ var unexportedSymbols = [
6980
6721
  'miniTempWebGLFloatBuffers',
6981
6722
  'miniTempWebGLIntBuffers',
6982
6723
  'GL',
6983
- 'emscripten_webgl_power_preferences',
6984
6724
  'AL',
6985
6725
  'GLUT',
6986
6726
  'EGL',
@@ -6990,6 +6730,8 @@ var unexportedSymbols = [
6990
6730
  'SDL_gfx',
6991
6731
  'ALLOC_STACK',
6992
6732
  'allocateUTF8',
6733
+ 'print',
6734
+ 'printErr',
6993
6735
  ];
6994
6736
  unexportedSymbols.forEach(unexportedRuntimeSymbol);
6995
6737
 
@@ -7038,7 +6780,7 @@ function run() {
7038
6780
 
7039
6781
  initRuntime();
7040
6782
 
7041
- if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
6783
+ Module['onRuntimeInitialized']?.();
7042
6784
 
7043
6785
  assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
7044
6786
 
@@ -7108,10 +6850,10 @@ if (Module['preInit']) {
7108
6850
 
7109
6851
  run();
7110
6852
 
7111
-
7112
6853
  // end include: postamble.js
7113
6854
 
7114
6855
 
6856
+
7115
6857
  // The shell-pre.js and emcc-generated code goes above
7116
6858
  return Module;
7117
6859
  }); // The end of the promise being returned
@@ -7169,6 +6911,11 @@ function onModuleReady(SQL) {
7169
6911
  id: data["id"],
7170
6912
  results: db.exec(data["sql"], data["params"], config)
7171
6913
  });
6914
+ case "getRowsModified":
6915
+ return postMessage({
6916
+ id: data["id"],
6917
+ rowsModified: db.getRowsModified()
6918
+ });
7172
6919
  case "each":
7173
6920
  if (db === null) {
7174
6921
  createDb();