@copasi/copasijs 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/copasijs.js CHANGED
@@ -42,18 +42,18 @@ async function createCpsModule(moduleArg = {}) {
42
42
  }
43
43
 
44
44
  const currentSafariVersion = userAgent.includes("Safari/") && !userAgent.includes("Chrome/") && userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/) ? humanReadableVersionToPacked(userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/)[1]) : TARGET_NOT_SUPPORTED;
45
- if (currentSafariVersion < 150000) {
46
- throw new Error(`This emscripten-generated code requires Safari v${ packedVersionToHumanReadable(150000) } (detected v${currentSafariVersion})`);
45
+ if (currentSafariVersion < 150400) {
46
+ throw new Error(`This emscripten-generated code requires Safari v${ packedVersionToHumanReadable(150400) } (detected v${currentSafariVersion})`);
47
47
  }
48
48
 
49
49
  const currentFirefoxVersion = userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/) ? parseFloat(userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED;
50
- if (currentFirefoxVersion < 79) {
51
- throw new Error(`This emscripten-generated code requires Firefox v79 (detected v${currentFirefoxVersion})`);
50
+ if (currentFirefoxVersion < 92) {
51
+ throw new Error(`This emscripten-generated code requires Firefox v92 (detected v${currentFirefoxVersion})`);
52
52
  }
53
53
 
54
54
  const currentChromeVersion = userAgent.match(/Chrome\/(\d+(?:\.\d+)?)/) ? parseFloat(userAgent.match(/Chrome\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED;
55
- if (currentChromeVersion < 85) {
56
- throw new Error(`This emscripten-generated code requires Chrome v85 (detected v${currentChromeVersion})`);
55
+ if (currentChromeVersion < 93) {
56
+ throw new Error(`This emscripten-generated code requires Chrome v93 (detected v${currentChromeVersion})`);
57
57
  }
58
58
  })();
59
59
 
@@ -516,8 +516,8 @@ async function getWasmBinary(binaryFile) {
516
516
  if (!wasmBinary) {
517
517
  // Fetch the binary using readAsync
518
518
  try {
519
- var response = await readAsync(binaryFile);
520
- return new Uint8Array(response);
519
+ // Await so a rejection is caught and falls back to getBinarySync.
520
+ return await readAsync(binaryFile);
521
521
  } catch {
522
522
  // Fall back to getBinarySync below;
523
523
  }
@@ -635,7 +635,6 @@ var tempI64;
635
635
 
636
636
  // Begin JS library code
637
637
 
638
-
639
638
  class ExitStatus {
640
639
  name = 'ExitStatus';
641
640
  constructor(status) {
@@ -643,16 +642,12 @@ var tempI64;
643
642
  this.status = status;
644
643
  }
645
644
  }
646
-
647
645
  /** @type {!Int32Array} */
648
646
  var HEAP32;
649
-
650
647
  /** @type {!Int8Array} */
651
648
  var HEAP8;
652
-
653
649
  /** @type {!Uint32Array} */
654
650
  var HEAPU32;
655
-
656
651
  var callRuntimeCallbacks = (callbacks) => {
657
652
  while (callbacks.length > 0) {
658
653
  // Pass the module as the first argument.
@@ -661,24 +656,18 @@ var tempI64;
661
656
  };
662
657
  var onPostRuns = [];
663
658
  var addOnPostRun = (cb) => onPostRuns.push(cb);
664
-
665
659
  var onPreRuns = [];
666
660
  var addOnPreRun = (cb) => onPreRuns.push(cb);
667
661
 
668
-
669
662
  var noExitRuntime = true;
670
-
671
663
  function ptrToString(ptr) {
672
664
  assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`);
673
665
  // Convert to 32-bit unsigned value
674
666
  ptr >>>= 0;
675
667
  return '0x' + ptr.toString(16).padStart(8, '0');
676
668
  }
677
-
678
669
  var stackRestore = (val) => __emscripten_stack_restore(val);
679
-
680
670
  var stackSave = () => _emscripten_stack_get_current();
681
-
682
671
  var warnOnce = (text) => {
683
672
  warnOnce.shown ||= {};
684
673
  if (!warnOnce.shown[text]) {
@@ -687,11 +676,10 @@ var tempI64;
687
676
  }
688
677
  };
689
678
 
690
-
691
-
679
+ /** @type {!Uint8Array} */
680
+ var HEAPU8;
692
681
  var UTF8Decoder = globalThis.TextDecoder && new TextDecoder();
693
682
 
694
-
695
683
  /**
696
684
  * heapOrArray is either a regular array, or a JavaScript typed array view.
697
685
  * @param {number} idx
@@ -710,7 +698,6 @@ var tempI64;
710
698
  return idx;
711
699
  };
712
700
 
713
-
714
701
  /**
715
702
  * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
716
703
  * array that contains uint8 values, returns a copy of that string as a
@@ -756,9 +743,8 @@ var tempI64;
756
743
  }
757
744
  return str;
758
745
  };
759
-
760
- /** @type {!Uint8Array} */
761
- var HEAPU8;
746
+ var UTF8ToString_cache = {
747
+ };
762
748
 
763
749
  /**
764
750
  * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
@@ -775,17 +761,27 @@ var tempI64;
775
761
  */
776
762
  var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => {
777
763
  assert(typeof ptr === 'number', `UTF8ToString expects a number (got ${typeof ptr})`);
778
- return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : '';
779
- };
780
- var ___assert_fail = (condition, filename, line, func) =>
781
- abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
782
-
783
- var exceptionCaught = [];
784
764
 
765
+ // Only cache full string reads (when maxBytesToRead is omitted).
766
+ // We use `== null` here since its shorter than `=== undefined`
767
+ var useCache = maxBytesToRead == null && ptr >= 1024 && ptr < 966500;
768
+ if (useCache) {
769
+ var rtn = UTF8ToString_cache[ptr];
770
+ if (rtn != null) {
771
+ return rtn;
772
+ }
773
+ }
785
774
 
786
- var uncaughtExceptionCount = 0;
775
+ var rtn = ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : '';
787
776
 
777
+ if (useCache) {
778
+ UTF8ToString_cache[ptr] = rtn;
779
+ }
788
780
 
781
+ return rtn;
782
+ };
783
+ var ___assert_fail = (condition, filename, line, func) =>
784
+ abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
789
785
  class ExceptionInfo {
790
786
  // excPtr - Thrown object pointer to wrap. Metadata pointer is calculated from it.
791
787
  constructor(excPtr) {
@@ -842,6 +838,8 @@ var tempI64;
842
838
  return HEAPU32[(((this.ptr)+(16))>>2)];
843
839
  }
844
840
  }
841
+ var exceptionCaught = [];
842
+ var uncaughtExceptionCount = 0;
845
843
  var ___cxa_begin_catch = (ptr) => {
846
844
  var info = new ExceptionInfo(ptr);
847
845
  if (!info.get_caught()) {
@@ -852,10 +850,6 @@ var tempI64;
852
850
  exceptionCaught.push(info);
853
851
  return ___cxa_get_exception_ptr(ptr);
854
852
  };
855
-
856
-
857
-
858
-
859
853
  var exceptionLast = null;
860
854
  var ___cxa_end_catch = () => {
861
855
  // Clear state flag.
@@ -867,11 +861,7 @@ var tempI64;
867
861
  ___cxa_decrement_exception_refcount(info.excPtr);
868
862
  exceptionLast = null; // XXX in decRef?
869
863
  };
870
-
871
864
  var setTempRet0 = (val) => __emscripten_tempret_set(val);
872
-
873
-
874
-
875
865
  var findMatchingCatch = (args) => {
876
866
  var thrown = exceptionLast?.excPtr;
877
867
  if (!thrown) {
@@ -908,15 +898,8 @@ var tempI64;
908
898
  return thrown;
909
899
  };
910
900
  var ___cxa_find_matching_catch_2 = () => findMatchingCatch([]);
911
-
912
901
  var ___cxa_find_matching_catch_3 = (arg0) => findMatchingCatch([arg0]);
913
-
914
902
  var ___cxa_find_matching_catch_4 = (arg0,arg1) => findMatchingCatch([arg0,arg1]);
915
-
916
-
917
-
918
-
919
-
920
903
  var __Unwind_RaiseException = (ex) => {
921
904
  throw ex;
922
905
  };
@@ -933,18 +916,8 @@ var tempI64;
933
916
  ptr = exceptionLast = new CppException(ptr);
934
917
  __Unwind_RaiseException(ptr);
935
918
  };
936
-
937
-
938
-
939
-
940
-
941
-
942
-
943
-
944
-
919
+ var decrementExceptionRefcount = (exn) => ___cxa_decrement_exception_refcount(exn.excPtr);
945
920
  var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
946
-
947
-
948
921
  var getExceptionMessageCommon = (ptr) => {
949
922
  var sp = stackSave();
950
923
  var type_addr_addr = stackAlloc(4);
@@ -963,11 +936,7 @@ var tempI64;
963
936
  return [type, message];
964
937
  };
965
938
  var getExceptionMessage = (exn) => getExceptionMessageCommon(exn.excPtr);
966
-
967
- var decrementExceptionRefcount = (exn) => ___cxa_decrement_exception_refcount(exn.excPtr);
968
-
969
939
  var incrementExceptionRefcount = (exn) => ___cxa_increment_exception_refcount(exn.excPtr);
970
-
971
940
  var ___cxa_throw = (ptr, type, destructor) => {
972
941
  var info = new ExceptionInfo(ptr);
973
942
  // Initialize ExceptionInfo content after it was allocated in __cxa_allocate_exception.
@@ -977,10 +946,7 @@ var tempI64;
977
946
  uncaughtExceptionCount++;
978
947
  __Unwind_RaiseException(ptr);
979
948
  };
980
-
981
949
  var ___cxa_uncaught_exceptions = () => uncaughtExceptionCount;
982
-
983
-
984
950
  var __Unwind_Resume = (ex) => {
985
951
  throw ex;
986
952
  };
@@ -988,7 +954,168 @@ var tempI64;
988
954
  ptr = exceptionLast ??= new CppException(ptr);
989
955
  __Unwind_Resume(ptr);
990
956
  };
991
-
957
+ const EBADF = 8;
958
+ const EINVAL = 28;
959
+ const EACCES = 2;
960
+ const EAGAIN = 6;
961
+ const EBUSY = 10;
962
+ const EEXIST = 20;
963
+ const EFBIG = 22;
964
+ const EIO = 29;
965
+ const EISDIR = 31;
966
+ const ELOOP = 32;
967
+ const EMFILE = 33;
968
+ const EMLINK = 34;
969
+ const ENODEV = 43;
970
+ const ENOENT = 44;
971
+ const ENOMEM = 48;
972
+ const ENOSYS = 52;
973
+ const ENOTDIR = 54;
974
+ const ENOTEMPTY = 55;
975
+ const ENOTTY = 59;
976
+ const EPERM = 63;
977
+ var ERRNO_CODES = {
978
+ 'EPERM': 63,
979
+ 'ENOENT': 44,
980
+ 'ESRCH': 71,
981
+ 'EINTR': 27,
982
+ 'EIO': 29,
983
+ 'ENXIO': 60,
984
+ 'E2BIG': 1,
985
+ 'ENOEXEC': 45,
986
+ 'EBADF': 8,
987
+ 'ECHILD': 12,
988
+ 'EAGAIN': 6,
989
+ 'EWOULDBLOCK': 6,
990
+ 'ENOMEM': 48,
991
+ 'EACCES': 2,
992
+ 'EFAULT': 21,
993
+ 'ENOTBLK': 105,
994
+ 'EBUSY': 10,
995
+ 'EEXIST': 20,
996
+ 'EXDEV': 75,
997
+ 'ENODEV': 43,
998
+ 'ENOTDIR': 54,
999
+ 'EISDIR': 31,
1000
+ 'EINVAL': 28,
1001
+ 'ENFILE': 41,
1002
+ 'EMFILE': 33,
1003
+ 'ENOTTY': 59,
1004
+ 'ETXTBSY': 74,
1005
+ 'EFBIG': 22,
1006
+ 'ENOSPC': 51,
1007
+ 'ESPIPE': 70,
1008
+ 'EROFS': 69,
1009
+ 'EMLINK': 34,
1010
+ 'EPIPE': 64,
1011
+ 'EDOM': 18,
1012
+ 'ERANGE': 68,
1013
+ 'ENOMSG': 49,
1014
+ 'EIDRM': 24,
1015
+ 'ECHRNG': 106,
1016
+ 'EL2NSYNC': 156,
1017
+ 'EL3HLT': 107,
1018
+ 'EL3RST': 108,
1019
+ 'ELNRNG': 109,
1020
+ 'EUNATCH': 110,
1021
+ 'ENOCSI': 111,
1022
+ 'EL2HLT': 112,
1023
+ 'EDEADLK': 16,
1024
+ 'ENOLCK': 46,
1025
+ 'EBADE': 113,
1026
+ 'EBADR': 114,
1027
+ 'EXFULL': 115,
1028
+ 'ENOANO': 104,
1029
+ 'EBADRQC': 103,
1030
+ 'EBADSLT': 102,
1031
+ 'EDEADLOCK': 16,
1032
+ 'EBFONT': 101,
1033
+ 'ENOSTR': 100,
1034
+ 'ENODATA': 116,
1035
+ 'ETIME': 117,
1036
+ 'ENOSR': 118,
1037
+ 'ENONET': 119,
1038
+ 'ENOPKG': 120,
1039
+ 'EREMOTE': 121,
1040
+ 'ENOLINK': 47,
1041
+ 'EADV': 122,
1042
+ 'ESRMNT': 123,
1043
+ 'ECOMM': 124,
1044
+ 'EPROTO': 65,
1045
+ 'EMULTIHOP': 36,
1046
+ 'EDOTDOT': 125,
1047
+ 'EBADMSG': 9,
1048
+ 'ENOTUNIQ': 126,
1049
+ 'EBADFD': 127,
1050
+ 'EREMCHG': 128,
1051
+ 'ELIBACC': 129,
1052
+ 'ELIBBAD': 130,
1053
+ 'ELIBSCN': 131,
1054
+ 'ELIBMAX': 132,
1055
+ 'ELIBEXEC': 133,
1056
+ 'ENOSYS': 52,
1057
+ 'ENOTEMPTY': 55,
1058
+ 'ENAMETOOLONG': 37,
1059
+ 'ELOOP': 32,
1060
+ 'EOPNOTSUPP': 138,
1061
+ 'EPFNOSUPPORT': 139,
1062
+ 'ECONNRESET': 15,
1063
+ 'ENOBUFS': 42,
1064
+ 'EAFNOSUPPORT': 5,
1065
+ 'EPROTOTYPE': 67,
1066
+ 'ENOTSOCK': 57,
1067
+ 'ENOPROTOOPT': 50,
1068
+ 'ESHUTDOWN': 140,
1069
+ 'ECONNREFUSED': 14,
1070
+ 'EADDRINUSE': 3,
1071
+ 'ECONNABORTED': 13,
1072
+ 'ENETUNREACH': 40,
1073
+ 'ENETDOWN': 38,
1074
+ 'ETIMEDOUT': 73,
1075
+ 'EHOSTDOWN': 142,
1076
+ 'EHOSTUNREACH': 23,
1077
+ 'EINPROGRESS': 26,
1078
+ 'EALREADY': 7,
1079
+ 'EDESTADDRREQ': 17,
1080
+ 'EMSGSIZE': 35,
1081
+ 'EPROTONOSUPPORT': 66,
1082
+ 'ESOCKTNOSUPPORT': 137,
1083
+ 'EADDRNOTAVAIL': 4,
1084
+ 'ENETRESET': 39,
1085
+ 'EISCONN': 30,
1086
+ 'ENOTCONN': 53,
1087
+ 'ETOOMANYREFS': 141,
1088
+ 'EUSERS': 136,
1089
+ 'EDQUOT': 19,
1090
+ 'ESTALE': 72,
1091
+ 'ENOTSUP': 138,
1092
+ 'ENOMEDIUM': 148,
1093
+ 'EILSEQ': 25,
1094
+ 'EOVERFLOW': 61,
1095
+ 'ECANCELED': 11,
1096
+ 'ENOTRECOVERABLE': 56,
1097
+ 'EOWNERDEAD': 62,
1098
+ 'ESTRPIPE': 135,
1099
+ };
1100
+ const ESPIPE = 70;
1101
+ const EXDEV = 75;
1102
+ const FS_MAX_OPEN_FDS = 4096;
1103
+ var FS_createDataFile = (...args) => FS.createDataFile(...args);
1104
+ var preloadPlugins = [];
1105
+ var FS_handledByPreloadPlugin = async (byteArray, fullname) => {
1106
+ // Ensure plugins are ready.
1107
+ if (typeof Browser !== 'undefined') Browser.init();
1108
+
1109
+ for (var plugin of preloadPlugins) {
1110
+ if (plugin['canHandle'](fullname)) {
1111
+ assert(plugin['handle'].constructor.name === 'AsyncFunction', 'Filesystem plugin handlers must be async functions (See #24914)')
1112
+ return plugin['handle'](byteArray, fullname);
1113
+ }
1114
+ }
1115
+ // If no plugin handled this file then return the original/unmodified
1116
+ // byteArray.
1117
+ return byteArray;
1118
+ };
992
1119
  var PATH = {
993
1120
  isAbs:(path) => path.charAt(0) === '/',
994
1121
  splitPath:(filename) => {
@@ -1049,15 +1176,6 @@ var tempI64;
1049
1176
  join:(...paths) => PATH.normalize(paths.join('/')),
1050
1177
  join2:(l, r) => PATH.normalize(l + '/' + r),
1051
1178
  };
1052
-
1053
- var initRandomFill = () => {
1054
-
1055
- return (view) => (crypto.getRandomValues(view), 0);
1056
- };
1057
- var randomFill = (view) => (randomFill = initRandomFill())(view);
1058
-
1059
-
1060
-
1061
1179
  var PATH_FS = {
1062
1180
  resolve:(...args) => {
1063
1181
  var resolvedPath = '',
@@ -1111,32 +1229,118 @@ relative:(from, to) => {
1111
1229
  return outputParts.join('/');
1112
1230
  },
1113
1231
  };
1232
+ var dependenciesPromise = null;
1233
+ var dependenciesPromiseResolve = null;
1234
+ var resolveRunDependencies = async () => dependenciesPromise;
1235
+ var runDependencies = 0;
1236
+ var runDependencyTracking = {
1237
+ };
1238
+ var runDependencyWatcher = null;
1239
+ var removeRunDependency = (id) => {
1240
+ runDependencies--;
1114
1241
 
1242
+ Module['monitorRunDependencies']?.(runDependencies);
1115
1243
 
1244
+ assert(id, 'removeRunDependency requires an ID');
1245
+ assert(runDependencyTracking[id]);
1246
+ delete runDependencyTracking[id];
1247
+ if (!runDependencies) {
1248
+ if (runDependencyWatcher !== null) {
1249
+ clearInterval(runDependencyWatcher);
1250
+ runDependencyWatcher = null;
1251
+ }
1252
+ dependenciesPromiseResolve();
1253
+ }
1254
+ };
1255
+ var addRunDependency = (id) => {
1256
+ if (!runDependencies) {
1257
+ dependenciesPromise = new Promise((resolve) => dependenciesPromiseResolve = resolve);
1258
+ }
1259
+ runDependencies++;
1260
+
1261
+ Module['monitorRunDependencies']?.(runDependencies);
1262
+
1263
+ assert(id, 'addRunDependency requires an ID')
1264
+ assert(!runDependencyTracking[id]);
1265
+ runDependencyTracking[id] = 1;
1266
+ if (!runDependencyWatcher && globalThis.setInterval) {
1267
+ // Check for missing dependencies every few seconds
1268
+ runDependencyWatcher = setInterval(() => {
1269
+ if (ABORT) {
1270
+ clearInterval(runDependencyWatcher);
1271
+ runDependencyWatcher = null;
1272
+ return;
1273
+ }
1274
+ var shown = false;
1275
+ for (var dep in runDependencyTracking) {
1276
+ if (!shown) {
1277
+ shown = true;
1278
+ err('still waiting on run dependencies:');
1279
+ }
1280
+ err(`dependency: ${dep}`);
1281
+ }
1282
+ if (shown) {
1283
+ err('(end of list)');
1284
+ }
1285
+ }, 10_000);
1286
+ }
1287
+ };
1288
+ var asyncLoad = async (url) => {
1289
+ var arrayBuffer = await readAsync(url);
1290
+ assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
1291
+ return new Uint8Array(arrayBuffer);
1292
+ };
1293
+ var getUniqueRunDependency = (id) => {
1294
+ var orig = id;
1295
+ while (1) {
1296
+ if (!runDependencyTracking[id]) return id;
1297
+ id = orig + Math.random();
1298
+ }
1299
+ };
1300
+ var FS_preloadFile = async (parent, name, url, canRead = undefined, canWrite = undefined, dontCreateFile = undefined, canOwn = undefined, preFinish = undefined) => {
1301
+ // TODO we should allow people to just pass in a complete filename instead
1302
+ // of parent and name being that we just join them anyways
1303
+ var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
1304
+ var dep = getUniqueRunDependency(`cp ${fullname}`); // might have several active requests for the same fullname
1305
+ addRunDependency(dep);
1116
1306
 
1117
- var FS_stdin_getChar_buffer = [];
1307
+ try {
1308
+ var byteArray = url;
1309
+ if (typeof url === 'string') {
1310
+ byteArray = await asyncLoad(url);
1311
+ }
1118
1312
 
1313
+ byteArray = await FS_handledByPreloadPlugin(byteArray, fullname);
1314
+ preFinish?.();
1315
+ if (!dontCreateFile) {
1316
+ FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
1317
+ }
1318
+ } finally {
1319
+ removeRunDependency(dep);
1320
+ }
1321
+ };
1322
+ var FS_createPreloadedFile = (parent, name, url, canRead = undefined, canWrite = undefined, onload = undefined, onerror = undefined, dontCreateFile = undefined, canOwn = undefined, preFinish = undefined) => {
1323
+ FS_preloadFile(parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish).then(onload).catch(onerror);
1324
+ };
1119
1325
  var lengthBytesUTF8 = (str) => {
1120
1326
  var len = 0;
1121
1327
  for (var i = 0; i < str.length; ++i) {
1122
- // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
1123
- // unit, not a Unicode code point of the character! So decode
1124
- // UTF16->UTF32->UTF8.
1125
- // See http://unicode.org/faq/utf_bom.html#utf16-3
1126
- var c = str.charCodeAt(i); // possibly a lead surrogate
1127
- if (c <= 0x7F) {
1328
+ var u = str.codePointAt(i);
1329
+ if (u <= 0x7F) {
1128
1330
  len++;
1129
- } else if (c <= 0x7FF) {
1331
+ } else if (u <= 0x7FF) {
1130
1332
  len += 2;
1131
- } else if (c >= 0xD800 && c <= 0xDFFF) {
1132
- len += 4; ++i;
1133
- } else {
1333
+ } else if (u <= 0xFFFF) {
1134
1334
  len += 3;
1335
+ } else {
1336
+ len += 4;
1337
+ // Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16.
1338
+ // We need to manually skip over the second code unit for correct iteration.
1339
+ i++;
1135
1340
  }
1136
1341
  }
1137
1342
  return len;
1138
1343
  };
1139
-
1140
1344
  var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1141
1345
  assert(typeof str === 'string', `stringToUTF8Array expects a string (got ${typeof str})`);
1142
1346
  // Parameter maxBytesToWrite is not optional. Negative values, 0, null,
@@ -1187,183 +1391,64 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1187
1391
  if (dontAddNull) u8array.length = numBytesWritten;
1188
1392
  return u8array;
1189
1393
  };
1190
- var FS_stdin_getChar = () => {
1191
- if (!FS_stdin_getChar_buffer.length) {
1192
- var result = null;
1193
- if (globalThis.window?.prompt) {
1194
- // Browser.
1195
- result = window.prompt('Input: '); // returns null on cancel
1196
- if (result !== null) {
1197
- result += '\n';
1198
- }
1199
- } else
1200
- {}
1201
- if (!result) {
1202
- return null;
1203
- }
1204
- FS_stdin_getChar_buffer = intArrayFromString(result, true);
1394
+ var FS_fileDataToTypedArray = (data) => {
1395
+ if (typeof data === 'string') {
1396
+ data = intArrayFromString(data, true);
1205
1397
  }
1206
- return FS_stdin_getChar_buffer.shift();
1398
+ if (!data.subarray) {
1399
+ data = new Uint8Array(data);
1400
+ }
1401
+ return data;
1207
1402
  };
1208
- var TTY = {
1209
- ttys:[],
1210
- init() {
1211
- // https://github.com/emscripten-core/emscripten/pull/1555
1212
- // if (ENVIRONMENT_IS_NODE) {
1213
- // // currently, FS.init does not distinguish if process.stdin is a file or TTY
1214
- // // device, it always assumes it's a TTY device. because of this, we're forcing
1215
- // // process.stdin to UTF8 encoding to at least make stdin reading compatible
1216
- // // with text files until FS.init can be refactored.
1217
- // process.stdin.setEncoding('utf8');
1218
- // }
1219
- },
1220
- shutdown() {
1221
- // https://github.com/emscripten-core/emscripten/pull/1555
1222
- // if (ENVIRONMENT_IS_NODE) {
1223
- // // inolen: any idea as to why node -e 'process.stdin.read()' wouldn't exit immediately (with process.stdin being a tty)?
1224
- // // isaacs: because now it's reading from the stream, you've expressed interest in it, so that read() kicks off a _read() which creates a ReadReq operation
1225
- // // inolen: I thought read() in that case was a synchronous operation that just grabbed some amount of buffered data if it exists?
1226
- // // isaacs: it is. but it also triggers a _read() call, which calls readStart() on the handle
1227
- // // isaacs: do process.stdin.pause() and i'd think it'd probably close the pending call
1228
- // process.stdin.pause();
1229
- // }
1230
- },
1231
- register(dev, ops) {
1232
- TTY.ttys[dev] = { input: [], output: [], ops: ops };
1233
- FS.registerDevice(dev, TTY.stream_ops);
1234
- },
1235
- stream_ops:{
1236
- open(stream) {
1237
- var tty = TTY.ttys[stream.node.rdev];
1238
- if (!tty) {
1239
- throw new FS.ErrnoError(43);
1240
- }
1241
- stream.tty = tty;
1242
- stream.seekable = false;
1243
- },
1244
- close(stream) {
1245
- // flush any pending line data
1246
- stream.tty.ops.fsync(stream.tty);
1247
- },
1248
- fsync(stream) {
1249
- stream.tty.ops.fsync(stream.tty);
1250
- },
1251
- read(stream, buffer, offset, length, pos /* ignored */) {
1252
- if (!stream.tty || !stream.tty.ops.get_char) {
1253
- throw new FS.ErrnoError(60);
1254
- }
1255
- var bytesRead = 0;
1256
- for (var i = 0; i < length; i++) {
1257
- var result;
1258
- try {
1259
- result = stream.tty.ops.get_char(stream.tty);
1260
- } catch (e) {
1261
- throw new FS.ErrnoError(29);
1262
- }
1263
- if (result === undefined && !bytesRead) {
1264
- throw new FS.ErrnoError(6);
1265
- }
1266
- if (result === null || result === undefined) break;
1267
- bytesRead++;
1268
- buffer[offset+i] = result;
1269
- // We currently only support canonical mode (ICANON), where
1270
- // read(2) returns as soon as a line delimiter is read.
1271
- if (result === 10) break;
1272
- }
1273
- if (bytesRead) {
1274
- stream.node.atime = Date.now();
1275
- }
1276
- return bytesRead;
1277
- },
1278
- write(stream, buffer, offset, length, pos) {
1279
- if (!stream.tty || !stream.tty.ops.put_char) {
1280
- throw new FS.ErrnoError(60);
1281
- }
1282
- try {
1283
- for (var i = 0; i < length; i++) {
1284
- stream.tty.ops.put_char(stream.tty, buffer[offset+i]);
1285
- }
1286
- } catch (e) {
1287
- throw new FS.ErrnoError(29);
1288
- }
1289
- if (length) {
1290
- stream.node.mtime = stream.node.ctime = Date.now();
1291
- }
1292
- return i;
1293
- },
1294
- },
1295
- default_tty_ops:{
1296
- get_char(tty) {
1297
- return FS_stdin_getChar();
1298
- },
1299
- put_char(tty, val) {
1300
- if (val === null || val === 10) {
1301
- out(UTF8ArrayToString(tty.output));
1302
- tty.output = [];
1303
- } else {
1304
- if (val != 0) tty.output.push(val); // val == 0 would cut text output off in the middle.
1305
- }
1306
- },
1307
- fsync(tty) {
1308
- if (tty.output?.length > 0) {
1309
- out(UTF8ArrayToString(tty.output));
1310
- tty.output = [];
1311
- }
1312
- },
1313
- ioctl_tcgets(tty) {
1314
- // typical setting
1315
- return {
1316
- c_iflag: 25856,
1317
- c_oflag: 5,
1318
- c_cflag: 191,
1319
- c_lflag: 35387,
1320
- c_cc: [
1321
- 0x03, 0x1c, 0x7f, 0x15, 0x04, 0x00, 0x01, 0x00, 0x11, 0x13, 0x1a, 0x00,
1322
- 0x12, 0x0f, 0x17, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1323
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1324
- ]
1325
- };
1326
- },
1327
- ioctl_tcsets(tty, optional_actions, data) {
1328
- // currently just ignore
1329
- return 0;
1330
- },
1331
- ioctl_tiocgwinsz(tty) {
1332
- return [24, 80];
1333
- },
1334
- },
1335
- default_tty1_ops:{
1336
- put_char(tty, val) {
1337
- if (val === null || val === 10) {
1338
- err(UTF8ArrayToString(tty.output));
1339
- tty.output = [];
1340
- } else {
1341
- if (val != 0) tty.output.push(val);
1342
- }
1343
- },
1344
- fsync(tty) {
1345
- if (tty.output?.length > 0) {
1346
- err(UTF8ArrayToString(tty.output));
1347
- tty.output = [];
1348
- }
1349
- },
1350
- },
1351
- };
1352
-
1353
-
1403
+ const S_IRUGO = 292;
1404
+ const S_IWUGO = 146;
1405
+ const S_IXUGO = 73;
1406
+ var FS_getMode = (canRead, canWrite) => {
1407
+ var mode = 0;
1408
+ if (canRead) mode |= S_IRUGO | S_IXUGO;
1409
+ if (canWrite) mode |= S_IWUGO;
1410
+ return mode;
1411
+ };
1412
+ const O_APPEND = 1024;
1413
+ const O_CREAT = 64;
1414
+ const O_RDONLY = 0;
1415
+ const O_RDWR = 2;
1416
+ const O_TRUNC = 512;
1417
+ const O_WRONLY = 1;
1418
+ var FS_modeStringToFlags = (str) => {
1419
+ if (typeof str !== 'string') return str;
1420
+ var flagModes = {
1421
+ 'r': O_RDONLY,
1422
+ 'r+': O_RDWR,
1423
+ 'w': O_TRUNC | O_CREAT | O_WRONLY,
1424
+ 'w+': O_TRUNC | O_CREAT | O_RDWR,
1425
+ 'a': O_APPEND | O_CREAT | O_WRONLY,
1426
+ 'a+': O_APPEND | O_CREAT | O_RDWR,
1427
+ };
1428
+ var flags = flagModes[str];
1429
+ if (typeof flags === 'undefined') {
1430
+ throw new Error(`Unknown file open mode: ${str}`);
1431
+ }
1432
+ return flags;
1433
+ };
1434
+ const MAP_PRIVATE = 2;
1435
+ const SEEK_CUR = 1;
1436
+ const SEEK_END = 2;
1437
+ const S_IFDIR = 16384;
1438
+ const S_IFLNK = 40960;
1439
+ const S_IRWXUGO = 511;
1354
1440
  var mmapAlloc = (size) => {
1355
1441
  abort('internal error: mmapAlloc called but `emscripten_builtin_memalign` native symbol not exported');
1356
1442
  };
1357
-
1358
1443
  var MEMFS = {
1359
1444
  ops_table:null,
1360
1445
  mount(mount) {
1361
- return MEMFS.createNode(null, '/', 16895, 0);
1446
+ return MEMFS.createNode(null, '/', S_IFDIR | S_IRWXUGO, 0);
1362
1447
  },
1363
1448
  createNode(parent, name, mode, dev = undefined) {
1364
1449
  if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
1365
1450
  // not supported
1366
- throw new FS.ErrnoError(63);
1451
+ throw new FS.ErrnoError(EPERM);
1367
1452
  }
1368
1453
  MEMFS.ops_table ||= {
1369
1454
  dir: {
@@ -1508,7 +1593,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1508
1593
  }
1509
1594
  },
1510
1595
  lookup(parent, name) {
1511
- throw new FS.ErrnoError(44);
1596
+ throw new FS.ErrnoError(ENOENT);
1512
1597
  },
1513
1598
  mknod(parent, name, mode, dev = undefined) {
1514
1599
  return MEMFS.createNode(parent, name, mode, dev);
@@ -1521,7 +1606,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1521
1606
  if (new_node && FS.isDir(old_node.mode)) {
1522
1607
  // if we're overwriting a directory at new_name, make sure it's empty.
1523
1608
  for (var i in new_node.contents) {
1524
- throw new FS.ErrnoError(55);
1609
+ throw new FS.ErrnoError(ENOTEMPTY);
1525
1610
  }
1526
1611
  }
1527
1612
  // do the internal rewiring
@@ -1537,7 +1622,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1537
1622
  rmdir(parent, name) {
1538
1623
  var node = FS.lookupNode(parent, name);
1539
1624
  for (var i in node.contents) {
1540
- throw new FS.ErrnoError(55);
1625
+ throw new FS.ErrnoError(ENOTEMPTY);
1541
1626
  }
1542
1627
  delete parent.contents[name];
1543
1628
  parent.ctime = parent.mtime = Date.now();
@@ -1546,13 +1631,13 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1546
1631
  return ['.', '..', ...Object.keys(node.contents)];
1547
1632
  },
1548
1633
  symlink(parent, newname, oldpath) {
1549
- var node = MEMFS.createNode(parent, newname, 0o777 | 40960, 0);
1634
+ var node = MEMFS.createNode(parent, newname, S_IRWXUGO | S_IFLNK, 0);
1550
1635
  node.link = oldpath;
1551
1636
  return node;
1552
1637
  },
1553
1638
  readlink(node) {
1554
1639
  if (!FS.isLink(node.mode)) {
1555
- throw new FS.ErrnoError(28);
1640
+ throw new FS.ErrnoError(EINVAL);
1556
1641
  }
1557
1642
  return node.link;
1558
1643
  },
@@ -1597,27 +1682,27 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1597
1682
  },
1598
1683
  llseek(stream, offset, whence) {
1599
1684
  var position = offset;
1600
- if (whence === 1) {
1685
+ if (whence === SEEK_CUR) {
1601
1686
  position += stream.position;
1602
- } else if (whence === 2) {
1687
+ } else if (whence === SEEK_END) {
1603
1688
  if (FS.isFile(stream.node.mode)) {
1604
1689
  position += stream.node.usedBytes;
1605
1690
  }
1606
1691
  }
1607
1692
  if (position < 0) {
1608
- throw new FS.ErrnoError(28);
1693
+ throw new FS.ErrnoError(EINVAL);
1609
1694
  }
1610
1695
  return position;
1611
1696
  },
1612
1697
  mmap(stream, length, position, prot, flags) {
1613
1698
  if (!FS.isFile(stream.node.mode)) {
1614
- throw new FS.ErrnoError(43);
1699
+ throw new FS.ErrnoError(ENODEV);
1615
1700
  }
1616
1701
  var ptr;
1617
1702
  var allocated;
1618
1703
  var contents = stream.node.contents;
1619
1704
  // Only make a new copy when MAP_PRIVATE is specified.
1620
- if (!(flags & 2) && contents.buffer === HEAP8.buffer) {
1705
+ if (!(flags & MAP_PRIVATE) && contents.buffer === HEAP8.buffer) {
1621
1706
  // We can't emulate MAP_SHARED when the file is not backed by the
1622
1707
  // buffer we're mapping to (e.g. the HEAP buffer).
1623
1708
  allocated = false;
@@ -1626,7 +1711,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1626
1711
  allocated = true;
1627
1712
  ptr = mmapAlloc(length);
1628
1713
  if (!ptr) {
1629
- throw new FS.ErrnoError(48);
1714
+ throw new FS.ErrnoError(ENOMEM);
1630
1715
  }
1631
1716
  if (contents) {
1632
1717
  // Try to avoid unnecessary slices.
@@ -1634,7 +1719,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1634
1719
  if (contents.subarray) {
1635
1720
  contents = contents.subarray(position, position + length);
1636
1721
  } else {
1637
- contents = Array.prototype.slice.call(contents, position, position + length);
1722
+ contents = contents.slice(position, position + length);
1638
1723
  }
1639
1724
  }
1640
1725
  HEAP8.set(contents, ptr);
@@ -1649,295 +1734,210 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1649
1734
  },
1650
1735
  },
1651
1736
  };
1652
-
1653
- var FS_modeStringToFlags = (str) => {
1654
- if (typeof str !== 'string') return str;
1655
- var flagModes = {
1656
- 'r': 0,
1657
- 'r+': 2,
1658
- 'w': 512 | 64 | 1,
1659
- 'w+': 512 | 64 | 2,
1660
- 'a': 1024 | 64 | 1,
1661
- 'a+': 1024 | 64 | 2,
1662
- };
1663
- var flags = flagModes[str];
1664
- if (typeof flags === 'undefined') {
1665
- throw new Error(`Unknown file open mode: ${str}`);
1666
- }
1667
- return flags;
1668
- };
1669
-
1670
- var FS_fileDataToTypedArray = (data) => {
1671
- if (typeof data === 'string') {
1672
- data = intArrayFromString(data, true);
1673
- }
1674
- if (!data.subarray) {
1675
- data = new Uint8Array(data);
1676
- }
1677
- return data;
1678
- };
1679
-
1680
- var FS_getMode = (canRead, canWrite) => {
1681
- var mode = 0;
1682
- if (canRead) mode |= 292 | 73;
1683
- if (canWrite) mode |= 146;
1684
- return mode;
1685
- };
1686
-
1687
-
1688
-
1689
-
1690
- var strError = (errno) => UTF8ToString(_strerror(errno));
1691
-
1692
- var ERRNO_CODES = {
1693
- 'EPERM': 63,
1694
- 'ENOENT': 44,
1695
- 'ESRCH': 71,
1696
- 'EINTR': 27,
1697
- 'EIO': 29,
1698
- 'ENXIO': 60,
1699
- 'E2BIG': 1,
1700
- 'ENOEXEC': 45,
1701
- 'EBADF': 8,
1702
- 'ECHILD': 12,
1703
- 'EAGAIN': 6,
1704
- 'EWOULDBLOCK': 6,
1705
- 'ENOMEM': 48,
1706
- 'EACCES': 2,
1707
- 'EFAULT': 21,
1708
- 'ENOTBLK': 105,
1709
- 'EBUSY': 10,
1710
- 'EEXIST': 20,
1711
- 'EXDEV': 75,
1712
- 'ENODEV': 43,
1713
- 'ENOTDIR': 54,
1714
- 'EISDIR': 31,
1715
- 'EINVAL': 28,
1716
- 'ENFILE': 41,
1717
- 'EMFILE': 33,
1718
- 'ENOTTY': 59,
1719
- 'ETXTBSY': 74,
1720
- 'EFBIG': 22,
1721
- 'ENOSPC': 51,
1722
- 'ESPIPE': 70,
1723
- 'EROFS': 69,
1724
- 'EMLINK': 34,
1725
- 'EPIPE': 64,
1726
- 'EDOM': 18,
1727
- 'ERANGE': 68,
1728
- 'ENOMSG': 49,
1729
- 'EIDRM': 24,
1730
- 'ECHRNG': 106,
1731
- 'EL2NSYNC': 156,
1732
- 'EL3HLT': 107,
1733
- 'EL3RST': 108,
1734
- 'ELNRNG': 109,
1735
- 'EUNATCH': 110,
1736
- 'ENOCSI': 111,
1737
- 'EL2HLT': 112,
1738
- 'EDEADLK': 16,
1739
- 'ENOLCK': 46,
1740
- 'EBADE': 113,
1741
- 'EBADR': 114,
1742
- 'EXFULL': 115,
1743
- 'ENOANO': 104,
1744
- 'EBADRQC': 103,
1745
- 'EBADSLT': 102,
1746
- 'EDEADLOCK': 16,
1747
- 'EBFONT': 101,
1748
- 'ENOSTR': 100,
1749
- 'ENODATA': 116,
1750
- 'ETIME': 117,
1751
- 'ENOSR': 118,
1752
- 'ENONET': 119,
1753
- 'ENOPKG': 120,
1754
- 'EREMOTE': 121,
1755
- 'ENOLINK': 47,
1756
- 'EADV': 122,
1757
- 'ESRMNT': 123,
1758
- 'ECOMM': 124,
1759
- 'EPROTO': 65,
1760
- 'EMULTIHOP': 36,
1761
- 'EDOTDOT': 125,
1762
- 'EBADMSG': 9,
1763
- 'ENOTUNIQ': 126,
1764
- 'EBADFD': 127,
1765
- 'EREMCHG': 128,
1766
- 'ELIBACC': 129,
1767
- 'ELIBBAD': 130,
1768
- 'ELIBSCN': 131,
1769
- 'ELIBMAX': 132,
1770
- 'ELIBEXEC': 133,
1771
- 'ENOSYS': 52,
1772
- 'ENOTEMPTY': 55,
1773
- 'ENAMETOOLONG': 37,
1774
- 'ELOOP': 32,
1775
- 'EOPNOTSUPP': 138,
1776
- 'EPFNOSUPPORT': 139,
1777
- 'ECONNRESET': 15,
1778
- 'ENOBUFS': 42,
1779
- 'EAFNOSUPPORT': 5,
1780
- 'EPROTOTYPE': 67,
1781
- 'ENOTSOCK': 57,
1782
- 'ENOPROTOOPT': 50,
1783
- 'ESHUTDOWN': 140,
1784
- 'ECONNREFUSED': 14,
1785
- 'EADDRINUSE': 3,
1786
- 'ECONNABORTED': 13,
1787
- 'ENETUNREACH': 40,
1788
- 'ENETDOWN': 38,
1789
- 'ETIMEDOUT': 73,
1790
- 'EHOSTDOWN': 142,
1791
- 'EHOSTUNREACH': 23,
1792
- 'EINPROGRESS': 26,
1793
- 'EALREADY': 7,
1794
- 'EDESTADDRREQ': 17,
1795
- 'EMSGSIZE': 35,
1796
- 'EPROTONOSUPPORT': 66,
1797
- 'ESOCKTNOSUPPORT': 137,
1798
- 'EADDRNOTAVAIL': 4,
1799
- 'ENETRESET': 39,
1800
- 'EISCONN': 30,
1801
- 'ENOTCONN': 53,
1802
- 'ETOOMANYREFS': 141,
1803
- 'EUSERS': 136,
1804
- 'EDQUOT': 19,
1805
- 'ESTALE': 72,
1806
- 'ENOTSUP': 138,
1807
- 'ENOMEDIUM': 148,
1808
- 'EILSEQ': 25,
1809
- 'EOVERFLOW': 61,
1810
- 'ECANCELED': 11,
1811
- 'ENOTRECOVERABLE': 56,
1812
- 'EOWNERDEAD': 62,
1813
- 'ESTRPIPE': 135,
1814
- };
1815
-
1816
-
1817
- var asyncLoad = async (url) => {
1818
- var arrayBuffer = await readAsync(url);
1819
- assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
1820
- return new Uint8Array(arrayBuffer);
1821
- };
1822
-
1823
-
1824
- var FS_createDataFile = (...args) => FS.createDataFile(...args);
1825
-
1826
- var getUniqueRunDependency = (id) => {
1827
- var orig = id;
1828
- while (1) {
1829
- if (!runDependencyTracking[id]) return id;
1830
- id = orig + Math.random();
1831
- }
1832
- };
1833
-
1834
- var dependenciesPromise = null;
1835
- var resolveRunDependencies = async () => dependenciesPromise;
1836
- var runDependencies = 0;
1837
-
1838
-
1839
- var dependenciesPromiseResolve = null;
1840
-
1841
- var runDependencyTracking = {
1842
- };
1843
-
1844
- var runDependencyWatcher = null;
1845
- var removeRunDependency = (id) => {
1846
- runDependencies--;
1847
-
1848
- Module['monitorRunDependencies']?.(runDependencies);
1849
-
1850
- assert(id, 'removeRunDependency requires an ID');
1851
- assert(runDependencyTracking[id]);
1852
- delete runDependencyTracking[id];
1853
- if (!runDependencies) {
1854
- if (runDependencyWatcher !== null) {
1855
- clearInterval(runDependencyWatcher);
1856
- runDependencyWatcher = null;
1737
+ const NAME_MAX = 255;
1738
+ const O_ACCMODE = 2097155;
1739
+ const O_DIRECTORY = 65536;
1740
+ const O_EXCL = 128;
1741
+ const O_NOFOLLOW = 131072;
1742
+ const POLLNVAL = 32;
1743
+ const PROT_WRITE = 2;
1744
+ const SEEK_SET = 0;
1745
+ const SYMLOOP_MAX = 40;
1746
+ const S_IALLUGO = 4095;
1747
+ const S_IFBLK = 24576;
1748
+ const S_IFCHR = 8192;
1749
+ const S_IFIFO = 4096;
1750
+ const S_IFMT = 61440;
1751
+ const S_IFREG = 32768;
1752
+ const S_IFSOCK = 49152;
1753
+ const S_ISVTX = 512;
1754
+ const B38400 = 15;
1755
+ const CREAD = 128;
1756
+ const CSIZE = 48;
1757
+ const ECHO = 8;
1758
+ const ECHOCTL = 512;
1759
+ const ECHOE = 16;
1760
+ const ECHOK = 32;
1761
+ const ECHOKE = 2048;
1762
+ const ENXIO = 60;
1763
+ var FS_stdin_getChar_buffer = [];
1764
+ var FS_stdin_getChar = () => {
1765
+ if (!FS_stdin_getChar_buffer.length) {
1766
+ var result = null;
1767
+ if (globalThis.window?.prompt) {
1768
+ // Browser.
1769
+ result = window.prompt('Input: '); // returns null on cancel
1770
+ if (result !== null) {
1771
+ result += '\n';
1772
+ }
1773
+ } else
1774
+ {}
1775
+ if (!result) {
1776
+ return null;
1857
1777
  }
1858
- dependenciesPromiseResolve();
1778
+ FS_stdin_getChar_buffer = intArrayFromString(result, true);
1859
1779
  }
1780
+ return FS_stdin_getChar_buffer.shift();
1860
1781
  };
1861
-
1862
-
1863
-
1864
-
1865
- var addRunDependency = (id) => {
1866
- if (!runDependencies) {
1867
- dependenciesPromise = new Promise((resolve) => dependenciesPromiseResolve = resolve);
1868
- }
1869
- runDependencies++;
1870
-
1871
- Module['monitorRunDependencies']?.(runDependencies);
1872
-
1873
- assert(id, 'addRunDependency requires an ID')
1874
- assert(!runDependencyTracking[id]);
1875
- runDependencyTracking[id] = 1;
1876
- if (!runDependencyWatcher && globalThis.setInterval) {
1877
- // Check for missing dependencies every few seconds
1878
- runDependencyWatcher = setInterval(() => {
1879
- if (ABORT) {
1880
- clearInterval(runDependencyWatcher);
1881
- runDependencyWatcher = null;
1882
- return;
1782
+ const ICANON = 2;
1783
+ const ICRNL = 256;
1784
+ const IEXTEN = 32768;
1785
+ const IMAXBEL = 8192;
1786
+ const ISIG = 1;
1787
+ const IUTF8 = 16384;
1788
+ const IXON = 1024;
1789
+ const ONLCR = 4;
1790
+ const OPOST = 1;
1791
+ var TTY = {
1792
+ ttys:[],
1793
+ init() {
1794
+ // https://github.com/emscripten-core/emscripten/pull/1555
1795
+ // if (ENVIRONMENT_IS_NODE) {
1796
+ // // currently, FS.init does not distinguish if process.stdin is a file or TTY
1797
+ // // device, it always assumes it's a TTY device. because of this, we're forcing
1798
+ // // process.stdin to UTF8 encoding to at least make stdin reading compatible
1799
+ // // with text files until FS.init can be refactored.
1800
+ // process.stdin.setEncoding('utf8');
1801
+ // }
1802
+ },
1803
+ shutdown() {
1804
+ // https://github.com/emscripten-core/emscripten/pull/1555
1805
+ // if (ENVIRONMENT_IS_NODE) {
1806
+ // // inolen: any idea as to why node -e 'process.stdin.read()' wouldn't exit immediately (with process.stdin being a tty)?
1807
+ // // isaacs: because now it's reading from the stream, you've expressed interest in it, so that read() kicks off a _read() which creates a ReadReq operation
1808
+ // // inolen: I thought read() in that case was a synchronous operation that just grabbed some amount of buffered data if it exists?
1809
+ // // isaacs: it is. but it also triggers a _read() call, which calls readStart() on the handle
1810
+ // // isaacs: do process.stdin.pause() and i'd think it'd probably close the pending call
1811
+ // process.stdin.pause();
1812
+ // }
1813
+ },
1814
+ register(dev, ops) {
1815
+ TTY.ttys[dev] = { input: [], output: [], ops: ops };
1816
+ FS.registerDevice(dev, TTY.stream_ops);
1817
+ },
1818
+ stream_ops:{
1819
+ open(stream) {
1820
+ var tty = TTY.ttys[stream.node.rdev];
1821
+ if (!tty) {
1822
+ throw new FS.ErrnoError(ENODEV);
1823
+ }
1824
+ stream.tty = tty;
1825
+ stream.seekable = false;
1826
+ },
1827
+ close(stream) {
1828
+ // flush any pending line data
1829
+ stream.tty.ops.fsync(stream.tty);
1830
+ },
1831
+ fsync(stream) {
1832
+ stream.tty.ops.fsync(stream.tty);
1833
+ },
1834
+ read(stream, buffer, offset, length, pos /* ignored */) {
1835
+ if (!stream.tty || !stream.tty.ops.get_char) {
1836
+ throw new FS.ErrnoError(ENXIO);
1883
1837
  }
1884
- var shown = false;
1885
- for (var dep in runDependencyTracking) {
1886
- if (!shown) {
1887
- shown = true;
1888
- err('still waiting on run dependencies:');
1838
+ var bytesRead = 0;
1839
+ for (var i = 0; i < length; i++) {
1840
+ var result;
1841
+ try {
1842
+ result = stream.tty.ops.get_char(stream.tty);
1843
+ } catch (e) {
1844
+ throw new FS.ErrnoError(EIO);
1889
1845
  }
1890
- err(`dependency: ${dep}`);
1846
+ if (result === undefined && !bytesRead) {
1847
+ throw new FS.ErrnoError(EAGAIN);
1848
+ }
1849
+ if (result === null || result === undefined) break;
1850
+ bytesRead++;
1851
+ buffer[offset+i] = result;
1852
+ // We currently only support canonical mode (ICANON), where
1853
+ // read(2) returns as soon as a line delimiter is read.
1854
+ if (result === 10) break;
1891
1855
  }
1892
- if (shown) {
1893
- err('(end of list)');
1856
+ if (bytesRead) {
1857
+ stream.node.atime = Date.now();
1894
1858
  }
1895
- }, 10_000);
1896
- }
1897
- };
1898
-
1899
-
1900
- var preloadPlugins = [];
1901
- var FS_handledByPreloadPlugin = async (byteArray, fullname) => {
1902
- // Ensure plugins are ready.
1903
- if (typeof Browser !== 'undefined') Browser.init();
1904
-
1905
- for (var plugin of preloadPlugins) {
1906
- if (plugin['canHandle'](fullname)) {
1907
- assert(plugin['handle'].constructor.name === 'AsyncFunction', 'Filesystem plugin handlers must be async functions (See #24914)')
1908
- return plugin['handle'](byteArray, fullname);
1909
- }
1910
- }
1911
- // If no plugin handled this file then return the original/unmodified
1912
- // byteArray.
1913
- return byteArray;
1914
- };
1915
- var FS_preloadFile = async (parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish) => {
1916
- // TODO we should allow people to just pass in a complete filename instead
1917
- // of parent and name being that we just join them anyways
1918
- var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
1919
- var dep = getUniqueRunDependency(`cp ${fullname}`); // might have several active requests for the same fullname
1920
- addRunDependency(dep);
1921
-
1922
- try {
1923
- var byteArray = url;
1924
- if (typeof url === 'string') {
1925
- byteArray = await asyncLoad(url);
1926
- }
1859
+ return bytesRead;
1860
+ },
1861
+ write(stream, buffer, offset, length, pos) {
1862
+ if (!stream.tty || !stream.tty.ops.put_char) {
1863
+ throw new FS.ErrnoError(ENXIO);
1864
+ }
1865
+ try {
1866
+ for (var i = 0; i < length; i++) {
1867
+ stream.tty.ops.put_char(stream.tty, buffer[offset+i]);
1868
+ }
1869
+ } catch (e) {
1870
+ throw new FS.ErrnoError(EIO);
1871
+ }
1872
+ if (length) {
1873
+ stream.node.mtime = stream.node.ctime = Date.now();
1874
+ }
1875
+ return i;
1876
+ },
1877
+ },
1878
+ default_tty_ops:{
1879
+ get_char(tty) {
1880
+ return FS_stdin_getChar();
1881
+ },
1882
+ put_char(tty, val) {
1883
+ if (val === null || val === 10) {
1884
+ out(UTF8ArrayToString(tty.output));
1885
+ tty.output = [];
1886
+ } else {
1887
+ if (val != 0) tty.output.push(val); // val == 0 would cut text output off in the middle.
1888
+ }
1889
+ },
1890
+ fsync(tty) {
1891
+ if (tty.output?.length > 0) {
1892
+ out(UTF8ArrayToString(tty.output));
1893
+ tty.output = [];
1894
+ }
1895
+ },
1896
+ ioctl_tcgets(tty) {
1897
+ // typical setting
1898
+ return {
1899
+ c_iflag: ICRNL | IXON | IMAXBEL | IUTF8,
1900
+ c_oflag: OPOST | ONLCR,
1901
+ c_cflag: B38400 | CSIZE | CREAD,
1902
+ c_lflag: ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN,
1903
+ c_cc: [
1904
+ 0x03, 0x1c, 0x7f, 0x15, 0x04, 0x00, 0x01, 0x00, 0x11, 0x13, 0x1a, 0x00,
1905
+ 0x12, 0x0f, 0x17, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1906
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1907
+ ]
1908
+ };
1909
+ },
1910
+ ioctl_tcsets(tty, optional_actions, data) {
1911
+ // currently just ignore
1912
+ return 0;
1913
+ },
1914
+ ioctl_tiocgwinsz(tty) {
1915
+ return [24, 80];
1916
+ },
1917
+ },
1918
+ default_tty1_ops:{
1919
+ put_char(tty, val) {
1920
+ if (val === null || val === 10) {
1921
+ err(UTF8ArrayToString(tty.output));
1922
+ tty.output = [];
1923
+ } else {
1924
+ if (val != 0) tty.output.push(val);
1925
+ }
1926
+ },
1927
+ fsync(tty) {
1928
+ if (tty.output?.length > 0) {
1929
+ err(UTF8ArrayToString(tty.output));
1930
+ tty.output = [];
1931
+ }
1932
+ },
1933
+ },
1934
+ };
1935
+ var initRandomFill = () => {
1927
1936
 
1928
- byteArray = await FS_handledByPreloadPlugin(byteArray, fullname);
1929
- preFinish?.();
1930
- if (!dontCreateFile) {
1931
- FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
1932
- }
1933
- } finally {
1934
- removeRunDependency(dep);
1935
- }
1937
+ return (view) => (crypto.getRandomValues(view), 0);
1936
1938
  };
1937
- var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
1938
- FS_preloadFile(parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish).then(onload).catch(onerror);
1939
- };
1940
-
1939
+ var randomFill = (view) => (randomFill = initRandomFill())(view);
1940
+ var strError = (errno) => UTF8ToString(_strerror(errno));
1941
1941
  var FS = {
1942
1942
  root:null,
1943
1943
  mounts:[],
@@ -1978,13 +1978,13 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1978
1978
  this.node = val;
1979
1979
  }
1980
1980
  get isRead() {
1981
- return (this.flags & 2097155) !== 1;
1981
+ return (this.flags & O_ACCMODE) !== O_WRONLY;
1982
1982
  }
1983
1983
  get isWrite() {
1984
- return (this.flags & 2097155) !== 0;
1984
+ return (this.flags & O_ACCMODE) !== O_RDONLY;
1985
1985
  }
1986
1986
  get isAppend() {
1987
- return (this.flags & 1024);
1987
+ return (this.flags & O_APPEND);
1988
1988
  }
1989
1989
  get flags() {
1990
1990
  return this.shared.flags;
@@ -2002,8 +2002,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2002
2002
  FSNode:class {
2003
2003
  node_ops = {};
2004
2004
  stream_ops = {};
2005
- readMode = 292 | 73;
2006
- writeMode = 146;
2005
+ readMode = S_IRUGO | S_IXUGO;
2006
+ writeMode = S_IWUGO;
2007
2007
  mounted = null;
2008
2008
  constructor(parent, name, mode, rdev) {
2009
2009
  if (!parent) {
@@ -2080,7 +2080,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2080
2080
  },
2081
2081
  lookupPath(path, opts = {}) {
2082
2082
  if (!path) {
2083
- throw new FS.ErrnoError(44);
2083
+ throw new FS.ErrnoError(ENOENT);
2084
2084
  }
2085
2085
  opts.follow_mount ??= true
2086
2086
 
@@ -2089,7 +2089,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2089
2089
  }
2090
2090
 
2091
2091
  // limit max consecutive symlinks to SYMLOOP_MAX.
2092
- linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
2092
+ linkloop: for (var nlinks = 0; nlinks < SYMLOOP_MAX; nlinks++) {
2093
2093
  // split the absolute path
2094
2094
  var parts = path.split('/').filter((p) => !!p);
2095
2095
 
@@ -2129,7 +2129,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2129
2129
  // if noent_okay is true, suppress a ENOENT in the last component
2130
2130
  // and return an object with an undefined node. This is needed for
2131
2131
  // resolving symlinks in the path when creating a file.
2132
- if ((e?.errno === 44) && islast && opts.noent_okay) {
2132
+ if ((e?.errno === ENOENT) && islast && opts.noent_okay) {
2133
2133
  return { path: current_path };
2134
2134
  }
2135
2135
  throw e;
@@ -2144,7 +2144,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2144
2144
  // setting opts.follow = true will override this behavior.
2145
2145
  if (FS.isLink(current.mode) && (!islast || opts.follow)) {
2146
2146
  if (!current.node_ops.readlink) {
2147
- throw new FS.ErrnoError(52);
2147
+ throw new FS.ErrnoError(ENOSYS);
2148
2148
  }
2149
2149
  var link = current.node_ops.readlink(current);
2150
2150
  if (!PATH.isAbs(link)) {
@@ -2156,7 +2156,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2156
2156
  }
2157
2157
  return { path: current_path, node: current };
2158
2158
  }
2159
- throw new FS.ErrnoError(32);
2159
+ throw new FS.ErrnoError(ELOOP);
2160
2160
  },
2161
2161
  getPath(node) {
2162
2162
  var path;
@@ -2231,29 +2231,29 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2231
2231
  return !!node.mounted;
2232
2232
  },
2233
2233
  isFile(mode) {
2234
- return (mode & 61440) === 32768;
2234
+ return (mode & S_IFMT) === S_IFREG;
2235
2235
  },
2236
2236
  isDir(mode) {
2237
- return (mode & 61440) === 16384;
2237
+ return (mode & S_IFMT) === S_IFDIR;
2238
2238
  },
2239
2239
  isLink(mode) {
2240
- return (mode & 61440) === 40960;
2240
+ return (mode & S_IFMT) === S_IFLNK;
2241
2241
  },
2242
2242
  isChrdev(mode) {
2243
- return (mode & 61440) === 8192;
2243
+ return (mode & S_IFMT) === S_IFCHR;
2244
2244
  },
2245
2245
  isBlkdev(mode) {
2246
- return (mode & 61440) === 24576;
2246
+ return (mode & S_IFMT) === S_IFBLK;
2247
2247
  },
2248
2248
  isFIFO(mode) {
2249
- return (mode & 61440) === 4096;
2249
+ return (mode & S_IFMT) === S_IFIFO;
2250
2250
  },
2251
2251
  isSocket(mode) {
2252
- return (mode & 49152) === 49152;
2252
+ return (mode & S_IFSOCK) === S_IFSOCK;
2253
2253
  },
2254
2254
  flagsToPermissionString(flag) {
2255
2255
  var perms = ['r', 'w', 'rw'][flag & 3];
2256
- if ((flag & 512)) {
2256
+ if ((flag & O_TRUNC)) {
2257
2257
  perms += 'w';
2258
2258
  }
2259
2259
  return perms;
@@ -2263,31 +2263,31 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2263
2263
  return 0;
2264
2264
  }
2265
2265
  // return 0 if any user, group or owner bits are set.
2266
- if (perms.includes('r') && !(node.mode & 292)) {
2267
- return 2;
2266
+ if (perms.includes('r') && !(node.mode & S_IRUGO)) {
2267
+ return EACCES;
2268
2268
  }
2269
- if (perms.includes('w') && !(node.mode & 146)) {
2270
- return 2;
2269
+ if (perms.includes('w') && !(node.mode & S_IWUGO)) {
2270
+ return EACCES;
2271
2271
  }
2272
- if (perms.includes('x') && !(node.mode & 73)) {
2273
- return 2;
2272
+ if (perms.includes('x') && !(node.mode & S_IXUGO)) {
2273
+ return EACCES;
2274
2274
  }
2275
2275
  return 0;
2276
2276
  },
2277
2277
  mayLookup(dir) {
2278
- if (!FS.isDir(dir.mode)) return 54;
2278
+ if (!FS.isDir(dir.mode)) return ENOTDIR;
2279
2279
  var errCode = FS.nodePermissions(dir, 'x');
2280
2280
  if (errCode) return errCode;
2281
- if (!dir.node_ops.lookup) return 2;
2281
+ if (!dir.node_ops.lookup) return EACCES;
2282
2282
  return 0;
2283
2283
  },
2284
2284
  mayCreate(dir, name) {
2285
2285
  if (!FS.isDir(dir.mode)) {
2286
- return 54;
2286
+ return ENOTDIR;
2287
2287
  }
2288
2288
  try {
2289
2289
  var node = FS.lookupNode(dir, name);
2290
- return 20;
2290
+ return EEXIST;
2291
2291
  } catch (e) {
2292
2292
  }
2293
2293
  return FS.nodePermissions(dir, 'wx');
@@ -2305,29 +2305,29 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2305
2305
  }
2306
2306
  if (isdir) {
2307
2307
  if (!FS.isDir(node.mode)) {
2308
- return 54;
2308
+ return ENOTDIR;
2309
2309
  }
2310
2310
  if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
2311
- return 10;
2311
+ return EBUSY;
2312
2312
  }
2313
2313
  } else if (FS.isDir(node.mode)) {
2314
- return 31;
2314
+ return EISDIR;
2315
2315
  }
2316
2316
  return 0;
2317
2317
  },
2318
2318
  mayOpen(node, flags) {
2319
2319
  if (!node) {
2320
- return 44;
2320
+ return ENOENT;
2321
2321
  }
2322
2322
  if (FS.isLink(node.mode)) {
2323
- return 32;
2323
+ return ELOOP;
2324
2324
  }
2325
2325
  var mode = FS.flagsToPermissionString(flags);
2326
2326
  if (FS.isDir(node.mode)) {
2327
2327
  // opening for write
2328
2328
  // TODO: check for O_SEARCH? (== search for dir only)
2329
- if (mode !== 'r' || (flags & (512 | 64))) {
2330
- return 31;
2329
+ if (mode !== 'r' || (flags & (O_TRUNC | O_CREAT))) {
2330
+ return EISDIR;
2331
2331
  }
2332
2332
  }
2333
2333
  return FS.nodePermissions(node, mode);
@@ -2338,19 +2338,18 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2338
2338
  }
2339
2339
  return op;
2340
2340
  },
2341
- MAX_OPEN_FDS:4096,
2342
2341
  nextfd() {
2343
- for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) {
2342
+ for (var fd = 0; fd <= FS_MAX_OPEN_FDS; fd++) {
2344
2343
  if (!FS.streams[fd]) {
2345
2344
  return fd;
2346
2345
  }
2347
2346
  }
2348
- throw new FS.ErrnoError(33);
2347
+ throw new FS.ErrnoError(EMFILE);
2349
2348
  },
2350
2349
  getStreamChecked(fd) {
2351
2350
  var stream = FS.getStream(fd);
2352
2351
  if (!stream) {
2353
- throw new FS.ErrnoError(8);
2352
+ throw new FS.ErrnoError(EBADF);
2354
2353
  }
2355
2354
  return stream;
2356
2355
  },
@@ -2379,12 +2378,12 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2379
2378
  var setattr = stream?.stream_ops.setattr;
2380
2379
  var arg = setattr ? stream : node;
2381
2380
  setattr ??= node.node_ops.setattr;
2382
- FS.checkOpExists(setattr, 63)
2381
+ FS.checkOpExists(setattr, EPERM)
2383
2382
  try {
2384
2383
  setattr(arg, attr);
2385
2384
  } catch (e) {
2386
2385
  if (e instanceof RangeError) {
2387
- throw new FS.ErrnoError(22);
2386
+ throw new FS.ErrnoError(EFBIG);
2388
2387
  }
2389
2388
  throw e;
2390
2389
  }
@@ -2398,7 +2397,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2398
2397
  stream.stream_ops.open?.(stream);
2399
2398
  },
2400
2399
  llseek() {
2401
- throw new FS.ErrnoError(70);
2400
+ throw new FS.ErrnoError(ESPIPE);
2402
2401
  },
2403
2402
  },
2404
2403
  major:(dev) => ((dev) >> 8),
@@ -2476,7 +2475,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2476
2475
  var node;
2477
2476
 
2478
2477
  if (root && FS.root) {
2479
- throw new FS.ErrnoError(10);
2478
+ throw new FS.ErrnoError(EBUSY);
2480
2479
  } else if (!root && !pseudo) {
2481
2480
  var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
2482
2481
 
@@ -2484,11 +2483,11 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2484
2483
  node = lookup.node;
2485
2484
 
2486
2485
  if (FS.isMountpoint(node)) {
2487
- throw new FS.ErrnoError(10);
2486
+ throw new FS.ErrnoError(EBUSY);
2488
2487
  }
2489
2488
 
2490
2489
  if (!FS.isDir(node.mode)) {
2491
- throw new FS.ErrnoError(54);
2490
+ throw new FS.ErrnoError(ENOTDIR);
2492
2491
  }
2493
2492
  }
2494
2493
 
@@ -2522,7 +2521,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2522
2521
  var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
2523
2522
 
2524
2523
  if (!FS.isMountpoint(lookup.node)) {
2525
- throw new FS.ErrnoError(28);
2524
+ throw new FS.ErrnoError(EINVAL);
2526
2525
  }
2527
2526
 
2528
2527
  // destroy the nodes for this mount, and all its child mounts
@@ -2558,17 +2557,17 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2558
2557
  var parent = lookup.node;
2559
2558
  var name = PATH.basename(path);
2560
2559
  if (!name) {
2561
- throw new FS.ErrnoError(28);
2560
+ throw new FS.ErrnoError(EINVAL);
2562
2561
  }
2563
2562
  if (name === '.' || name === '..') {
2564
- throw new FS.ErrnoError(20);
2563
+ throw new FS.ErrnoError(EEXIST);
2565
2564
  }
2566
2565
  var errCode = FS.mayCreate(parent, name);
2567
2566
  if (errCode) {
2568
2567
  throw new FS.ErrnoError(errCode);
2569
2568
  }
2570
2569
  if (!parent.node_ops.mknod) {
2571
- throw new FS.ErrnoError(63);
2570
+ throw new FS.ErrnoError(EPERM);
2572
2571
  }
2573
2572
  return parent.node_ops.mknod(parent, name, mode, dev);
2574
2573
  },
@@ -2595,7 +2594,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2595
2594
  ffree: FS.nextInode - 1,
2596
2595
  fsid: 42,
2597
2596
  flags: 2,
2598
- namelen: 255,
2597
+ namelen: NAME_MAX,
2599
2598
  };
2600
2599
 
2601
2600
  if (node.node_ops.statfs) {
@@ -2603,17 +2602,17 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2603
2602
  }
2604
2603
  return rtn;
2605
2604
  },
2606
- create(path, mode = 0o666) {
2607
- mode &= 4095;
2608
- mode |= 32768;
2605
+ create(path, mode = S_IRUGO | S_IWUGO) {
2606
+ mode &= S_IALLUGO;
2607
+ mode |= S_IFREG;
2609
2608
  return FS.mknod(path, mode, 0);
2610
2609
  },
2611
- mkdir(path, mode = 0o777) {
2612
- mode &= 511 | 512;
2613
- mode |= 16384;
2610
+ mkdir(path, mode = S_IRWXUGO) {
2611
+ mode &= S_IRWXUGO | S_ISVTX;
2612
+ mode |= S_IFDIR;
2614
2613
  return FS.mknod(path, mode, 0);
2615
2614
  },
2616
- mkdirTree(path, mode = 0o777) {
2615
+ mkdirTree(path, mode = S_IRWXUGO) {
2617
2616
  var dirs = path.split('/');
2618
2617
  var d = '';
2619
2618
  for (var dir of dirs) {
@@ -2623,26 +2622,26 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2623
2622
  try {
2624
2623
  FS.mkdir(d, mode);
2625
2624
  } catch(e) {
2626
- if (e.errno != 20) throw e;
2625
+ if (e.errno != EEXIST) throw e;
2627
2626
  }
2628
2627
  }
2629
2628
  },
2630
2629
  mkdev(path, mode, dev = undefined) {
2631
2630
  if (typeof dev === 'undefined') {
2632
2631
  dev = mode;
2633
- mode = 0o666;
2632
+ mode = S_IRUGO | S_IWUGO;
2634
2633
  }
2635
- mode |= 8192;
2634
+ mode |= S_IFCHR;
2636
2635
  return FS.mknod(path, mode, dev);
2637
2636
  },
2638
2637
  symlink(oldpath, newpath) {
2639
2638
  if (!PATH_FS.resolve(oldpath)) {
2640
- throw new FS.ErrnoError(44);
2639
+ throw new FS.ErrnoError(ENOENT);
2641
2640
  }
2642
2641
  var lookup = FS.lookupPath(newpath, { parent: true });
2643
2642
  var parent = lookup.node;
2644
2643
  if (!parent) {
2645
- throw new FS.ErrnoError(44);
2644
+ throw new FS.ErrnoError(ENOENT);
2646
2645
  }
2647
2646
  var newname = PATH.basename(newpath);
2648
2647
  var errCode = FS.mayCreate(parent, newname);
@@ -2650,7 +2649,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2650
2649
  throw new FS.ErrnoError(errCode);
2651
2650
  }
2652
2651
  if (!parent.node_ops.symlink) {
2653
- throw new FS.ErrnoError(63);
2652
+ throw new FS.ErrnoError(EPERM);
2654
2653
  }
2655
2654
  return parent.node_ops.symlink(parent, newname, oldpath);
2656
2655
  },
@@ -2658,7 +2657,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2658
2657
  var lookup = FS.lookupPath(newpath, { parent: true });
2659
2658
  var parent = lookup.node;
2660
2659
  if (!parent) {
2661
- throw new FS.ErrnoError(44);
2660
+ throw new FS.ErrnoError(ENOENT);
2662
2661
  }
2663
2662
  var newname = PATH.basename(newpath);
2664
2663
  var errCode = FS.mayCreate(parent, newname);
@@ -2669,7 +2668,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2669
2668
  // `link` node op (e.g. NODERAWFS backed by the host). NODEFS omits it:
2670
2669
  // a host hardlink cannot be confined to the mount root.
2671
2670
  if (!parent.node_ops.link) {
2672
- throw new FS.ErrnoError(34);
2671
+ throw new FS.ErrnoError(EMLINK);
2673
2672
  }
2674
2673
  return parent.node_ops.link(parent, newname, oldpath, flags);
2675
2674
  },
@@ -2687,22 +2686,22 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2687
2686
  lookup = FS.lookupPath(new_path, { parent: true });
2688
2687
  new_dir = lookup.node;
2689
2688
 
2690
- if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
2689
+ if (!old_dir || !new_dir) throw new FS.ErrnoError(ENOENT);
2691
2690
  // need to be part of the same mount
2692
2691
  if (old_dir.mount !== new_dir.mount) {
2693
- throw new FS.ErrnoError(75);
2692
+ throw new FS.ErrnoError(EXDEV);
2694
2693
  }
2695
2694
  // source must exist
2696
2695
  var old_node = FS.lookupNode(old_dir, old_name);
2697
2696
  // old path should not be an ancestor of the new path
2698
2697
  var relative = PATH_FS.relative(old_path, new_dirname);
2699
2698
  if (relative.charAt(0) !== '.') {
2700
- throw new FS.ErrnoError(28);
2699
+ throw new FS.ErrnoError(EINVAL);
2701
2700
  }
2702
2701
  // new path should not be an ancestor of the old path
2703
2702
  relative = PATH_FS.relative(new_path, old_dirname);
2704
2703
  if (relative.charAt(0) !== '.') {
2705
- throw new FS.ErrnoError(55);
2704
+ throw new FS.ErrnoError(ENOTEMPTY);
2706
2705
  }
2707
2706
  // see if the new path already exists
2708
2707
  var new_node;
@@ -2730,10 +2729,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2730
2729
  throw new FS.ErrnoError(errCode);
2731
2730
  }
2732
2731
  if (!old_dir.node_ops.rename) {
2733
- throw new FS.ErrnoError(63);
2732
+ throw new FS.ErrnoError(EPERM);
2734
2733
  }
2735
2734
  if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
2736
- throw new FS.ErrnoError(10);
2735
+ throw new FS.ErrnoError(EBUSY);
2737
2736
  }
2738
2737
  // if we are going to change the parent, check write permissions
2739
2738
  if (new_dir !== old_dir) {
@@ -2773,10 +2772,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2773
2772
  throw new FS.ErrnoError(errCode);
2774
2773
  }
2775
2774
  if (!parent.node_ops.rmdir) {
2776
- throw new FS.ErrnoError(63);
2775
+ throw new FS.ErrnoError(EPERM);
2777
2776
  }
2778
2777
  if (FS.isMountpoint(node)) {
2779
- throw new FS.ErrnoError(10);
2778
+ throw new FS.ErrnoError(EBUSY);
2780
2779
  }
2781
2780
  parent.node_ops.rmdir(parent, name);
2782
2781
  FS.destroyNode(node);
@@ -2784,14 +2783,14 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2784
2783
  readdir(path) {
2785
2784
  var lookup = FS.lookupPath(path, { follow: true });
2786
2785
  var node = lookup.node;
2787
- var readdir = FS.checkOpExists(node.node_ops.readdir, 54);
2786
+ var readdir = FS.checkOpExists(node.node_ops.readdir, ENOTDIR);
2788
2787
  return readdir(node);
2789
2788
  },
2790
2789
  unlink(path) {
2791
2790
  var lookup = FS.lookupPath(path, { parent: true });
2792
2791
  var parent = lookup.node;
2793
2792
  if (!parent) {
2794
- throw new FS.ErrnoError(44);
2793
+ throw new FS.ErrnoError(ENOENT);
2795
2794
  }
2796
2795
  var name = PATH.basename(path);
2797
2796
  var node = FS.lookupNode(parent, name);
@@ -2803,10 +2802,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2803
2802
  throw new FS.ErrnoError(errCode);
2804
2803
  }
2805
2804
  if (!parent.node_ops.unlink) {
2806
- throw new FS.ErrnoError(63);
2805
+ throw new FS.ErrnoError(EPERM);
2807
2806
  }
2808
2807
  if (FS.isMountpoint(node)) {
2809
- throw new FS.ErrnoError(10);
2808
+ throw new FS.ErrnoError(EBUSY);
2810
2809
  }
2811
2810
  parent.node_ops.unlink(parent, name);
2812
2811
  FS.destroyNode(node);
@@ -2815,17 +2814,17 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2815
2814
  var lookup = FS.lookupPath(path);
2816
2815
  var link = lookup.node;
2817
2816
  if (!link) {
2818
- throw new FS.ErrnoError(44);
2817
+ throw new FS.ErrnoError(ENOENT);
2819
2818
  }
2820
2819
  if (!link.node_ops.readlink) {
2821
- throw new FS.ErrnoError(28);
2820
+ throw new FS.ErrnoError(EINVAL);
2822
2821
  }
2823
2822
  return link.node_ops.readlink(link);
2824
2823
  },
2825
2824
  stat(path, dontFollow = false) {
2826
2825
  var lookup = FS.lookupPath(path, { follow: !dontFollow });
2827
2826
  var node = lookup.node;
2828
- var getattr = FS.checkOpExists(node.node_ops.getattr, 63);
2827
+ var getattr = FS.checkOpExists(node.node_ops.getattr, EPERM);
2829
2828
  return getattr(node);
2830
2829
  },
2831
2830
  fstat(fd) {
@@ -2834,7 +2833,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2834
2833
  var getattr = stream.stream_ops.getattr;
2835
2834
  var arg = getattr ? stream : node;
2836
2835
  getattr ??= node.node_ops.getattr;
2837
- FS.checkOpExists(getattr, 63)
2836
+ FS.checkOpExists(getattr, EPERM)
2838
2837
  return getattr(arg);
2839
2838
  },
2840
2839
  lstat(path) {
@@ -2842,7 +2841,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2842
2841
  },
2843
2842
  doChmod(stream, node, mode, dontFollow = false) {
2844
2843
  FS.doSetAttr(stream, node, {
2845
- mode: (mode & 4095) | (node.mode & ~4095),
2844
+ mode: (mode & S_IALLUGO) | (node.mode & ~S_IALLUGO),
2846
2845
  ctime: Date.now(),
2847
2846
  dontFollow
2848
2847
  });
@@ -2890,10 +2889,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2890
2889
  },
2891
2890
  doTruncate(stream, node, len) {
2892
2891
  if (FS.isDir(node.mode)) {
2893
- throw new FS.ErrnoError(31);
2892
+ throw new FS.ErrnoError(EISDIR);
2894
2893
  }
2895
2894
  if (!FS.isFile(node.mode)) {
2896
- throw new FS.ErrnoError(28);
2895
+ throw new FS.ErrnoError(EINVAL);
2897
2896
  }
2898
2897
  var errCode = FS.nodePermissions(node, 'w');
2899
2898
  if (errCode) {
@@ -2906,7 +2905,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2906
2905
  },
2907
2906
  truncate(path, len) {
2908
2907
  if (len < 0) {
2909
- throw new FS.ErrnoError(28);
2908
+ throw new FS.ErrnoError(EINVAL);
2910
2909
  }
2911
2910
  var node;
2912
2911
  if (typeof path === 'string') {
@@ -2919,8 +2918,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2919
2918
  },
2920
2919
  ftruncate(fd, len) {
2921
2920
  var stream = FS.getStreamChecked(fd);
2922
- if (len < 0 || (stream.flags & 2097155) === 0) {
2923
- throw new FS.ErrnoError(28);
2921
+ if (len < 0 || (stream.flags & O_ACCMODE) === O_RDONLY) {
2922
+ throw new FS.ErrnoError(EINVAL);
2924
2923
  }
2925
2924
  FS.doTruncate(stream, stream.node, len);
2926
2925
  },
@@ -2932,13 +2931,13 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2932
2931
  dontFollow
2933
2932
  });
2934
2933
  },
2935
- open(path, flags, mode = 0o666) {
2934
+ open(path, flags, mode = S_IRUGO | S_IWUGO) {
2936
2935
  if (path === '') {
2937
- throw new FS.ErrnoError(44);
2936
+ throw new FS.ErrnoError(ENOENT);
2938
2937
  }
2939
2938
  flags = FS_modeStringToFlags(flags);
2940
- if ((flags & 64)) {
2941
- mode = (mode & 4095) | 32768;
2939
+ if ((flags & O_CREAT)) {
2940
+ mode = (mode & S_IALLUGO) | S_IFREG;
2942
2941
  } else {
2943
2942
  mode = 0;
2944
2943
  }
@@ -2952,7 +2951,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2952
2951
  // doesn't exist, lookupPath returns `node: undefined`. `path` will be
2953
2952
  // updated to point to the target of all symlinks.
2954
2953
  var lookup = FS.lookupPath(path, {
2955
- follow: !(flags & 131072),
2954
+ follow: !(flags & O_NOFOLLOW),
2956
2955
  noent_okay: true
2957
2956
  });
2958
2957
  node = lookup.node;
@@ -2960,33 +2959,33 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2960
2959
  }
2961
2960
  // perhaps we need to create the node
2962
2961
  var created = false;
2963
- if ((flags & 64)) {
2962
+ if ((flags & O_CREAT)) {
2964
2963
  if (node) {
2965
2964
  // if O_CREAT and O_EXCL are set, error out if the node already exists
2966
- if ((flags & 128)) {
2967
- throw new FS.ErrnoError(20);
2965
+ if ((flags & O_EXCL)) {
2966
+ throw new FS.ErrnoError(EEXIST);
2968
2967
  }
2969
2968
  } else if (isDirPath) {
2970
- throw new FS.ErrnoError(31);
2969
+ throw new FS.ErrnoError(EISDIR);
2971
2970
  } else {
2972
2971
  // node doesn't exist, try to create it
2973
2972
  // Ignore the permission bits here to ensure we can `open` this new
2974
2973
  // file below. We use chmod below to apply the permissions once the
2975
2974
  // file is open.
2976
- node = FS.mknod(path, mode | 0o777, 0);
2975
+ node = FS.mknod(path, mode | S_IRWXUGO, 0);
2977
2976
  created = true;
2978
2977
  }
2979
2978
  }
2980
2979
  if (!node) {
2981
- throw new FS.ErrnoError(44);
2980
+ throw new FS.ErrnoError(ENOENT);
2982
2981
  }
2983
2982
  // can't truncate a device
2984
2983
  if (FS.isChrdev(node.mode)) {
2985
- flags &= ~512;
2984
+ flags &= ~O_TRUNC;
2986
2985
  }
2987
2986
  // if asked only for a directory, then this must be one
2988
- if ((flags & 65536) && !FS.isDir(node.mode)) {
2989
- throw new FS.ErrnoError(54);
2987
+ if ((flags & O_DIRECTORY) && !FS.isDir(node.mode)) {
2988
+ throw new FS.ErrnoError(ENOTDIR);
2990
2989
  }
2991
2990
  // check permissions, if this is not a file we just created now (it is ok to
2992
2991
  // create and write to a file with read-only permissions; it is read-only
@@ -2998,11 +2997,11 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2998
2997
  }
2999
2998
  }
3000
2999
  // do truncation if necessary
3001
- if ((flags & 512) && !created) {
3000
+ if ((flags & O_TRUNC) && !created) {
3002
3001
  FS.truncate(node, 0);
3003
3002
  }
3004
3003
  // we've already handled these, don't pass down to the underlying vfs
3005
- flags &= ~(128 | 512 | 131072);
3004
+ flags &= ~(O_EXCL | O_TRUNC | O_NOFOLLOW);
3006
3005
 
3007
3006
  // register the stream with the filesystem
3008
3007
  var stream = FS.createStream({
@@ -3021,20 +3020,20 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3021
3020
  stream.stream_ops.open(stream);
3022
3021
  }
3023
3022
  if (created) {
3024
- FS.chmod(node, mode & 0o777);
3023
+ FS.chmod(node, mode & S_IRWXUGO);
3025
3024
  }
3026
3025
  return stream;
3027
3026
  },
3028
3027
  close(stream) {
3029
3028
  if (FS.isClosed(stream)) {
3030
- throw new FS.ErrnoError(8);
3029
+ throw new FS.ErrnoError(EBADF);
3031
3030
  }
3032
3031
  if (stream.getdents) stream.getdents = null; // free readdir state
3033
3032
  // The fd is going away: wake anything waiting on it (poll/epoll) with
3034
3033
  // POLLNVAL so a blocking wait unblocks and an epoll registration is evicted
3035
3034
  // on its next derive. Only sockets/pipes/epoll ever carry a wait-queue, so
3036
3035
  // for every other stream (incl. nodeless noderawfs stdio) this is a no-op.
3037
- stream.node?.notifyListeners(32);
3036
+ stream.node?.notifyListeners(POLLNVAL);
3038
3037
  try {
3039
3038
  if (stream.stream_ops.close) {
3040
3039
  stream.stream_ops.close(stream);
@@ -3051,13 +3050,13 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3051
3050
  },
3052
3051
  llseek(stream, offset, whence) {
3053
3052
  if (FS.isClosed(stream)) {
3054
- throw new FS.ErrnoError(8);
3053
+ throw new FS.ErrnoError(EBADF);
3055
3054
  }
3056
3055
  if (!stream.seekable || !stream.stream_ops.llseek) {
3057
- throw new FS.ErrnoError(70);
3056
+ throw new FS.ErrnoError(ESPIPE);
3058
3057
  }
3059
- if (whence != 0 && whence != 1 && whence != 2) {
3060
- throw new FS.ErrnoError(28);
3058
+ if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) {
3059
+ throw new FS.ErrnoError(EINVAL);
3061
3060
  }
3062
3061
  stream.position = stream.stream_ops.llseek(stream, offset, whence);
3063
3062
  stream.ungotten = [];
@@ -3066,25 +3065,25 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3066
3065
  read(stream, buffer, offset, length, position = undefined) {
3067
3066
  assert(offset >= 0);
3068
3067
  if (length < 0 || position < 0) {
3069
- throw new FS.ErrnoError(28);
3068
+ throw new FS.ErrnoError(EINVAL);
3070
3069
  }
3071
3070
  if (FS.isClosed(stream)) {
3072
- throw new FS.ErrnoError(8);
3071
+ throw new FS.ErrnoError(EBADF);
3073
3072
  }
3074
- if ((stream.flags & 2097155) === 1) {
3075
- throw new FS.ErrnoError(8);
3073
+ if ((stream.flags & O_ACCMODE) === O_WRONLY) {
3074
+ throw new FS.ErrnoError(EBADF);
3076
3075
  }
3077
3076
  if (FS.isDir(stream.node.mode)) {
3078
- throw new FS.ErrnoError(31);
3077
+ throw new FS.ErrnoError(EISDIR);
3079
3078
  }
3080
3079
  if (!stream.stream_ops.read) {
3081
- throw new FS.ErrnoError(28);
3080
+ throw new FS.ErrnoError(EINVAL);
3082
3081
  }
3083
3082
  var seeking = typeof position !== 'undefined';
3084
3083
  if (!seeking) {
3085
3084
  position = stream.position;
3086
3085
  } else if (!stream.seekable) {
3087
- throw new FS.ErrnoError(70);
3086
+ throw new FS.ErrnoError(ESPIPE);
3088
3087
  }
3089
3088
  var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
3090
3089
  if (!seeking) stream.position += bytesRead;
@@ -3094,29 +3093,29 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3094
3093
  assert(offset >= 0);
3095
3094
  assert(buffer.subarray, 'FS.write expects a TypedArray');
3096
3095
  if (length < 0 || position < 0) {
3097
- throw new FS.ErrnoError(28);
3096
+ throw new FS.ErrnoError(EINVAL);
3098
3097
  }
3099
3098
  if (FS.isClosed(stream)) {
3100
- throw new FS.ErrnoError(8);
3099
+ throw new FS.ErrnoError(EBADF);
3101
3100
  }
3102
- if ((stream.flags & 2097155) === 0) {
3103
- throw new FS.ErrnoError(8);
3101
+ if ((stream.flags & O_ACCMODE) === O_RDONLY) {
3102
+ throw new FS.ErrnoError(EBADF);
3104
3103
  }
3105
3104
  if (FS.isDir(stream.node.mode)) {
3106
- throw new FS.ErrnoError(31);
3105
+ throw new FS.ErrnoError(EISDIR);
3107
3106
  }
3108
3107
  if (!stream.stream_ops.write) {
3109
- throw new FS.ErrnoError(28);
3108
+ throw new FS.ErrnoError(EINVAL);
3110
3109
  }
3111
- if (stream.seekable && stream.flags & 1024) {
3110
+ if (stream.seekable && stream.flags & O_APPEND) {
3112
3111
  // seek to the end before writing in append mode
3113
- FS.llseek(stream, 0, 2);
3112
+ FS.llseek(stream, 0, SEEK_END);
3114
3113
  }
3115
3114
  var seeking = typeof position !== 'undefined';
3116
3115
  if (!seeking) {
3117
3116
  position = stream.position;
3118
3117
  } else if (!stream.seekable) {
3119
- throw new FS.ErrnoError(70);
3118
+ throw new FS.ErrnoError(ESPIPE);
3120
3119
  }
3121
3120
  var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
3122
3121
  if (!seeking) stream.position += bytesWritten;
@@ -3129,19 +3128,19 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3129
3128
  // to write to file opened in read-only mode with MAP_PRIVATE flag,
3130
3129
  // as all modifications will be visible only in the memory of
3131
3130
  // the current process.
3132
- if ((prot & 2)
3133
- && !(flags & 2)
3134
- && (stream.flags & 2097155) !== 2) {
3135
- throw new FS.ErrnoError(2);
3131
+ if ((prot & PROT_WRITE)
3132
+ && !(flags & MAP_PRIVATE)
3133
+ && (stream.flags & O_ACCMODE) !== O_RDWR) {
3134
+ throw new FS.ErrnoError(EACCES);
3136
3135
  }
3137
- if ((stream.flags & 2097155) === 1) {
3138
- throw new FS.ErrnoError(2);
3136
+ if ((stream.flags & O_ACCMODE) === O_WRONLY) {
3137
+ throw new FS.ErrnoError(EACCES);
3139
3138
  }
3140
3139
  if (!stream.stream_ops.mmap) {
3141
- throw new FS.ErrnoError(43);
3140
+ throw new FS.ErrnoError(ENODEV);
3142
3141
  }
3143
3142
  if (!length) {
3144
- throw new FS.ErrnoError(28);
3143
+ throw new FS.ErrnoError(EINVAL);
3145
3144
  }
3146
3145
  return stream.stream_ops.mmap(stream, length, position, prot, flags);
3147
3146
  },
@@ -3154,12 +3153,12 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3154
3153
  },
3155
3154
  ioctl(stream, cmd, arg) {
3156
3155
  if (!stream.stream_ops.ioctl) {
3157
- throw new FS.ErrnoError(59);
3156
+ throw new FS.ErrnoError(ENOTTY);
3158
3157
  }
3159
3158
  return stream.stream_ops.ioctl(stream, cmd, arg);
3160
3159
  },
3161
3160
  readFile(path, opts = {}) {
3162
- opts.flags ??= 0;
3161
+ opts.flags ??= O_RDONLY;
3163
3162
  opts.encoding ??= 'binary';
3164
3163
  if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
3165
3164
  abort(`Invalid encoding type "${opts.encoding}"`);
@@ -3176,7 +3175,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3176
3175
  return buf;
3177
3176
  },
3178
3177
  writeFile(path, data, opts = {}) {
3179
- opts.flags ??= 577;
3178
+ opts.flags ??= O_TRUNC | O_CREAT | O_WRONLY;
3180
3179
  var stream = FS.open(path, opts.flags, opts.mode);
3181
3180
  data = FS_fileDataToTypedArray(data);
3182
3181
  FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
@@ -3186,10 +3185,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3186
3185
  chdir(path) {
3187
3186
  var lookup = FS.lookupPath(path, { follow: true });
3188
3187
  if (lookup.node === null) {
3189
- throw new FS.ErrnoError(44);
3188
+ throw new FS.ErrnoError(ENOENT);
3190
3189
  }
3191
3190
  if (!FS.isDir(lookup.node.mode)) {
3192
- throw new FS.ErrnoError(54);
3191
+ throw new FS.ErrnoError(ENOTDIR);
3193
3192
  }
3194
3193
  var errCode = FS.nodePermissions(lookup.node, 'x');
3195
3194
  if (errCode) {
@@ -3244,7 +3243,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3244
3243
  FS.mkdir('/proc/self/fd');
3245
3244
  FS.mount({
3246
3245
  mount() {
3247
- var node = FS.createNode(proc_self, 'fd', 16895, 73);
3246
+ var node = FS.createNode(proc_self, 'fd', S_IFDIR | S_IRWXUGO, S_IXUGO);
3248
3247
  node.stream_ops = {
3249
3248
  llseek: MEMFS.stream_ops.llseek,
3250
3249
  };
@@ -3297,9 +3296,9 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3297
3296
  }
3298
3297
 
3299
3298
  // open default streams for the stdin, stdout and stderr devices
3300
- var stdin = FS.open('/dev/stdin', 0);
3301
- var stdout = FS.open('/dev/stdout', 1);
3302
- var stderr = FS.open('/dev/stderr', 1);
3299
+ var stdin = FS.open('/dev/stdin', O_RDONLY);
3300
+ var stdout = FS.open('/dev/stdout', O_WRONLY);
3301
+ var stderr = FS.open('/dev/stderr', O_WRONLY);
3303
3302
  assert(stdin.fd === 0, `invalid handle for stdin (${stdin.fd})`);
3304
3303
  assert(stdout.fd === 1, `invalid handle for stdout (${stdout.fd})`);
3305
3304
  assert(stderr.fd === 2, `invalid handle for stderr (${stderr.fd})`);
@@ -3374,7 +3373,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3374
3373
  try {
3375
3374
  FS.mkdir(current);
3376
3375
  } catch (e) {
3377
- if (e.errno != 20) throw e;
3376
+ if (e.errno != EEXIST) throw e;
3378
3377
  }
3379
3378
  parent = current;
3380
3379
  }
@@ -3396,8 +3395,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3396
3395
  if (data) {
3397
3396
  data = FS_fileDataToTypedArray(data);
3398
3397
  // make sure we can write to the file
3399
- FS.chmod(node, mode | 146);
3400
- var stream = FS.open(node, 577);
3398
+ FS.chmod(node, mode | S_IWUGO);
3399
+ var stream = FS.open(node, O_TRUNC | O_CREAT | O_WRONLY);
3401
3400
  FS.write(stream, data, 0, data.length, 0, canOwn);
3402
3401
  FS.close(stream);
3403
3402
  FS.chmod(node, mode);
@@ -3427,10 +3426,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3427
3426
  try {
3428
3427
  result = input();
3429
3428
  } catch (e) {
3430
- throw new FS.ErrnoError(29);
3429
+ throw new FS.ErrnoError(EIO);
3431
3430
  }
3432
3431
  if (result === undefined && !bytesRead) {
3433
- throw new FS.ErrnoError(6);
3432
+ throw new FS.ErrnoError(EAGAIN);
3434
3433
  }
3435
3434
  if (result === null || result === undefined) break;
3436
3435
  bytesRead++;
@@ -3446,7 +3445,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3446
3445
  try {
3447
3446
  output(buffer[offset+i]);
3448
3447
  } catch (e) {
3449
- throw new FS.ErrnoError(29);
3448
+ throw new FS.ErrnoError(EIO);
3450
3449
  }
3451
3450
  }
3452
3451
  if (length) {
@@ -3465,7 +3464,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3465
3464
  try {
3466
3465
  obj.contents = readBinary(obj.url);
3467
3466
  } catch (e) {
3468
- throw new FS.ErrnoError(29);
3467
+ throw new FS.ErrnoError(EIO);
3469
3468
  }
3470
3469
  }
3471
3470
  },
@@ -3621,7 +3620,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3621
3620
  FS.forceLoadFile(node);
3622
3621
  var ptr = mmapAlloc(length);
3623
3622
  if (!ptr) {
3624
- throw new FS.ErrnoError(48);
3623
+ throw new FS.ErrnoError(ENOMEM);
3625
3624
  }
3626
3625
  writeChunks(stream, HEAP8, ptr, length, position);
3627
3626
  return { ptr, allocated: true };
@@ -3630,10 +3629,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3630
3629
  return node;
3631
3630
  },
3632
3631
  };
3633
-
3634
-
3635
-
3636
-
3632
+ const O_CLOEXEC = 524288;
3633
+ const AT_FDCWD = -100;
3637
3634
  var SYSCALLS = {
3638
3635
  currentUmask:18,
3639
3636
  calculateAt(dirfd, path, allowEmpty = false) {
@@ -3642,7 +3639,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3642
3639
  }
3643
3640
  // relative path
3644
3641
  var dir;
3645
- if (dirfd === -100) {
3642
+ if (dirfd === AT_FDCWD) {
3646
3643
  dir = FS.cwd();
3647
3644
  } else {
3648
3645
  var dirstream = SYSCALLS.getStreamFromFD(dirfd);
@@ -3650,7 +3647,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3650
3647
  }
3651
3648
  if (path.length == 0) {
3652
3649
  if (!allowEmpty) {
3653
- throw new FS.ErrnoError(44);;
3650
+ throw new FS.ErrnoError(ENOENT);;
3654
3651
  }
3655
3652
  return dir;
3656
3653
  }
@@ -3692,9 +3689,9 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3692
3689
  },
3693
3690
  doMsync(addr, stream, len, flags, offset) {
3694
3691
  if (!FS.isFile(stream.node.mode)) {
3695
- throw new FS.ErrnoError(43);
3692
+ throw new FS.ErrnoError(ENODEV);
3696
3693
  }
3697
- if (flags & 2) {
3694
+ if (flags & MAP_PRIVATE) {
3698
3695
  // MAP_PRIVATE calls need not to be synced back to underlying fs
3699
3696
  return 0;
3700
3697
  }
@@ -3714,16 +3711,16 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3714
3711
  function ___syscall_dup3(fd, newfd, flags) {
3715
3712
  try {
3716
3713
 
3717
- if (fd === newfd) return -28;
3718
- if (flags & ~524288) return -28;
3714
+ if (fd === newfd) return -EINVAL;
3715
+ if (flags & ~O_CLOEXEC) return -EINVAL;
3719
3716
  var old = SYSCALLS.getStreamFromFD(fd);
3720
3717
  // Check newfd is within range of valid open file descriptors.
3721
- if (newfd < 0 || newfd >= FS.MAX_OPEN_FDS) return -8;
3718
+ if (newfd < 0 || newfd >= FS_MAX_OPEN_FDS) return -EBADF;
3722
3719
  var existing = FS.getStream(newfd);
3723
3720
  if (existing) FS.close(existing);
3724
3721
  var stream = FS.dupStream(old, newfd);
3725
- if (flags & 524288) {
3726
- stream.flags |= 524288;
3722
+ if (flags & O_CLOEXEC) {
3723
+ stream.flags |= O_CLOEXEC;
3727
3724
  }
3728
3725
  return stream.fd;
3729
3726
  } catch (e) {
@@ -3732,28 +3729,32 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3732
3729
  }
3733
3730
  }
3734
3731
 
3735
-
3732
+ const AT_EACCESS = 512;
3733
+ const R_OK = 4;
3734
+ const S_IRWXO = 7;
3735
+ const W_OK = 2;
3736
+ const X_OK = 1;
3736
3737
  function ___syscall_faccessat(dirfd, path, amode, flags) {
3737
3738
  try {
3738
3739
 
3739
3740
  path = SYSCALLS.getStr(path);
3740
- assert(!flags || flags == 512);
3741
+ assert(!flags || flags == AT_EACCESS);
3741
3742
  path = SYSCALLS.calculateAt(dirfd, path);
3742
- if (amode & ~7) {
3743
+ if (amode & ~S_IRWXO) {
3743
3744
  // need a valid mode
3744
- return -28;
3745
+ return -EINVAL;
3745
3746
  }
3746
3747
  var lookup = FS.lookupPath(path, { follow: true });
3747
3748
  var node = lookup.node;
3748
3749
  if (!node) {
3749
- return -44;
3750
+ return -ENOENT;
3750
3751
  }
3751
3752
  var perms = '';
3752
- if (amode & 4) perms += 'r';
3753
- if (amode & 2) perms += 'w';
3754
- if (amode & 1) perms += 'x';
3753
+ if (amode & R_OK) perms += 'r';
3754
+ if (amode & W_OK) perms += 'w';
3755
+ if (amode & X_OK) perms += 'x';
3755
3756
  if (perms /* otherwise, they've just passed F_OK */ && FS.nodePermissions(node, perms)) {
3756
- return -2;
3757
+ return -EACCES;
3757
3758
  }
3758
3759
  return 0;
3759
3760
  } catch (e) {
@@ -3762,7 +3763,21 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3762
3763
  }
3763
3764
  }
3764
3765
 
3765
-
3766
+ const F_DUPFD = 0;
3767
+ const F_GETFD = 1;
3768
+ const F_GETFL = 3;
3769
+ const F_GETLK = 12;
3770
+ const F_SETFD = 2;
3771
+ const F_SETFL = 4;
3772
+ const F_SETLK = 13;
3773
+ const F_SETLKW = 14;
3774
+ const F_UNLCK = 2;
3775
+ /** @type {!Int16Array} */
3776
+ var HEAP16;
3777
+ const O_ASYNC = 8192;
3778
+ const O_DIRECT = 16384;
3779
+ const O_NOATIME = 262144;
3780
+ const O_NONBLOCK = 2048;
3766
3781
  var syscallGetVarargI = () => {
3767
3782
  assert(SYSCALLS.varargs != undefined);
3768
3783
  // the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
@@ -3770,22 +3785,16 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3770
3785
  SYSCALLS.varargs += 4;
3771
3786
  return ret;
3772
3787
  };
3773
- var syscallGetVarargP = syscallGetVarargI;
3774
-
3775
-
3776
-
3777
- /** @type {!Int16Array} */
3778
- var HEAP16;
3779
3788
  function ___syscall_fcntl64(fd, cmd, varargs) {
3780
3789
  SYSCALLS.varargs = varargs;
3781
3790
  try {
3782
3791
 
3783
3792
  var stream = SYSCALLS.getStreamFromFD(fd);
3784
3793
  switch (cmd) {
3785
- case 0: {
3794
+ case F_DUPFD: {
3786
3795
  var arg = syscallGetVarargI();
3787
3796
  if (arg < 0) {
3788
- return -28;
3797
+ return -EINVAL;
3789
3798
  }
3790
3799
  while (FS.streams[arg]) {
3791
3800
  arg++;
@@ -3794,40 +3803,39 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3794
3803
  newStream = FS.dupStream(stream, arg);
3795
3804
  return newStream.fd;
3796
3805
  }
3797
- case 1:
3798
- case 2:
3806
+ case F_GETFD:
3807
+ case F_SETFD:
3799
3808
  return 0; // FD_CLOEXEC makes no sense for a single process.
3800
- case 3:
3809
+ case F_GETFL:
3801
3810
  return stream.flags;
3802
- case 4: {
3811
+ case F_SETFL: {
3803
3812
  var arg = syscallGetVarargI();
3804
- var mask = 289792;
3813
+ var mask = O_APPEND | O_ASYNC | O_DIRECT | O_NOATIME | O_NONBLOCK;
3805
3814
  stream.flags = (stream.flags & ~mask) | (arg & mask);
3806
3815
  return 0;
3807
3816
  }
3808
- case 12: {
3817
+ case F_GETLK: {
3809
3818
  var arg = syscallGetVarargP();
3810
3819
  var offset = 0;
3811
3820
  // We're always unlocked.
3812
- HEAP16[(((arg)+(offset))>>1)] = 2;
3821
+ HEAP16[(((arg)+(offset))>>1)] = F_UNLCK;
3813
3822
  return 0;
3814
3823
  }
3815
- case 13:
3816
- case 14:
3824
+ case F_SETLK:
3825
+ case F_SETLKW:
3817
3826
  // Pretend that the locking is successful. These are process-level locks,
3818
3827
  // and Emscripten programs are a single process. If we supported linking a
3819
3828
  // filesystem between programs, we'd need to do more here.
3820
3829
  // See https://github.com/emscripten-core/emscripten/issues/23697
3821
3830
  return 0;
3822
3831
  }
3823
- return -28;
3832
+ return -EINVAL;
3824
3833
  } catch (e) {
3825
3834
  if (typeof FS === 'undefined' || !(e.name === 'ErrnoError')) throw e;
3826
3835
  return -e.errno;
3827
3836
  }
3828
3837
  }
3829
3838
 
3830
-
3831
3839
  function ___syscall_fstat64(fd, buf) {
3832
3840
  try {
3833
3841
 
@@ -3838,7 +3846,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3838
3846
  }
3839
3847
  }
3840
3848
 
3841
-
3842
3849
  var convertI32PairToI53Checked = (lo, hi) => {
3843
3850
  assert(lo == (lo >>> 0) || lo == (lo|0)); // lo should either be a i32 or a u32
3844
3851
  assert(hi === (hi|0)); // hi should be a i32
@@ -3850,7 +3857,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3850
3857
 
3851
3858
  try {
3852
3859
 
3853
- if (isNaN(length)) return -22;
3860
+ if (isNaN(length)) return -EFBIG;
3854
3861
  FS.ftruncate(fd, length);
3855
3862
  return 0;
3856
3863
  } catch (e) {
@@ -3859,9 +3866,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3859
3866
  }
3860
3867
  ;
3861
3868
  }
3862
-
3863
-
3864
-
3869
+ const ERANGE = 68;
3865
3870
  var stringToUTF8 = (str, outPtr, maxBytesToWrite) => {
3866
3871
  assert(typeof maxBytesToWrite === 'number', 'stringToUTF8 requires a third parameter that specifies the length of the output buffer');
3867
3872
  return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
@@ -3869,10 +3874,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3869
3874
  function ___syscall_getcwd(buf, size) {
3870
3875
  try {
3871
3876
 
3872
- if (!size) return -28;
3877
+ if (!size) return -EINVAL;
3873
3878
  var cwd = FS.cwd();
3874
3879
  var cwdLengthInBytes = lengthBytesUTF8(cwd) + 1;
3875
- if (size < cwdLengthInBytes) return -68;
3880
+ if (size < cwdLengthInBytes) return -ERANGE;
3876
3881
  stringToUTF8(cwd, buf, size);
3877
3882
  return cwdLengthInBytes;
3878
3883
  } catch (e) {
@@ -3881,11 +3886,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3881
3886
  }
3882
3887
  }
3883
3888
 
3884
-
3885
-
3886
-
3887
-
3888
-
3889
+ const DT_CHR = 2;
3890
+ const DT_DIR = 4;
3891
+ const DT_LNK = 10;
3892
+ const DT_REG = 8;
3889
3893
  function ___syscall_getdents64(fd, dirp, count) {
3890
3894
  try {
3891
3895
 
@@ -3894,7 +3898,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3894
3898
 
3895
3899
  var struct_size = 280;
3896
3900
  var pos = 0;
3897
- var off = FS.llseek(stream, 0, 1);
3901
+ var off = FS.llseek(stream, 0, SEEK_CUR);
3898
3902
 
3899
3903
  var startIdx = Math.floor(off / struct_size);
3900
3904
  var endIdx = Math.min(stream.getdents.length, startIdx + Math.floor(count/struct_size))
@@ -3904,12 +3908,12 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3904
3908
  var name = stream.getdents[idx];
3905
3909
  if (name === '.') {
3906
3910
  id = stream.node.id;
3907
- type = 4;
3911
+ type = DT_DIR;
3908
3912
  }
3909
3913
  else if (name === '..') {
3910
3914
  var lookup = FS.lookupPath(stream.path, { parent: true });
3911
3915
  id = lookup.node.id;
3912
- type = 4;
3916
+ type = DT_DIR;
3913
3917
  }
3914
3918
  else {
3915
3919
  var child;
@@ -3918,26 +3922,26 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3918
3922
  } catch (e) {
3919
3923
  // If the entry is not a directory, file, or symlink, nodefs
3920
3924
  // lookupNode will raise EINVAL. Skip these and continue.
3921
- if (e?.errno === 28) {
3925
+ if (e?.errno === EINVAL) {
3922
3926
  continue;
3923
3927
  }
3924
3928
  throw e;
3925
3929
  }
3926
3930
  id = child.id;
3927
- type = FS.isChrdev(child.mode) ? 2 : // character device.
3928
- FS.isDir(child.mode) ? 4 : // directory
3929
- FS.isLink(child.mode) ? 10 : // symbolic link.
3930
- 8; // regular file.
3931
+ type = FS.isChrdev(child.mode) ? DT_CHR : // character device.
3932
+ FS.isDir(child.mode) ? DT_DIR : // directory
3933
+ FS.isLink(child.mode) ? DT_LNK : // symbolic link.
3934
+ DT_REG; // regular file.
3931
3935
  }
3932
3936
  assert(id);
3933
3937
  (tempI64 = [id>>>0,(tempDouble = id,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((dirp + pos)>>2)] = tempI64[0],HEAP32[(((dirp + pos)+(4))>>2)] = tempI64[1]);
3934
3938
  (tempI64 = [(idx + 1) * struct_size>>>0,(tempDouble = (idx + 1) * struct_size,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((dirp + pos)+(8))>>2)] = tempI64[0],HEAP32[(((dirp + pos)+(12))>>2)] = tempI64[1]);
3935
3939
  HEAP16[(((dirp + pos)+(16))>>1)] = 280;
3936
3940
  HEAP8[(dirp + pos)+(18)] = type;
3937
- stringToUTF8(name, dirp + pos + 19, 256);
3941
+ stringToUTF8(name, dirp + pos + 19, NAME_MAX + 1);
3938
3942
  pos += struct_size;
3939
3943
  }
3940
- FS.llseek(stream, idx * struct_size, 0);
3944
+ FS.llseek(stream, idx * struct_size, SEEK_SET);
3941
3945
  return pos;
3942
3946
  } catch (e) {
3943
3947
  if (typeof FS === 'undefined' || !(e.name === 'ErrnoError')) throw e;
@@ -3945,23 +3949,34 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3945
3949
  }
3946
3950
  }
3947
3951
 
3948
-
3949
-
3950
-
3951
-
3952
-
3952
+ const FIONBIO = 21537;
3953
+ const FIONREAD = 21531;
3954
+ const NCCS = 32;
3955
+ const TCFLSH = 21515;
3956
+ const TCGETA = 21509;
3957
+ const TCGETS = 21505;
3958
+ const TCSETA = 21510;
3959
+ const TCSETAF = 21512;
3960
+ const TCSETAW = 21511;
3961
+ const TCSETS = 21506;
3962
+ const TCSETSF = 21508;
3963
+ const TCSETSW = 21507;
3964
+ const TIOCGPGRP = 21519;
3965
+ const TIOCGWINSZ = 21523;
3966
+ const TIOCSPGRP = 21520;
3967
+ const TIOCSWINSZ = 21524;
3953
3968
  function ___syscall_ioctl(fd, op, varargs) {
3954
3969
  SYSCALLS.varargs = varargs;
3955
3970
  try {
3956
3971
 
3957
3972
  var stream = SYSCALLS.getStreamFromFD(fd);
3958
3973
  switch (op) {
3959
- case 21509: {
3960
- if (!stream.tty) return -59;
3974
+ case TCGETA: {
3975
+ if (!stream.tty) return -ENOTTY;
3961
3976
  return 0;
3962
3977
  }
3963
- case 21505: {
3964
- if (!stream.tty) return -59;
3978
+ case TCGETS: {
3979
+ if (!stream.tty) return -ENOTTY;
3965
3980
  if (stream.tty.ops.ioctl_tcgets) {
3966
3981
  var termios = stream.tty.ops.ioctl_tcgets(stream);
3967
3982
  var argp = syscallGetVarargP();
@@ -3969,23 +3984,23 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3969
3984
  HEAP32[(((argp)+(4))>>2)] = termios.c_oflag || 0;
3970
3985
  HEAP32[(((argp)+(8))>>2)] = termios.c_cflag || 0;
3971
3986
  HEAP32[(((argp)+(12))>>2)] = termios.c_lflag || 0;
3972
- for (var i = 0; i < 32; i++) {
3987
+ for (var i = 0; i < NCCS; i++) {
3973
3988
  HEAP8[(argp + i)+(17)] = termios.c_cc[i] || 0;
3974
3989
  }
3975
3990
  return 0;
3976
3991
  }
3977
3992
  return 0;
3978
3993
  }
3979
- case 21510:
3980
- case 21511:
3981
- case 21512: {
3982
- if (!stream.tty) return -59;
3994
+ case TCSETA:
3995
+ case TCSETAW:
3996
+ case TCSETAF: {
3997
+ if (!stream.tty) return -ENOTTY;
3983
3998
  return 0; // no-op, not actually adjusting terminal settings
3984
3999
  }
3985
- case 21506:
3986
- case 21507:
3987
- case 21508: {
3988
- if (!stream.tty) return -59;
4000
+ case TCSETS:
4001
+ case TCSETSW:
4002
+ case TCSETSF: {
4003
+ if (!stream.tty) return -ENOTTY;
3989
4004
  if (stream.tty.ops.ioctl_tcsets) {
3990
4005
  var argp = syscallGetVarargP();
3991
4006
  var c_iflag = HEAP32[((argp)>>2)];
@@ -3993,32 +4008,32 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3993
4008
  var c_cflag = HEAP32[(((argp)+(8))>>2)];
3994
4009
  var c_lflag = HEAP32[(((argp)+(12))>>2)];
3995
4010
  var c_cc = []
3996
- for (var i = 0; i < 32; i++) {
4011
+ for (var i = 0; i < NCCS; i++) {
3997
4012
  c_cc.push(HEAP8[(argp + i)+(17)]);
3998
4013
  }
3999
4014
  return stream.tty.ops.ioctl_tcsets(stream.tty, op, { c_iflag, c_oflag, c_cflag, c_lflag, c_cc });
4000
4015
  }
4001
4016
  return 0; // no-op, not actually adjusting terminal settings
4002
4017
  }
4003
- case 21519: {
4004
- if (!stream.tty) return -59;
4018
+ case TIOCGPGRP: {
4019
+ if (!stream.tty) return -ENOTTY;
4005
4020
  var argp = syscallGetVarargP();
4006
4021
  HEAP32[((argp)>>2)] = 0;
4007
4022
  return 0;
4008
4023
  }
4009
- case 21520: {
4010
- if (!stream.tty) return -59;
4011
- return -28; // not supported
4024
+ case TIOCSPGRP: {
4025
+ if (!stream.tty) return -ENOTTY;
4026
+ return -EINVAL; // not supported
4012
4027
  }
4013
- case 21537:
4014
- case 21531: {
4028
+ case FIONBIO:
4029
+ case FIONREAD: {
4015
4030
  var argp = syscallGetVarargP();
4016
4031
  return FS.ioctl(stream, op, argp);
4017
4032
  }
4018
- case 21523: {
4033
+ case TIOCGWINSZ: {
4019
4034
  // TODO: in theory we should write to the winsize struct that gets
4020
4035
  // passed in, but for now musl doesn't read anything on it
4021
- if (!stream.tty) return -59;
4036
+ if (!stream.tty) return -ENOTTY;
4022
4037
  if (stream.tty.ops.ioctl_tiocgwinsz) {
4023
4038
  var winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty);
4024
4039
  var argp = syscallGetVarargP();
@@ -4027,18 +4042,18 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4027
4042
  }
4028
4043
  return 0;
4029
4044
  }
4030
- case 21524: {
4045
+ case TIOCSWINSZ: {
4031
4046
  // TODO: technically, this ioctl call should change the window size.
4032
4047
  // but, since emscripten doesn't have any concept of a terminal window
4033
4048
  // yet, we'll just silently throw it away as we do TIOCGWINSZ
4034
- if (!stream.tty) return -59;
4049
+ if (!stream.tty) return -ENOTTY;
4035
4050
  return 0;
4036
4051
  }
4037
- case 21515: {
4038
- if (!stream.tty) return -59;
4052
+ case TCFLSH: {
4053
+ if (!stream.tty) return -ENOTTY;
4039
4054
  return 0;
4040
4055
  }
4041
- default: return -28; // not supported
4056
+ default: return -EINVAL; // not supported
4042
4057
  }
4043
4058
  } catch (e) {
4044
4059
  if (typeof FS === 'undefined' || !(e.name === 'ErrnoError')) throw e;
@@ -4046,7 +4061,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4046
4061
  }
4047
4062
  }
4048
4063
 
4049
-
4050
4064
  function ___syscall_lstat64(path, buf) {
4051
4065
  try {
4052
4066
 
@@ -4058,7 +4072,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4058
4072
  }
4059
4073
  }
4060
4074
 
4061
-
4062
4075
  function ___syscall_mkdirat(dirfd, path, mode) {
4063
4076
  try {
4064
4077
 
@@ -4073,14 +4086,16 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4073
4086
  }
4074
4087
  }
4075
4088
 
4076
-
4089
+ const AT_EMPTY_PATH = 4096;
4090
+ const AT_NO_AUTOMOUNT = 2048;
4091
+ const AT_SYMLINK_NOFOLLOW = 256;
4077
4092
  function ___syscall_newfstatat(dirfd, path, buf, flags) {
4078
4093
  try {
4079
4094
 
4080
4095
  path = SYSCALLS.getStr(path);
4081
- var nofollow = flags & 256;
4082
- var allowEmpty = flags & 4096;
4083
- flags = flags & (~6400);
4096
+ var nofollow = flags & AT_SYMLINK_NOFOLLOW;
4097
+ var allowEmpty = flags & AT_EMPTY_PATH;
4098
+ flags = flags & (~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH | AT_NO_AUTOMOUNT));
4084
4099
  assert(!flags, `unknown flags in __syscall_newfstatat: ${flags}`);
4085
4100
  path = SYSCALLS.calculateAt(dirfd, path, allowEmpty);
4086
4101
  return SYSCALLS.writeStat(buf, nofollow ? FS.lstat(path) : FS.stat(path));
@@ -4090,8 +4105,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4090
4105
  }
4091
4106
  }
4092
4107
 
4093
-
4094
-
4095
4108
  function ___syscall_openat(dirfd, path, flags, varargs) {
4096
4109
  SYSCALLS.varargs = varargs;
4097
4110
  try {
@@ -4099,7 +4112,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4099
4112
  path = SYSCALLS.getStr(path);
4100
4113
  path = SYSCALLS.calculateAt(dirfd, path);
4101
4114
  var mode = varargs ? syscallGetVarargI() : 0;
4102
- if (flags & 64) {
4115
+ if (flags & O_CREAT) {
4103
4116
  mode &= ~SYSCALLS.currentUmask;
4104
4117
  }
4105
4118
  return FS.open(path, flags, mode).fd;
@@ -4109,7 +4122,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4109
4122
  }
4110
4123
  }
4111
4124
 
4112
-
4113
4125
  function ___syscall_rmdir(path) {
4114
4126
  try {
4115
4127
 
@@ -4122,7 +4134,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4122
4134
  }
4123
4135
  }
4124
4136
 
4125
-
4126
4137
  function ___syscall_stat64(path, buf) {
4127
4138
  try {
4128
4139
 
@@ -4134,7 +4145,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4134
4145
  }
4135
4146
  }
4136
4147
 
4137
-
4148
+ const AT_REMOVEDIR = 512;
4138
4149
  function ___syscall_unlinkat(dirfd, path, flags) {
4139
4150
  try {
4140
4151
 
@@ -4142,10 +4153,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4142
4153
  path = SYSCALLS.calculateAt(dirfd, path);
4143
4154
  if (!flags) {
4144
4155
  FS.unlink(path);
4145
- } else if (flags === 512) {
4156
+ } else if (flags === AT_REMOVEDIR) {
4146
4157
  FS.rmdir(path);
4147
4158
  } else {
4148
- return -28;
4159
+ return -EINVAL;
4149
4160
  }
4150
4161
  return 0;
4151
4162
  } catch (e) {
@@ -4154,17 +4165,15 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4154
4165
  }
4155
4166
  }
4156
4167
 
4157
-
4158
-
4168
+ const UTIME_NOW = 1073741823;
4169
+ const UTIME_OMIT = 1073741822;
4159
4170
  var readI53FromI64 = (ptr) => {
4160
4171
  return HEAPU32[((ptr)>>2)] + HEAP32[(((ptr)+(4))>>2)] * 4294967296;
4161
4172
  };
4162
-
4163
-
4164
4173
  function ___syscall_utimensat(dirfd, path, times, flags) {
4165
4174
  try {
4166
4175
 
4167
- var nofollow = flags & 256;
4176
+ var nofollow = flags & AT_SYMLINK_NOFOLLOW;
4168
4177
  path = SYSCALLS.getStr(path);
4169
4178
  path = SYSCALLS.calculateAt(dirfd, path, true);
4170
4179
  var now = Date.now(), atime, mtime;
@@ -4174,10 +4183,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4174
4183
  } else {
4175
4184
  function readTimespec(ptr) {
4176
4185
  var tv_nsec = HEAP32[(((ptr)+(8))>>2)];
4177
- if (tv_nsec == 1073741823) {
4186
+ if (tv_nsec == UTIME_NOW) {
4178
4187
  return now;
4179
4188
  }
4180
- if (tv_nsec == 1073741822) {
4189
+ if (tv_nsec == UTIME_OMIT) {
4181
4190
  return null;
4182
4191
  }
4183
4192
  var tv_sec = readI53FromI64(ptr);
@@ -4198,30 +4207,35 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4198
4207
  }
4199
4208
  }
4200
4209
 
4201
-
4202
4210
  var __abort_js = () =>
4203
4211
  abort('native code called abort()');
4204
-
4205
- var __embind_register_bigint = (primitiveType, name, size, minRange, maxRange) => {};
4206
-
4212
+ var __embind_register_bigint = (typeID, name, size, minRange, maxRange) => {};
4213
+ var AsciiToString_cache = {
4214
+ };
4207
4215
  var AsciiToString = (ptr) => {
4216
+ var origPtr = ptr;
4217
+ var useCache = ptr >= 1024 && ptr < 966500;
4218
+ if (useCache) {
4219
+ var rtn = AsciiToString_cache[origPtr];
4220
+ if (rtn != null) {
4221
+ return rtn;
4222
+ }
4223
+ }
4208
4224
  var str = '';
4209
4225
  while (1) {
4210
4226
  var ch = HEAPU8[ptr++];
4211
- if (!ch) return str;
4227
+ if (!ch) break;
4212
4228
  str += String.fromCharCode(ch);
4213
4229
  }
4230
+ if (useCache) {
4231
+ AsciiToString_cache[origPtr] = str;
4232
+ }
4233
+ return str;
4214
4234
  };
4215
-
4216
4235
  var awaitingDependencies = {
4217
4236
  };
4218
-
4219
4237
  var registeredTypes = {
4220
4238
  };
4221
-
4222
- var typeDependencies = {
4223
- };
4224
-
4225
4239
  class BindingError extends Error {
4226
4240
  constructor(message) {
4227
4241
  super(message);
@@ -4229,13 +4243,15 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4229
4243
  }
4230
4244
  }
4231
4245
  var throwBindingError = (message) => { throw new BindingError(message); };
4246
+ var typeDependencies = {
4247
+ };
4232
4248
  /** @param {Object=} options */
4233
- function sharedRegisterType(rawType, registeredInstance, options = {}) {
4249
+ function sharedRegisterType(typeID, registeredInstance, options = {}) {
4234
4250
  var name = registeredInstance.name;
4235
- if (!rawType) {
4251
+ if (!typeID) {
4236
4252
  throwBindingError(`type "${name}" must have a positive integer typeid pointer`);
4237
4253
  }
4238
- if (registeredTypes.hasOwnProperty(rawType)) {
4254
+ if (registeredTypes[typeID]) {
4239
4255
  if (options.ignoreDuplicateRegistrations) {
4240
4256
  return;
4241
4257
  } else {
@@ -4243,24 +4259,23 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4243
4259
  }
4244
4260
  }
4245
4261
 
4246
- registeredTypes[rawType] = registeredInstance;
4247
- delete typeDependencies[rawType];
4262
+ registeredTypes[typeID] = registeredInstance;
4263
+ delete typeDependencies[typeID];
4248
4264
 
4249
- if (awaitingDependencies.hasOwnProperty(rawType)) {
4250
- var callbacks = awaitingDependencies[rawType];
4251
- delete awaitingDependencies[rawType];
4265
+ if (awaitingDependencies[typeID]) {
4266
+ var callbacks = awaitingDependencies[typeID];
4267
+ delete awaitingDependencies[typeID];
4252
4268
  callbacks.forEach((cb) => cb());
4253
4269
  }
4254
4270
  }
4255
4271
  /** @param {Object=} options */
4256
- function registerType(rawType, registeredInstance, options = {}) {
4257
- return sharedRegisterType(rawType, registeredInstance, options);
4272
+ function registerType(typeID, registeredInstance, options = {}) {
4273
+ return sharedRegisterType(typeID, registeredInstance, options);
4258
4274
  }
4259
-
4260
4275
  /** @suppress {globalThis} */
4261
- var __embind_register_bool = (rawType, name, trueValue, falseValue) => {
4276
+ var __embind_register_bool = (typeID, name, trueValue, falseValue) => {
4262
4277
  name = AsciiToString(name);
4263
- registerType(rawType, {
4278
+ registerType(typeID, {
4264
4279
  name,
4265
4280
  fromWireType: function(wt) {
4266
4281
  // ambiguous emscripten ABI: sometimes return values are
@@ -4273,50 +4288,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4273
4288
  readValueFromPointer: function(pointer) {
4274
4289
  return this.fromWireType(HEAPU8[pointer]);
4275
4290
  },
4276
- destructorFunction: null, // This type does not need a destructor
4277
4291
  });
4278
4292
  };
4279
-
4280
-
4281
-
4282
- var shallowCopyInternalPointer = (o) => {
4283
- return {
4284
- count: o.count,
4285
- deleteScheduled: o.deleteScheduled,
4286
- preservePointerOnDelete: o.preservePointerOnDelete,
4287
- ptr: o.ptr,
4288
- ptrType: o.ptrType,
4289
- smartPtr: o.smartPtr,
4290
- smartPtrType: o.smartPtrType,
4291
- };
4292
- };
4293
-
4294
- var throwInstanceAlreadyDeleted = (obj) => {
4295
- function getInstanceTypeName(handle) {
4296
- return handle.$$.ptrType.registeredClass.name;
4297
- }
4298
- throwBindingError(getInstanceTypeName(obj) + ' instance already deleted');
4299
- };
4300
-
4301
- var finalizationRegistry = false;
4302
-
4303
- var detachFinalizer = (handle) => {};
4304
-
4305
- var runDestructor = ($$) => {
4306
- if ($$.smartPtr) {
4307
- $$.smartPtrType.rawDestructor($$.smartPtr);
4308
- } else {
4309
- $$.ptrType.registeredClass.rawDestructor($$.ptr);
4310
- }
4311
- };
4312
- var releaseClassHandle = ($$) => {
4313
- $$.count.value -= 1;
4314
- var toDelete = 0 === $$.count.value;
4315
- if (toDelete) {
4316
- runDestructor($$);
4317
- }
4318
- };
4319
-
4320
4293
  var downcastPointer = (ptr, ptrClass, desiredClass) => {
4321
4294
  if (ptrClass === desiredClass) {
4322
4295
  return ptr;
@@ -4331,13 +4304,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4331
4304
  }
4332
4305
  return desiredClass.downcast(rv);
4333
4306
  };
4334
-
4335
- var registeredPointers = {
4336
- };
4337
-
4338
- var registeredInstances = {
4339
- };
4340
-
4341
4307
  var getBasestPointer = (class_, ptr) => {
4342
4308
  if (ptr === undefined) {
4343
4309
  throwBindingError('ptr should not be undefined');
@@ -4348,11 +4314,11 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4348
4314
  }
4349
4315
  return ptr;
4350
4316
  };
4317
+ var registeredInstances = new Map;
4351
4318
  var getInheritedInstance = (class_, ptr) => {
4352
4319
  ptr = getBasestPointer(class_, ptr);
4353
- return registeredInstances[ptr];
4320
+ return registeredInstances.get(ptr);
4354
4321
  };
4355
-
4356
4322
  class InternalError extends Error {
4357
4323
  constructor(message) {
4358
4324
  super(message);
@@ -4360,7 +4326,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4360
4326
  }
4361
4327
  }
4362
4328
  var throwInternalError = (message) => { throw new InternalError(message); };
4363
-
4364
4329
  var makeClassHandle = (prototype, record) => {
4365
4330
  if (!record.ptrType || !record.ptr) {
4366
4331
  throwInternalError('makeClassHandle requires ptr and ptrType');
@@ -4378,6 +4343,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4378
4343
  },
4379
4344
  }));
4380
4345
  };
4346
+ var registeredPointers = {
4347
+ };
4381
4348
  /** @suppress {globalThis} */
4382
4349
  function RegisteredPointer_fromWireType(ptr) {
4383
4350
  // ptr is a raw pointer (or a raw smartpointer)
@@ -4453,7 +4420,23 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4453
4420
  ptr: dp,
4454
4421
  });
4455
4422
  }
4456
- }
4423
+ }
4424
+ var finalizationRegistry = false;
4425
+ var detachFinalizer = (handle) => {};
4426
+ var runDestructor = ($$) => {
4427
+ if ($$.smartPtr) {
4428
+ $$.smartPtrType.rawDestructor($$.smartPtr);
4429
+ } else {
4430
+ $$.ptrType.registeredClass.rawDestructor($$.ptr);
4431
+ }
4432
+ };
4433
+ var releaseClassHandle = ($$) => {
4434
+ $$.count.value -= 1;
4435
+ var toDelete = 0 === $$.count.value;
4436
+ if (toDelete) {
4437
+ runDestructor($$);
4438
+ }
4439
+ };
4457
4440
  var attachFinalizer = (handle) => {
4458
4441
  if (!globalThis.FinalizationRegistry) {
4459
4442
  attachFinalizer = (handle) => handle;
@@ -4493,10 +4476,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4493
4476
  detachFinalizer = (handle) => finalizationRegistry.unregister(handle);
4494
4477
  return attachFinalizer(handle);
4495
4478
  };
4496
-
4497
-
4498
-
4499
-
4479
+ var delayFunction;
4500
4480
  var deletionQueue = [];
4501
4481
  var flushPendingDeletes = () => {
4502
4482
  while (deletionQueue.length) {
@@ -4505,8 +4485,23 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4505
4485
  obj['delete']();
4506
4486
  }
4507
4487
  };
4508
-
4509
- var delayFunction;
4488
+ var shallowCopyInternalPointer = (o) => {
4489
+ return {
4490
+ count: o.count,
4491
+ deleteScheduled: o.deleteScheduled,
4492
+ preservePointerOnDelete: o.preservePointerOnDelete,
4493
+ ptr: o.ptr,
4494
+ ptrType: o.ptrType,
4495
+ smartPtr: o.smartPtr,
4496
+ smartPtrType: o.smartPtrType,
4497
+ };
4498
+ };
4499
+ var throwInstanceAlreadyDeleted = (obj) => {
4500
+ function getInstanceTypeName(handle) {
4501
+ return handle.$$.ptrType.registeredClass.name;
4502
+ }
4503
+ throwBindingError(getInstanceTypeName(obj) + ' instance already deleted');
4504
+ };
4510
4505
  var init_ClassHandle = () => {
4511
4506
  let proto = ClassHandle.prototype;
4512
4507
 
@@ -4606,62 +4601,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4606
4601
  /** @constructor */
4607
4602
  function ClassHandle() {
4608
4603
  }
4609
-
4610
- var createNamedFunction = (name, func) => Object.defineProperty(func, 'name', { value: name });
4611
-
4612
-
4613
- var ensureOverloadTable = (proto, methodName, humanName) => {
4614
- if (undefined === proto[methodName].overloadTable) {
4615
- var prevFunc = proto[methodName];
4616
- // Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
4617
- proto[methodName] = function(...args) {
4618
- // TODO This check can be removed in -O3 level "unsafe" optimizations.
4619
- if (!proto[methodName].overloadTable.hasOwnProperty(args.length)) {
4620
- throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${args.length}) - expects one of (${proto[methodName].overloadTable})!`);
4621
- }
4622
- return proto[methodName].overloadTable[args.length].apply(this, args);
4623
- };
4624
- // Move the previous function into the overload table.
4625
- proto[methodName].overloadTable = [];
4626
- proto[methodName].overloadTable[prevFunc.argCount] = prevFunc;
4627
- }
4628
- };
4629
-
4630
- /** @param {number=} numArguments */
4631
- var exposePublicSymbol = (name, value, numArguments) => {
4632
- if (Module.hasOwnProperty(name)) {
4633
- if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
4634
- throwBindingError(`Cannot register public name '${name}' twice`);
4635
- }
4636
-
4637
- // We are exposing a function with the same name as an existing function. Create an overload table and a function selector
4638
- // that routes between the two.
4639
- ensureOverloadTable(Module, name, name);
4640
- if (Module[name].overloadTable.hasOwnProperty(numArguments)) {
4641
- throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
4642
- }
4643
- // Add the new function into the overload table.
4644
- Module[name].overloadTable[numArguments] = value;
4645
- } else {
4646
- Module[name] = value;
4647
- Module[name].argCount = numArguments;
4648
- }
4649
- };
4650
-
4651
- var char_0 = 48;
4652
-
4653
- var char_9 = 57;
4654
- var makeLegalFunctionName = (name) => {
4655
- assert(typeof name === 'string');
4656
- name = name.replace(/[^a-zA-Z0-9_]/g, '$');
4657
- var f = name.charCodeAt(0);
4658
- if (f >= char_0 && f <= char_9) {
4659
- return `_${name}`;
4660
- }
4661
- return name;
4662
- };
4663
-
4664
-
4665
4604
  /** @constructor */
4666
4605
  function RegisteredClass(name,
4667
4606
  constructor,
@@ -4681,19 +4620,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4681
4620
  this.downcast = downcast;
4682
4621
  this.pureVirtualFunctions = [];
4683
4622
  }
4684
-
4685
-
4686
- var upcastPointer = (ptr, ptrClass, desiredClass) => {
4687
- while (ptrClass !== desiredClass) {
4688
- if (!ptrClass.upcast) {
4689
- throwBindingError(`Expected null or instance of ${desiredClass.name}, got an instance of ${ptrClass.name}`);
4690
- }
4691
- ptr = ptrClass.upcast(ptr);
4692
- ptrClass = ptrClass.baseClass;
4693
- }
4694
- return ptr;
4695
- };
4696
-
4697
4623
  var embindRepr = (v) => {
4698
4624
  if (v === null) {
4699
4625
  return 'null';
@@ -4705,6 +4631,16 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4705
4631
  return '' + v;
4706
4632
  }
4707
4633
  };
4634
+ var upcastPointer = (ptr, ptrClass, desiredClass) => {
4635
+ while (ptrClass !== desiredClass) {
4636
+ if (!ptrClass.upcast) {
4637
+ throwBindingError(`Expected null or instance of ${desiredClass.name}, got an instance of ${ptrClass.name}`);
4638
+ }
4639
+ ptr = ptrClass.upcast(ptr);
4640
+ ptrClass = ptrClass.baseClass;
4641
+ }
4642
+ return ptr;
4643
+ };
4708
4644
  /** @suppress {globalThis} */
4709
4645
  function constNoSmartPtrRawPointerToWireType(destructors, handle) {
4710
4646
  if (handle === null) {
@@ -4724,8 +4660,32 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4724
4660
  var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
4725
4661
  return ptr;
4726
4662
  }
4727
-
4728
-
4663
+ var emval_freelist = [];
4664
+ const EMVAL_RESERVED_HANDLES = 5;
4665
+ var emval_handles = [0,1,,1,null,1,true,1,false,1];
4666
+ var Emval = {
4667
+ toValue:(handle) => {
4668
+ if (!handle) {
4669
+ throwBindingError(`Cannot use deleted val. handle = ${handle}`);
4670
+ }
4671
+ assert(handle === 2 || emval_handles[handle] !== undefined && handle % 2 === 0, `invalid handle: ${handle}`);
4672
+ return emval_handles[handle];
4673
+ },
4674
+ toHandle:(value) => {
4675
+ switch (value) {
4676
+ case undefined: return 2;
4677
+ case null: return 4;
4678
+ case true: return 6;
4679
+ case false: return 8;
4680
+ default:{
4681
+ const handle = emval_freelist.pop() || emval_handles.length;
4682
+ emval_handles[handle] = value;
4683
+ emval_handles[handle + 1] = 1;
4684
+ return handle;
4685
+ }
4686
+ }
4687
+ },
4688
+ };
4729
4689
  /** @suppress {globalThis} */
4730
4690
  function genericPointerToWireType(destructors, handle) {
4731
4691
  var ptr;
@@ -4766,7 +4726,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4766
4726
  }
4767
4727
 
4768
4728
  switch (this.sharingPolicy) {
4769
- case 0: // NONE
4729
+ case 0:
4770
4730
  // no upcasting
4771
4731
  if (handle.$$.smartPtrType === this) {
4772
4732
  ptr = handle.$$.smartPtr;
@@ -4775,11 +4735,11 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4775
4735
  }
4776
4736
  break;
4777
4737
 
4778
- case 1: // INTRUSIVE
4738
+ case 1:
4779
4739
  ptr = handle.$$.smartPtr;
4780
4740
  break;
4781
4741
 
4782
- case 2: // BY_EMVAL
4742
+ case 2:
4783
4743
  if (handle.$$.smartPtrType === this) {
4784
4744
  ptr = handle.$$.smartPtr;
4785
4745
  } else {
@@ -4800,9 +4760,25 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4800
4760
  }
4801
4761
  return ptr;
4802
4762
  }
4803
-
4804
-
4805
-
4763
+ /** @suppress {globalThis} */
4764
+ function readPointer(pointer) {
4765
+ return this.fromWireType(HEAPU32[((pointer)>>2)]);
4766
+ }
4767
+ var init_RegisteredPointer = () => {
4768
+ Object.assign(RegisteredPointer.prototype, {
4769
+ getPointee(ptr) {
4770
+ if (this.rawGetPointee) {
4771
+ ptr = this.rawGetPointee(ptr);
4772
+ }
4773
+ return ptr;
4774
+ },
4775
+ destructor(ptr) {
4776
+ this.rawDestructor?.(ptr);
4777
+ },
4778
+ readValueFromPointer: readPointer,
4779
+ fromWireType: RegisteredPointer_fromWireType,
4780
+ });
4781
+ };
4806
4782
  /** @suppress {globalThis} */
4807
4783
  function nonConstNoSmartPtrRawPointerToWireType(destructors, handle) {
4808
4784
  if (handle === null) {
@@ -4825,28 +4801,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4825
4801
  var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
4826
4802
  return ptr;
4827
4803
  }
4828
-
4829
-
4830
- /** @suppress {globalThis} */
4831
- function readPointer(pointer) {
4832
- return this.fromWireType(HEAPU32[((pointer)>>2)]);
4833
- }
4834
-
4835
- var init_RegisteredPointer = () => {
4836
- Object.assign(RegisteredPointer.prototype, {
4837
- getPointee(ptr) {
4838
- if (this.rawGetPointee) {
4839
- ptr = this.rawGetPointee(ptr);
4840
- }
4841
- return ptr;
4842
- },
4843
- destructor(ptr) {
4844
- this.rawDestructor?.(ptr);
4845
- },
4846
- readValueFromPointer: readPointer,
4847
- fromWireType: RegisteredPointer_fromWireType,
4848
- });
4849
- };
4850
4804
  /** @constructor
4851
4805
  @param {*=} pointeeType,
4852
4806
  @param {*=} sharingPolicy,
@@ -4887,36 +4841,17 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4887
4841
  if (!isSmartPointer && registeredClass.baseClass === undefined) {
4888
4842
  if (isConst) {
4889
4843
  this.toWireType = constNoSmartPtrRawPointerToWireType;
4890
- this.destructorFunction = null;
4891
4844
  } else {
4892
4845
  this.toWireType = nonConstNoSmartPtrRawPointerToWireType;
4893
- this.destructorFunction = null;
4894
4846
  }
4895
4847
  } else {
4896
4848
  this.toWireType = genericPointerToWireType;
4897
- // Here we must leave this.destructorFunction undefined, since whether genericPointerToWireType returns
4898
- // a pointer that needs to be freed up is runtime-dependent, and cannot be evaluated at registration time.
4899
- // TODO: Create an alternative mechanism that allows removing the use of var destructors = []; array in
4900
- // craftInvokerFunction altogether.
4849
+ if (isSmartPointer) {
4850
+ this.usesDestructor = true;
4851
+ }
4901
4852
  }
4902
4853
  }
4903
-
4904
- /** @param {number=} numArguments */
4905
- var replacePublicSymbol = (name, value, numArguments) => {
4906
- if (!Module.hasOwnProperty(name)) {
4907
- throwInternalError('Replacing nonexistent public symbol');
4908
- }
4909
- // If there's an overload table for this symbol, replace the symbol in the overload table instead.
4910
- if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
4911
- Module[name].overloadTable[numArguments] = value;
4912
- } else {
4913
- Module[name] = value;
4914
- Module[name].argCount = numArguments;
4915
- }
4916
- };
4917
-
4918
-
4919
-
4854
+ var createNamedFunction = (name, func) => Object.defineProperty(func, 'name', { value: name });
4920
4855
  var dynCalls = {
4921
4856
  };
4922
4857
  var dynCallLegacy = (sig, ptr, args) => {
@@ -4931,10 +4866,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4931
4866
  var f = dynCalls[sig];
4932
4867
  return f(ptr, ...args);
4933
4868
  };
4934
-
4935
4869
  var wasmTableMirror = [];
4936
-
4937
-
4938
4870
  var getWasmTableEntry = (funcPtr) => {
4939
4871
  var func = wasmTableMirror[funcPtr];
4940
4872
  if (!func) {
@@ -4945,7 +4877,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4945
4877
  assert(wasmTable.get(funcPtr) == func, 'table mirror is out of date');
4946
4878
  return func;
4947
4879
  };
4948
-
4949
4880
  var dynCall = (sig, ptr, args = [], promising = false) => {
4950
4881
  assert(ptr, `null function pointer in dynCall`);
4951
4882
  assert(!promising, 'async dynCall is not supported in this mode')
@@ -4962,43 +4893,97 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
4962
4893
  function convert(rtn) {
4963
4894
  return rtn;
4964
4895
  }
4965
-
4966
- return convert(rtn);
4967
- };
4968
- var getDynCaller = (sig, ptr, promising = false) => {
4969
- assert(sig.includes('j') || sig.includes('p'), 'getDynCaller should only be called with i64 sigs')
4970
- return (...args) => dynCall(sig, ptr, args, promising);
4896
+
4897
+ return convert(rtn);
4898
+ };
4899
+ var getDynCaller = (sig, ptr, promising = false) => {
4900
+ assert(sig.includes('j') || sig.includes('p'), 'getDynCaller should only be called with i64 sigs')
4901
+ return (...args) => dynCall(sig, ptr, args, promising);
4902
+ };
4903
+ var embind__requireFunction = (signature, rawFunction, isAsync = false) => {
4904
+ assert(!isAsync, 'async bindings are only supported with JSPI');
4905
+
4906
+ signature = AsciiToString(signature);
4907
+
4908
+ function makeDynCaller() {
4909
+ if (signature.includes('j')) {
4910
+ return getDynCaller(signature, rawFunction);
4911
+ }
4912
+ var rtn = getWasmTableEntry(rawFunction);
4913
+ return rtn;
4914
+ }
4915
+
4916
+ var fp = makeDynCaller();
4917
+ if (typeof fp !== 'function') {
4918
+ throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);
4919
+ }
4920
+ return fp;
4921
+ };
4922
+ var ensureOverloadTable = (proto, methodName, humanName) => {
4923
+ if (undefined === proto[methodName].overloadTable) {
4924
+ var prevFunc = proto[methodName];
4925
+ // Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
4926
+ proto[methodName] = function(...args) {
4927
+ // TODO This check can be removed in -O3 level "unsafe" optimizations.
4928
+ if (!proto[methodName].overloadTable[args.length]) {
4929
+ throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${args.length}) - expects one of (${proto[methodName].overloadTable})!`);
4930
+ }
4931
+ return proto[methodName].overloadTable[args.length].apply(this, args);
4932
+ };
4933
+ // Move the previous function into the overload table.
4934
+ proto[methodName].overloadTable = [];
4935
+ proto[methodName].overloadTable[prevFunc.argCount] = prevFunc;
4936
+ }
4937
+ };
4938
+ /** @type {function(?, ?): boolean} */
4939
+ var hasOwn = Object.hasOwn;
4940
+ /** @param {number=} numArguments */
4941
+ var exposePublicSymbol = (name, value, numArguments) => {
4942
+ if (hasOwn(Module, name)) {
4943
+ if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
4944
+ throwBindingError(`Cannot register public name '${name}' twice`);
4945
+ }
4946
+
4947
+ // We are exposing a function with the same name as an existing function. Create an overload table and a function selector
4948
+ // that routes between the two.
4949
+ ensureOverloadTable(Module, name, name);
4950
+ if (Module[name].overloadTable[numArguments]) {
4951
+ throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
4952
+ }
4953
+ // Add the new function into the overload table.
4954
+ Module[name].overloadTable[numArguments] = value;
4955
+ } else {
4956
+ Module[name] = value;
4957
+ Module[name].argCount = numArguments;
4958
+ }
4959
+ };
4960
+ const char_0 = 48;
4961
+ const char_9 = 57;
4962
+ var makeLegalFunctionName = (name) => {
4963
+ assert(typeof name === 'string');
4964
+ name = name.replace(/[^a-zA-Z0-9_]/g, '$');
4965
+ var f = name.charCodeAt(0);
4966
+ if (f >= char_0 && f <= char_9) {
4967
+ return `_${name}`;
4968
+ }
4969
+ return name;
4971
4970
  };
4972
-
4973
-
4974
- var embind__requireFunction = (signature, rawFunction, isAsync = false) => {
4975
- assert(!isAsync, 'async bindings are only supported with JSPI');
4976
-
4977
- signature = AsciiToString(signature);
4978
-
4979
- function makeDynCaller() {
4980
- if (signature.includes('j')) {
4981
- return getDynCaller(signature, rawFunction);
4982
- }
4983
- var rtn = getWasmTableEntry(rawFunction);
4984
- return rtn;
4971
+ /** @param {number=} numArguments */
4972
+ var replacePublicSymbol = (name, value, numArguments) => {
4973
+ if (!hasOwn(Module, name)) {
4974
+ throwInternalError('Replacing nonexistent public symbol');
4985
4975
  }
4986
-
4987
- var fp = makeDynCaller();
4988
- if (typeof fp !== 'function') {
4989
- throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);
4976
+ // If there's an overload table for this symbol, replace the symbol in the overload table instead.
4977
+ if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
4978
+ Module[name].overloadTable[numArguments] = value;
4979
+ } else {
4980
+ Module[name] = value;
4981
+ Module[name].argCount = numArguments;
4990
4982
  }
4991
- return fp;
4992
4983
  };
4993
-
4994
-
4995
-
4996
4984
  class UnboundTypeError extends Error {}
4997
-
4998
-
4999
-
5000
- var getTypeName = (type) => {
5001
- var ptr = ___getTypeName(type);
4985
+ var getTypeName = (typeID) => {
4986
+ var ptr = ___getTypeName(typeID);
5002
4987
  var rv = AsciiToString(ptr);
5003
4988
  _free(ptr);
5004
4989
  return rv;
@@ -5024,10 +5009,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5024
5009
 
5025
5010
  throw new UnboundTypeError(`${message}: ` + unboundTypes.map(getTypeName).join([', ']));
5026
5011
  };
5027
-
5028
-
5029
-
5030
-
5031
5012
  var whenDependentTypesAreResolved = (myTypes, dependentTypes, getTypeConverters) => {
5032
5013
  myTypes.forEach((type) => typeDependencies[type] = dependentTypes);
5033
5014
 
@@ -5045,14 +5026,11 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5045
5026
  var unregisteredTypes = [];
5046
5027
  var registered = 0;
5047
5028
  for (let [i, dt] of dependentTypes.entries()) {
5048
- if (registeredTypes.hasOwnProperty(dt)) {
5029
+ if (registeredTypes[dt]) {
5049
5030
  typeConverters[i] = registeredTypes[dt];
5050
5031
  } else {
5051
5032
  unregisteredTypes.push(dt);
5052
- if (!awaitingDependencies.hasOwnProperty(dt)) {
5053
- awaitingDependencies[dt] = [];
5054
- }
5055
- awaitingDependencies[dt].push(() => {
5033
+ (awaitingDependencies[dt] ??= []).push(() => {
5056
5034
  typeConverters[i] = registeredTypes[dt];
5057
5035
  ++registered;
5058
5036
  if (registered === unregisteredTypes.length) {
@@ -5065,10 +5043,10 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5065
5043
  onComplete(typeConverters);
5066
5044
  }
5067
5045
  };
5068
- var __embind_register_class = (rawType,
5069
- rawPointerType,
5070
- rawConstPointerType,
5071
- baseClassRawType,
5046
+ var __embind_register_class = (typeID,
5047
+ pointerTypeID,
5048
+ constPointerTypeID,
5049
+ baseClassTypeID,
5072
5050
  getActualTypeSignature,
5073
5051
  getActualType,
5074
5052
  upcastSignature,
@@ -5086,19 +5064,19 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5086
5064
  var legalFunctionName = makeLegalFunctionName(name);
5087
5065
 
5088
5066
  exposePublicSymbol(legalFunctionName, function() {
5089
- // this code cannot run if baseClassRawType is zero
5090
- throwUnboundTypeError(`Cannot construct ${name} due to unbound types`, [baseClassRawType]);
5067
+ // this code cannot run if baseClassTypeID is zero
5068
+ throwUnboundTypeError(`Cannot construct ${name} due to unbound types`, [baseClassTypeID]);
5091
5069
  });
5092
5070
 
5093
5071
  whenDependentTypesAreResolved(
5094
- [rawType, rawPointerType, rawConstPointerType],
5095
- baseClassRawType ? [baseClassRawType] : [],
5072
+ [typeID, pointerTypeID, constPointerTypeID],
5073
+ baseClassTypeID ? [baseClassTypeID] : [],
5096
5074
  (base) => {
5097
5075
  base = base[0];
5098
5076
 
5099
5077
  var baseClass;
5100
5078
  var basePrototype;
5101
- if (baseClassRawType) {
5079
+ if (baseClassTypeID) {
5102
5080
  baseClass = base.registeredClass;
5103
5081
  basePrototype = baseClass.instancePrototype;
5104
5082
  } else {
@@ -5159,7 +5137,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5159
5137
  true,
5160
5138
  false);
5161
5139
 
5162
- registeredPointers[rawType] = {
5140
+ registeredPointers[typeID] = {
5163
5141
  pointerType: pointerConverter,
5164
5142
  constPointerType: constPointerConverter
5165
5143
  };
@@ -5170,40 +5148,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5170
5148
  }
5171
5149
  );
5172
5150
  };
5173
-
5174
- var heap32VectorToArray = (count, firstElement) => {
5175
- var array = [];
5176
- for (var i = 0; i < count; i++) {
5177
- // TODO(https://github.com/emscripten-core/emscripten/issues/17310):
5178
- // Find a way to hoist the `>> 2` or `>> 3` out of this loop.
5179
- array.push(HEAPU32[(((firstElement)+(i * 4))>>2)]);
5180
- }
5181
- return array;
5182
- };
5183
-
5184
-
5185
-
5186
-
5187
- var runDestructors = (destructors) => {
5188
- while (destructors.length) {
5189
- var ptr = destructors.pop();
5190
- var del = destructors.pop();
5191
- del(ptr);
5192
- }
5193
- };
5194
-
5195
-
5196
- function usesDestructorStack(argTypes) {
5197
- // Skip return value at index 0 - it's not deleted here.
5198
- for (var i = 1; i < argTypes.length; ++i) {
5199
- // The type does not define a destructor function - must use dynamic stack
5200
- if (argTypes[i] !== null && argTypes[i].destructorFunction === undefined) {
5201
- return true;
5202
- }
5203
- }
5204
- return false;
5205
- }
5206
-
5207
5151
  function argsUseStackAlloc(argTypes) {
5208
5152
  // Skip return value at index 0 - only arguments stack-allocate.
5209
5153
  for (var i = 1; i < argTypes.length; ++i) {
@@ -5213,117 +5157,195 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5213
5157
  }
5214
5158
  return false;
5215
5159
  }
5216
-
5217
-
5218
-
5219
-
5220
-
5221
5160
  function checkArgCount(numArgs, minArgs, maxArgs, humanName, throwBindingError) {
5222
5161
  if (numArgs < minArgs || numArgs > maxArgs) {
5223
5162
  var argCountMessage = minArgs == maxArgs ? minArgs : `${minArgs} to ${maxArgs}`;
5224
5163
  throwBindingError(`function ${humanName} called with ${numArgs} arguments, expected ${argCountMessage}`);
5225
5164
  }
5226
5165
  }
5227
- function createJsInvoker(argTypes, isClassMethodFunc, returns, isAsync) {
5228
- var needsDestructorStack = usesDestructorStack(argTypes);
5229
- var argsNeedStack = argsUseStackAlloc(argTypes);
5230
- // JSPI-async invokers resume after the frame would be gone, so they
5231
- // defer through the destructors array instead.
5232
- var useStackFrame = argsNeedStack && !isAsync && !needsDestructorStack;
5233
- if (argsNeedStack && !useStackFrame) {
5234
- // A stack-allocating type must never see a null destructors argument
5235
- // without a bracketing frame; route it through the destructors array
5236
- // (it heap-allocates on that path).
5237
- needsDestructorStack = true;
5238
- }
5239
- var argCount = argTypes.length - 2;
5240
- var argsList = [];
5241
- var argsListWired = ['fn'];
5242
- if (isClassMethodFunc) {
5243
- argsListWired.push('thisWired');
5166
+ function getRequiredArgCount(argTypes) {
5167
+ var requiredArgCount = argTypes.length - 2;
5168
+ for (var i = argTypes.length - 1; i >= 2; --i) {
5169
+ if (!argTypes[i].optional) {
5170
+ break;
5171
+ }
5172
+ requiredArgCount--;
5244
5173
  }
5245
- for (var i = 0; i < argCount; ++i) {
5246
- argsList.push(`arg${i}`)
5247
- argsListWired.push(`arg${i}Wired`)
5174
+ return requiredArgCount;
5175
+ }
5176
+ var runDestructors = (destructors) => {
5177
+ while (destructors.length) {
5178
+ var ptr = destructors.pop();
5179
+ var del = destructors.pop();
5180
+ del(ptr);
5248
5181
  }
5249
- argsList = argsList.join()
5250
- argsListWired = argsListWired.join()
5251
-
5252
- var invokerFnBody = `return function (${argsList}) {\n`;
5182
+ };
5183
+ var invokerFunctions = {'fffn0': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,checkArgCount,minArgs,maxArgs
5184
+ ) {
5185
+ if (arguments.length !== 10){ throw new Error(humanName + "Expected 10 closure arguments " + arguments.length + " given."); }
5186
+ return function () {
5187
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5188
+ invoker(fn);
5189
+ }
5253
5190
 
5254
- invokerFnBody += 'checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);\n';
5191
+ },
5192
+ 'fffn1': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,checkArgCount,minArgs,maxArgs
5193
+ ) {
5194
+ if (arguments.length !== 11){ throw new Error(humanName + "Expected 11 closure arguments " + arguments.length + " given."); }
5195
+ return function (arg0) {
5196
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5197
+ var arg0Wired = toArg0Wire(null, arg0);
5198
+ invoker(fn,arg0Wired);
5199
+ }
5255
5200
 
5256
- if (needsDestructorStack) {
5257
- invokerFnBody += 'var destructors = [];\n';
5258
- }
5259
- if (useStackFrame) {
5260
- // The frame must be released on every completion, including a throwing
5261
- // argument conversion or callee: a skipped stackRestore permanently
5262
- // leaks wasm stack. `var` declarations hoist out of the try block.
5263
- invokerFnBody += 'var sp = stackSave();\ntry {\n';
5264
- }
5201
+ },
5202
+ 'fffn2': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,toArg1Wire,checkArgCount,minArgs,maxArgs
5203
+ ) {
5204
+ if (arguments.length !== 12){ throw new Error(humanName + "Expected 12 closure arguments " + arguments.length + " given."); }
5205
+ return function (arg0,arg1) {
5206
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5207
+ var arg0Wired = toArg0Wire(null, arg0);
5208
+ var arg1Wired = toArg1Wire(null, arg1);
5209
+ invoker(fn,arg0Wired,arg1Wired);
5210
+ }
5265
5211
 
5266
- var dtorStack = needsDestructorStack ? 'destructors' : 'null';
5267
- var args1 = ['humanName', 'throwBindingError', 'invoker', 'fn', 'runDestructors', 'fromRetWire', 'toClassParamWire'];
5268
- if (useStackFrame) {
5269
- args1.push('stackSave', 'stackRestore');
5270
- }
5212
+ },
5213
+ 'ftfn0': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,checkArgCount,minArgs,maxArgs
5214
+ ) {
5215
+ if (arguments.length !== 10){ throw new Error(humanName + "Expected 10 closure arguments " + arguments.length + " given."); }
5216
+ return function () {
5217
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5218
+ var rv = invoker(fn);
5219
+ var ret = fromRetWire(rv);
5220
+ return ret;
5221
+ }
5271
5222
 
5272
- if (isClassMethodFunc) {
5273
- invokerFnBody += `var thisWired = toClassParamWire(${dtorStack}, this);\n`;
5274
- }
5223
+ },
5224
+ 'ftfn1': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,checkArgCount,minArgs,maxArgs
5225
+ ) {
5226
+ if (arguments.length !== 11){ throw new Error(humanName + "Expected 11 closure arguments " + arguments.length + " given."); }
5227
+ return function (arg0) {
5228
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5229
+ var arg0Wired = toArg0Wire(null, arg0);
5230
+ var rv = invoker(fn,arg0Wired);
5231
+ var ret = fromRetWire(rv);
5232
+ return ret;
5233
+ }
5275
5234
 
5276
- for (var i = 0; i < argCount; ++i) {
5277
- var argName = `toArg${i}Wire`;
5278
- invokerFnBody += `var arg${i}Wired = ${argName}(${dtorStack}, arg${i});\n`;
5279
- args1.push(argName);
5280
- }
5235
+ },
5236
+ 'ftfn2': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,toArg1Wire,checkArgCount,minArgs,maxArgs
5237
+ ) {
5238
+ if (arguments.length !== 12){ throw new Error(humanName + "Expected 12 closure arguments " + arguments.length + " given."); }
5239
+ return function (arg0,arg1) {
5240
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5241
+ var arg0Wired = toArg0Wire(null, arg0);
5242
+ var arg1Wired = toArg1Wire(null, arg1);
5243
+ var rv = invoker(fn,arg0Wired,arg1Wired);
5244
+ var ret = fromRetWire(rv);
5245
+ return ret;
5246
+ }
5281
5247
 
5282
- invokerFnBody += (returns || isAsync ? 'var rv = ' : '') + `invoker(${argsListWired});\n`;
5283
- if (useStackFrame) {
5284
- // The callee has consumed the stack-allocated argument temporaries;
5285
- // release the frame before any post-call work.
5286
- invokerFnBody += '} finally {\nstackRestore(sp);\n}\n';
5287
- }
5248
+ },
5249
+ 'ftfn3': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,toArg1Wire,toArg2Wire,checkArgCount,minArgs,maxArgs
5250
+ ) {
5251
+ if (arguments.length !== 13){ throw new Error(humanName + "Expected 13 closure arguments " + arguments.length + " given."); }
5252
+ return function (arg0,arg1,arg2) {
5253
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5254
+ var arg0Wired = toArg0Wire(null, arg0);
5255
+ var arg1Wired = toArg1Wire(null, arg1);
5256
+ var arg2Wired = toArg2Wire(null, arg2);
5257
+ var rv = invoker(fn,arg0Wired,arg1Wired,arg2Wired);
5258
+ var ret = fromRetWire(rv);
5259
+ return ret;
5260
+ }
5288
5261
 
5289
- var returnVal = returns ? 'rv' : '';
5262
+ },
5263
+ 'ftfn4': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,toArg1Wire,toArg2Wire,toArg3Wire,checkArgCount,minArgs,maxArgs
5264
+ ) {
5265
+ if (arguments.length !== 14){ throw new Error(humanName + "Expected 14 closure arguments " + arguments.length + " given."); }
5266
+ return function (arg0,arg1,arg2,arg3) {
5267
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5268
+ var arg0Wired = toArg0Wire(null, arg0);
5269
+ var arg1Wired = toArg1Wire(null, arg1);
5270
+ var arg2Wired = toArg2Wire(null, arg2);
5271
+ var arg3Wired = toArg3Wire(null, arg3);
5272
+ var rv = invoker(fn,arg0Wired,arg1Wired,arg2Wired,arg3Wired);
5273
+ var ret = fromRetWire(rv);
5274
+ return ret;
5275
+ }
5290
5276
 
5291
- if (needsDestructorStack) {
5292
- invokerFnBody += 'runDestructors(destructors);\n';
5293
- } else {
5294
- for (var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
5295
- var paramName = (i === 1 ? 'thisWired' : `arg${i - 2}Wired`);
5296
- if (argTypes[i].destructorFunction !== null) {
5297
- invokerFnBody += `${paramName}_dtor(${paramName});\n`;
5298
- args1.push(`${paramName}_dtor`);
5299
- }
5300
- }
5301
- }
5277
+ },
5278
+ 'tffn1': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,checkArgCount,minArgs,maxArgs
5279
+ ) {
5280
+ if (arguments.length !== 11){ throw new Error(humanName + "Expected 11 closure arguments " + arguments.length + " given."); }
5281
+ return function (arg0) {
5282
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5283
+ var thisWired = toClassParamWire(null, this);
5284
+ var arg0Wired = toArg0Wire(null, arg0);
5285
+ invoker(fn,thisWired,arg0Wired);
5286
+ }
5302
5287
 
5303
- if (returns) {
5304
- invokerFnBody += 'var ret = fromRetWire(rv);\n' +
5305
- 'return ret;\n';
5306
- } else {
5307
- }
5288
+ },
5289
+ 'tffn2': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,toArg1Wire,checkArgCount,minArgs,maxArgs
5290
+ ) {
5291
+ if (arguments.length !== 12){ throw new Error(humanName + "Expected 12 closure arguments " + arguments.length + " given."); }
5292
+ return function (arg0,arg1) {
5293
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5294
+ var thisWired = toClassParamWire(null, this);
5295
+ var arg0Wired = toArg0Wire(null, arg0);
5296
+ var arg1Wired = toArg1Wire(null, arg1);
5297
+ invoker(fn,thisWired,arg0Wired,arg1Wired);
5298
+ }
5308
5299
 
5309
- invokerFnBody += '}\n';
5300
+ },
5301
+ 'ttfn0': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,checkArgCount,minArgs,maxArgs
5302
+ ) {
5303
+ if (arguments.length !== 10){ throw new Error(humanName + "Expected 10 closure arguments " + arguments.length + " given."); }
5304
+ return function () {
5305
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5306
+ var thisWired = toClassParamWire(null, this);
5307
+ var rv = invoker(fn,thisWired);
5308
+ var ret = fromRetWire(rv);
5309
+ return ret;
5310
+ }
5310
5311
 
5311
- args1.push('checkArgCount', 'minArgs', 'maxArgs');
5312
- invokerFnBody = `if (arguments.length !== ${args1.length}){ throw new Error(humanName + "Expected ${args1.length} closure arguments " + arguments.length + " given."); }\n${invokerFnBody}`;
5313
- return new Function(args1, invokerFnBody);
5314
- }
5312
+ },
5313
+ 'ttfn1': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,checkArgCount,minArgs,maxArgs
5314
+ ) {
5315
+ if (arguments.length !== 11){ throw new Error(humanName + "Expected 11 closure arguments " + arguments.length + " given."); }
5316
+ return function (arg0) {
5317
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5318
+ var thisWired = toClassParamWire(null, this);
5319
+ var arg0Wired = toArg0Wire(null, arg0);
5320
+ var rv = invoker(fn,thisWired,arg0Wired);
5321
+ var ret = fromRetWire(rv);
5322
+ return ret;
5323
+ }
5315
5324
 
5316
- function getRequiredArgCount(argTypes) {
5317
- var requiredArgCount = argTypes.length - 2;
5318
- for (var i = argTypes.length - 1; i >= 2; --i) {
5319
- if (!argTypes[i].optional) {
5320
- break;
5325
+ },
5326
+ 'ttfn2': function anonymous(humanName,throwBindingError,invoker,fn,runDestructors,fromRetWire,toClassParamWire,toArg0Wire,toArg1Wire,checkArgCount,minArgs,maxArgs
5327
+ ) {
5328
+ if (arguments.length !== 12){ throw new Error(humanName + "Expected 12 closure arguments " + arguments.length + " given."); }
5329
+ return function (arg0,arg1) {
5330
+ checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);
5331
+ var thisWired = toClassParamWire(null, this);
5332
+ var arg0Wired = toArg0Wire(null, arg0);
5333
+ var arg1Wired = toArg1Wire(null, arg1);
5334
+ var rv = invoker(fn,thisWired,arg0Wired,arg1Wired);
5335
+ var ret = fromRetWire(rv);
5336
+ return ret;
5337
+ }
5338
+
5339
+ },};
5340
+ function usesDestructorStack(argTypes) {
5341
+ // Skip return value at index 0 - it's not deleted here.
5342
+ for (var i = 1; i < argTypes.length; ++i) {
5343
+ if (argTypes[i]?.usesDestructor) {
5344
+ return true;
5321
5345
  }
5322
- requiredArgCount--;
5323
5346
  }
5324
- return requiredArgCount;
5347
+ return false;
5325
5348
  }
5326
-
5327
5349
  function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc, /** boolean= */ isAsync) {
5328
5350
  // humanName: a human-readable string name for the function to be generated.
5329
5351
  // argTypes: An array that contains the embind type objects for all types in the function signature.
@@ -5350,7 +5372,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5350
5372
  // }
5351
5373
 
5352
5374
  // Determine if we need to use a dynamic stack to store the destructors for the function parameters.
5353
- // TODO: Remove this completely once all function invokers are being dynamically generated.
5354
5375
  var needsDestructorStack = usesDestructorStack(argTypes);
5355
5376
 
5356
5377
  // Stack-allocating trivial value types get a stackSave/stackRestore
@@ -5378,22 +5399,26 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5378
5399
  var argType = argTypes[i];
5379
5400
  closureArgs.push(argType.toWireType.bind(argType));
5380
5401
  }
5381
- if (!needsDestructorStack) {
5382
- // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
5383
- for (var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) {
5384
- if (argTypes[i].destructorFunction !== null) {
5385
- closureArgs.push(argTypes[i].destructorFunction);
5386
- }
5387
- }
5388
- }
5389
5402
  closureArgs.push(checkArgCount, minArgs, expectedArgCount);
5390
5403
 
5391
- let invokerFactory = createJsInvoker(argTypes, isClassMethodFunc, returns, isAsync);
5404
+ var cleanupMode = useStackFrame ? 's' : (needsDestructorStack ? 'd' : 'n');
5405
+ var signature = `${isClassMethodFunc ? 't' : 'f'}${returns ? 't' : 'f'}${isAsync ? 't' : 'f'}${cleanupMode}${expectedArgCount}`;
5406
+ var invokerFactory = invokerFunctions[signature];
5407
+ assert(invokerFactory, `Missing embind invoker for signature: ${signature}`);
5392
5408
  var invokerFn = invokerFactory(...closureArgs);
5393
5409
  return createNamedFunction(humanName, invokerFn);
5394
5410
  }
5411
+ var heap32VectorToArray = (count, firstElement) => {
5412
+ var array = [];
5413
+ for (var i = 0; i < count; i++) {
5414
+ // TODO(https://github.com/emscripten-core/emscripten/issues/17310):
5415
+ // Find a way to hoist the `>> 2` or `>> 3` out of this loop.
5416
+ array.push(HEAPU32[(((firstElement)+(i * 4))>>2)]);
5417
+ }
5418
+ return array;
5419
+ };
5395
5420
  var __embind_register_class_constructor = (
5396
- rawClassType,
5421
+ classTypeID,
5397
5422
  argCount,
5398
5423
  rawArgTypesAddr,
5399
5424
  invokerSignature,
@@ -5401,12 +5426,12 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5401
5426
  rawConstructor
5402
5427
  ) => {
5403
5428
  assert(argCount > 0);
5404
- var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
5429
+ var argTypeIDs = heap32VectorToArray(argCount, rawArgTypesAddr);
5405
5430
  invoker = embind__requireFunction(invokerSignature, invoker);
5406
5431
  var args = [rawConstructor];
5407
5432
  var destructors = [];
5408
5433
 
5409
- whenDependentTypesAreResolved([], [rawClassType], (classType) => {
5434
+ whenDependentTypesAreResolved([], [classTypeID], (classType) => {
5410
5435
  classType = classType[0];
5411
5436
  var humanName = `constructor ${classType.name}`;
5412
5437
 
@@ -5417,10 +5442,10 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5417
5442
  throw new BindingError(`Cannot register multiple constructors with identical number of parameters (${argCount-1}) for class '${classType.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);
5418
5443
  }
5419
5444
  classType.registeredClass.constructor_body[argCount - 1] = () => {
5420
- throwUnboundTypeError(`Cannot construct ${classType.name} due to unbound types`, rawArgTypes);
5445
+ throwUnboundTypeError(`Cannot construct ${classType.name} due to unbound types`, argTypeIDs);
5421
5446
  };
5422
5447
 
5423
- whenDependentTypesAreResolved([], rawArgTypes, (argTypes) => {
5448
+ whenDependentTypesAreResolved([], argTypeIDs, (argTypes) => {
5424
5449
  // Insert empty slot for context type (argTypes[1]).
5425
5450
  argTypes.splice(1, 0, null);
5426
5451
  classType.registeredClass.constructor_body[argCount - 1] = craftInvokerFunction(humanName, argTypes, null, invoker, rawConstructor);
@@ -5429,13 +5454,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5429
5454
  return [];
5430
5455
  });
5431
5456
  };
5432
-
5433
-
5434
-
5435
-
5436
-
5437
-
5438
-
5439
5457
  var getFunctionName = (signature) => {
5440
5458
  signature = signature.trim();
5441
5459
  const argsIndex = signature.indexOf('(');
@@ -5443,7 +5461,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5443
5461
  assert(signature.endsWith(')'), 'Parentheses for argument names should match.');
5444
5462
  return signature.slice(0, argsIndex);
5445
5463
  };
5446
- var __embind_register_class_function = (rawClassType,
5464
+ var __embind_register_class_function = (classTypeID,
5447
5465
  methodName,
5448
5466
  argCount,
5449
5467
  rawArgTypesAddr, // [ReturnType, ThisType, Args...]
@@ -5453,12 +5471,12 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5453
5471
  isPureVirtual,
5454
5472
  isAsync,
5455
5473
  isNonnullReturn) => {
5456
- var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
5474
+ var argTypeIDs = heap32VectorToArray(argCount, rawArgTypesAddr);
5457
5475
  methodName = AsciiToString(methodName);
5458
5476
  methodName = getFunctionName(methodName);
5459
5477
  rawInvoker = embind__requireFunction(invokerSignature, rawInvoker, isAsync);
5460
5478
 
5461
- whenDependentTypesAreResolved([], [rawClassType], (classType) => {
5479
+ whenDependentTypesAreResolved([], [classTypeID], (classType) => {
5462
5480
  classType = classType[0];
5463
5481
  var humanName = `${classType.name}.${methodName}`;
5464
5482
 
@@ -5471,7 +5489,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5471
5489
  }
5472
5490
 
5473
5491
  function unboundTypesHandler() {
5474
- throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, rawArgTypes);
5492
+ throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, argTypeIDs);
5475
5493
  }
5476
5494
 
5477
5495
  var proto = classType.registeredClass.instancePrototype;
@@ -5489,7 +5507,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5489
5507
  proto[methodName].overloadTable[argCount - 2] = unboundTypesHandler;
5490
5508
  }
5491
5509
 
5492
- whenDependentTypesAreResolved([], rawArgTypes, (argTypes) => {
5510
+ whenDependentTypesAreResolved([], argTypeIDs, (argTypes) => {
5493
5511
  var memberFunction = craftInvokerFunction(humanName, argTypes, classType, rawInvoker, context, isAsync);
5494
5512
 
5495
5513
  // Replace the initial unbound-handler-stub function with the
@@ -5509,15 +5527,10 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5509
5527
  return [];
5510
5528
  });
5511
5529
  };
5512
-
5513
-
5514
- var emval_freelist = [];
5515
-
5516
- var emval_handles = [0,1,,1,null,1,true,1,false,1];
5517
-
5530
+ const EMVAL_LAST_RESERVED_HANDLE = 9;
5518
5531
  var emval_exception_decrefs = [];
5519
5532
  var __emval_decref = (handle) => {
5520
- if (handle > 9 && 0 === --emval_handles[handle + 1]) {
5533
+ if (handle > EMVAL_LAST_RESERVED_HANDLE && 0 === --emval_handles[handle + 1]) {
5521
5534
  assert(emval_handles[handle] !== undefined, `decref for unallocated handle`);
5522
5535
  var value = emval_handles[handle];
5523
5536
  emval_handles[handle] = undefined;
@@ -5531,34 +5544,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5531
5544
  emval_freelist.push(handle);
5532
5545
  }
5533
5546
  };
5534
-
5535
-
5536
-
5537
- var Emval = {
5538
- toValue:(handle) => {
5539
- if (!handle) {
5540
- throwBindingError(`Cannot use deleted val. handle = ${handle}`);
5541
- }
5542
- // handle 2 is supposed to be `undefined`.
5543
- assert(handle === 2 || emval_handles[handle] !== undefined && handle % 2 === 0, `invalid handle: ${handle}`);
5544
- return emval_handles[handle];
5545
- },
5546
- toHandle:(value) => {
5547
- switch (value) {
5548
- case undefined: return 2;
5549
- case null: return 4;
5550
- case true: return 6;
5551
- case false: return 8;
5552
- default:{
5553
- const handle = emval_freelist.pop() || emval_handles.length;
5554
- emval_handles[handle] = value;
5555
- emval_handles[handle + 1] = 1;
5556
- return handle;
5557
- }
5558
- }
5559
- },
5560
- };
5561
-
5562
5547
  var EmValType = {
5563
5548
  name: 'emscripten::val',
5564
5549
  fromWireType: (handle) => {
@@ -5568,16 +5553,13 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5568
5553
  },
5569
5554
  toWireType: (destructors, value) => Emval.toHandle(value),
5570
5555
  readValueFromPointer: readPointer,
5571
- destructorFunction: null, // This type does not need a destructor
5572
5556
 
5573
5557
  // TODO: do we need a deleteObject here? write a test where
5574
5558
  // emval is passed into JS via an interface
5575
5559
  };
5576
- var __embind_register_emval = (rawType) => registerType(rawType, EmValType);
5577
-
5560
+ var __embind_register_emval = (typeID) => registerType(typeID, EmValType);
5578
5561
  /** @type {!Float32Array} */
5579
5562
  var HEAPF32;
5580
-
5581
5563
  /** @type {!Float64Array} */
5582
5564
  var HEAPF64;
5583
5565
  var floatReadValueFromPointer = (name, width) => {
@@ -5592,12 +5574,9 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5592
5574
  throw new TypeError(`invalid float width (${width}): ${name}`);
5593
5575
  }
5594
5576
  };
5595
-
5596
-
5597
-
5598
- var __embind_register_float = (rawType, name, size) => {
5577
+ var __embind_register_float = (typeID, name, size) => {
5599
5578
  name = AsciiToString(name);
5600
- registerType(rawType, {
5579
+ registerType(typeID, {
5601
5580
  name,
5602
5581
  fromWireType: (value) => value,
5603
5582
  toWireType: (destructors, value) => {
@@ -5609,43 +5588,32 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5609
5588
  return value;
5610
5589
  },
5611
5590
  readValueFromPointer: floatReadValueFromPointer(name, size),
5612
- destructorFunction: null, // This type does not need a destructor
5613
5591
  });
5614
5592
  };
5615
-
5616
-
5617
-
5618
-
5619
-
5620
-
5621
-
5622
-
5623
-
5624
5593
  var __embind_register_function = (name, argCount, rawArgTypesAddr, signature, rawInvoker, fn, isAsync, isNonnullReturn) => {
5625
- var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
5594
+ var argTypeIDs = heap32VectorToArray(argCount, rawArgTypesAddr);
5626
5595
  name = AsciiToString(name);
5627
5596
  name = getFunctionName(name);
5628
5597
 
5629
5598
  rawInvoker = embind__requireFunction(signature, rawInvoker, isAsync);
5630
5599
 
5631
5600
  exposePublicSymbol(name, function() {
5632
- throwUnboundTypeError(`Cannot call ${name} due to unbound types`, argTypes);
5601
+ throwUnboundTypeError(`Cannot call ${name} due to unbound types`, argTypeIDs);
5633
5602
  }, argCount - 1);
5634
5603
 
5635
- whenDependentTypesAreResolved([], argTypes, (argTypes) => {
5604
+ whenDependentTypesAreResolved([], argTypeIDs, (argTypes) => {
5636
5605
  var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
5637
5606
  replacePublicSymbol(name, craftInvokerFunction(name, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn, isAsync), argCount - 1);
5638
5607
  return [];
5639
5608
  });
5640
5609
  };
5641
-
5642
-
5643
-
5644
-
5610
+ var assertIntegerRange = (typeName, value, minRange, maxRange) => {
5611
+ if (value < minRange || value > maxRange) {
5612
+ throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${typeName}", which is outside the valid range [${minRange}, ${maxRange}]!`);
5613
+ }
5614
+ };
5645
5615
  /** @type {!Uint16Array} */
5646
5616
  var HEAPU16;
5647
-
5648
-
5649
5617
  var integerReadValueFromPointer = (name, width, signed) => {
5650
5618
  // integers are quite common, so generate very specialized functions
5651
5619
  switch (width) {
@@ -5662,17 +5630,8 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5662
5630
  throw new TypeError(`invalid integer width (${width}): ${name}`);
5663
5631
  }
5664
5632
  };
5665
-
5666
-
5667
-
5668
-
5669
- var assertIntegerRange = (typeName, value, minRange, maxRange) => {
5670
- if (value < minRange || value > maxRange) {
5671
- throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${typeName}", which is outside the valid range [${minRange}, ${maxRange}]!`);
5672
- }
5673
- };
5674
5633
  /** @suppress {globalThis} */
5675
- var __embind_register_integer = (primitiveType, name, size, minRange, maxRange) => {
5634
+ var __embind_register_integer = (typeID, name, size, minRange, maxRange) => {
5676
5635
  name = AsciiToString(name);
5677
5636
 
5678
5637
  const isUnsignedType = minRange === 0;
@@ -5684,7 +5643,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5684
5643
  maxRange = fromWireType(maxRange);
5685
5644
  }
5686
5645
 
5687
- registerType(primitiveType, {
5646
+ registerType(typeID, {
5688
5647
  name,
5689
5648
  fromWireType: fromWireType,
5690
5649
  toWireType: (destructors, value) => {
@@ -5697,17 +5656,8 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5697
5656
  return value;
5698
5657
  },
5699
5658
  readValueFromPointer: integerReadValueFromPointer(name, size, minRange !== 0),
5700
- destructorFunction: null, // This type does not need a destructor
5701
5659
  });
5702
5660
  };
5703
-
5704
-
5705
-
5706
-
5707
-
5708
-
5709
-
5710
-
5711
5661
 
5712
5662
  /**
5713
5663
  * @param {number} ptr
@@ -5753,21 +5703,16 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5753
5703
  };
5754
5704
  }
5755
5705
  };
5756
-
5757
- var __embind_register_iterable = (rawClassType, rawElementType, sizeMethodName, getMethodName) => {
5706
+ var __embind_register_iterable = (classTypeID, elementTypeID, sizeMethodName, getMethodName) => {
5758
5707
  sizeMethodName = AsciiToString(sizeMethodName);
5759
5708
  getMethodName = AsciiToString(getMethodName);
5760
- whenDependentTypesAreResolved([], [rawClassType, rawElementType], (types) => {
5709
+ whenDependentTypesAreResolved([], [classTypeID, elementTypeID], (types) => {
5761
5710
  const classType = types[0];
5762
5711
  installIndexedIterator(classType.registeredClass.instancePrototype, sizeMethodName, getMethodName);
5763
5712
  return [];
5764
5713
  });
5765
5714
  };
5766
-
5767
-
5768
-
5769
-
5770
- var __embind_register_memory_view = (rawType, dataTypeIndex, name) => {
5715
+ var __embind_register_memory_view = (typeID, dataTypeIndex, name) => {
5771
5716
  var typeMapping = [
5772
5717
  Int8Array,
5773
5718
  Uint8Array,
@@ -5777,6 +5722,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5777
5722
  Uint32Array,
5778
5723
  Float32Array,
5779
5724
  Float64Array,
5725
+ Uint8ClampedArray,
5780
5726
  ];
5781
5727
 
5782
5728
  var TA = typeMapping[dataTypeIndex];
@@ -5788,7 +5734,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5788
5734
  }
5789
5735
 
5790
5736
  name = AsciiToString(name);
5791
- registerType(rawType, {
5737
+ registerType(typeID, {
5792
5738
  name,
5793
5739
  fromWireType: decodeMemoryView,
5794
5740
  readValueFromPointer: decodeMemoryView,
@@ -5796,28 +5742,15 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5796
5742
  ignoreDuplicateRegistrations: true,
5797
5743
  });
5798
5744
  };
5799
-
5800
-
5801
5745
  var EmValOptionalType = Object.assign({optional: true}, EmValType);;
5802
- var __embind_register_optional = (rawOptionalType, rawType) => {
5803
- registerType(rawOptionalType, EmValOptionalType);
5746
+ var __embind_register_optional = (optionalTypeID, typeID) => {
5747
+ registerType(optionalTypeID, EmValOptionalType);
5804
5748
  };
5805
-
5806
-
5807
-
5808
-
5809
-
5810
-
5811
-
5812
-
5813
-
5814
-
5815
-
5816
- var __embind_register_std_string = (rawType, name) => {
5749
+ var __embind_register_std_string = (typeID, name) => {
5817
5750
  name = AsciiToString(name);
5818
5751
  const stdStringIsUTF8 = true;
5819
5752
 
5820
- registerType(rawType, {
5753
+ registerType(typeID, {
5821
5754
  name,
5822
5755
  // For some method names we use string keys here since they are part of
5823
5756
  // the public/external API and/or used by the runtime-generated code.
@@ -5878,24 +5811,12 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5878
5811
  HEAPU8.set(value, ptr);
5879
5812
  }
5880
5813
 
5881
- if (destructors !== null) {
5882
- destructors.push(_free, base);
5883
- }
5884
5814
  return base;
5885
5815
  },
5886
5816
  readValueFromPointer: readPointer,
5887
- destructorFunction(ptr) {
5888
- _free(ptr);
5889
- },
5890
5817
  });
5891
5818
  };
5892
-
5893
-
5894
-
5895
-
5896
5819
  var UTF16Decoder = globalThis.TextDecoder ? new TextDecoder('utf-16le') : undefined;;
5897
-
5898
-
5899
5820
  var UTF16ToString = (ptr, maxBytesToRead, ignoreNul) => {
5900
5821
  assert(ptr % 2 == 0, 'pointer passed to UTF16ToString must be 2-byte aligned');
5901
5822
  var idx = ((ptr)>>1);
@@ -5920,7 +5841,34 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5920
5841
 
5921
5842
  return str;
5922
5843
  };
5844
+ var UTF32ToString = (ptr, maxBytesToRead, ignoreNul) => {
5845
+ assert(ptr % 4 == 0, 'pointer passed to UTF32ToString must be 2-byte aligned');
5846
+ var str = '';
5847
+ var startIdx = ((ptr)>>2);
5848
+ // If maxBytesToRead is not passed explicitly, it will be undefined, and this
5849
+ // will always evaluate to true. This saves on code size.
5850
+ for (var i = 0; !(i >= maxBytesToRead / 4); i++) {
5851
+ var utf32 = HEAPU32[startIdx + i];
5852
+ if (!utf32 && !ignoreNul) break;
5853
+ str += String.fromCodePoint(utf32);
5854
+ }
5855
+ return str;
5856
+ };
5857
+ var lengthBytesUTF16 = (str) => str.length*2;
5858
+ var lengthBytesUTF32 = (str) => {
5859
+ var len = 0;
5860
+ for (var i = 0; i < str.length; ++i) {
5861
+ var codePoint = str.codePointAt(i);
5862
+ // Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16.
5863
+ // We need to manually skip over the second code unit for correct iteration.
5864
+ if (codePoint > 0xFFFF) {
5865
+ i++;
5866
+ }
5867
+ len += 4;
5868
+ }
5923
5869
 
5870
+ return len;
5871
+ };
5924
5872
  var stringToUTF16 = (str, outPtr, maxBytesToWrite = 0x7FFFFFFF) => {
5925
5873
  assert(outPtr % 2 == 0, 'pointer passed to stringToUTF16 must be 2-byte aligned');
5926
5874
  assert(typeof maxBytesToWrite === 'number', 'stringToUTF16 requires a third parameter that specifies the length of the output buffer');
@@ -5938,23 +5886,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5938
5886
  HEAP16[((outPtr)>>1)] = 0;
5939
5887
  return outPtr - startPtr;
5940
5888
  };
5941
-
5942
- var lengthBytesUTF16 = (str) => str.length*2;
5943
-
5944
- var UTF32ToString = (ptr, maxBytesToRead, ignoreNul) => {
5945
- assert(ptr % 4 == 0, 'pointer passed to UTF32ToString must be 2-byte aligned');
5946
- var str = '';
5947
- var startIdx = ((ptr)>>2);
5948
- // If maxBytesToRead is not passed explicitly, it will be undefined, and this
5949
- // will always evaluate to true. This saves on code size.
5950
- for (var i = 0; !(i >= maxBytesToRead / 4); i++) {
5951
- var utf32 = HEAPU32[startIdx + i];
5952
- if (!utf32 && !ignoreNul) break;
5953
- str += String.fromCodePoint(utf32);
5954
- }
5955
- return str;
5956
- };
5957
-
5958
5889
  var stringToUTF32 = (str, outPtr, maxBytesToWrite = 0x7FFFFFFF) => {
5959
5890
  assert(outPtr % 4 == 0, 'pointer passed to stringToUTF32 must be 4-byte aligned');
5960
5891
  assert(typeof maxBytesToWrite === 'number', 'stringToUTF32 requires a third parameter that specifies the length of the output buffer');
@@ -5976,23 +5907,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
5976
5907
  HEAP32[((outPtr)>>2)] = 0;
5977
5908
  return outPtr - startPtr;
5978
5909
  };
5979
-
5980
- var lengthBytesUTF32 = (str) => {
5981
- var len = 0;
5982
- for (var i = 0; i < str.length; ++i) {
5983
- var codePoint = str.codePointAt(i);
5984
- // Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16.
5985
- // We need to manually skip over the second code unit for correct iteration.
5986
- if (codePoint > 0xFFFF) {
5987
- i++;
5988
- }
5989
- len += 4;
5990
- }
5991
-
5992
- return len;
5993
- };
5994
-
5995
- var __embind_register_std_wstring = (rawType, charSize, name) => {
5910
+ var __embind_register_std_wstring = (typeID, charSize, name) => {
5996
5911
  name = AsciiToString(name);
5997
5912
  var decodeString, encodeString, lengthBytesUTF;
5998
5913
  if (charSize === 2) {
@@ -6005,7 +5920,7 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
6005
5920
  encodeString = stringToUTF32;
6006
5921
  lengthBytesUTF = lengthBytesUTF32;
6007
5922
  }
6008
- registerType(rawType, {
5923
+ registerType(typeID, {
6009
5924
  name,
6010
5925
  fromWireType: (value) => {
6011
5926
  // Code mostly taken from _embind_register_std_string fromWireType
@@ -6028,22 +5943,14 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
6028
5943
 
6029
5944
  encodeString(value, ptr + 4, length + charSize);
6030
5945
 
6031
- if (destructors !== null) {
6032
- destructors.push(_free, ptr);
6033
- }
6034
5946
  return ptr;
6035
5947
  },
6036
5948
  readValueFromPointer: readPointer,
6037
- destructorFunction(ptr) {
6038
- _free(ptr);
6039
- }
6040
5949
  });
6041
5950
  };
6042
-
6043
-
6044
- var __embind_register_void = (rawType, name) => {
5951
+ var __embind_register_void = (typeID, name) => {
6045
5952
  name = AsciiToString(name);
6046
- registerType(rawType, {
5953
+ registerType(typeID, {
6047
5954
  isVoid: true, // void return values can be optimized out sometimes
6048
5955
  name,
6049
5956
  fromWireType: () => undefined,
@@ -6051,24 +5958,30 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
6051
5958
  toWireType: (destructors, o) => undefined,
6052
5959
  });
6053
5960
  };
6054
-
6055
5961
  var emval_methodCallers = [];
6056
5962
  var emval_addMethodCaller = (caller) => {
6057
5963
  var id = emval_methodCallers.length;
6058
5964
  emval_methodCallers.push(caller);
6059
5965
  return id;
6060
5966
  };
6061
-
6062
-
6063
-
6064
- var requireRegisteredType = (rawType, humanName) => {
6065
- var impl = registeredTypes[rawType];
5967
+ var emval_returnValue = (toReturnWire, destructorsRef, handle) => {
5968
+ var destructors = [];
5969
+ var result = toReturnWire(destructors, handle);
5970
+ if (destructors.length) {
5971
+ // void, primitives and any other types w/o destructors don't need to allocate a handle
5972
+ HEAPU32[((destructorsRef)>>2)] = Emval.toHandle(destructors);
5973
+ }
5974
+ return result;
5975
+ };
5976
+ var emval_invokerFunctions = {'2t1': (toReturnWire,argFromPtr0) => (handle, methodName, destructorsRef, args) => emval_returnValue(toReturnWire, destructorsRef, new (Emval.toValue(handle))(argFromPtr0(args))),
5977
+ '3t1': (toReturnWire,argFromPtr0) => (handle, methodName, destructorsRef, args) => emval_returnValue(toReturnWire, destructorsRef, argFromPtr0(args)),};
5978
+ var requireRegisteredType = (typeID, humanName) => {
5979
+ var impl = registeredTypes[typeID];
6066
5980
  if (undefined === impl) {
6067
- throwBindingError(`${humanName} has unknown type ${getTypeName(rawType)}`);
5981
+ throwBindingError(`${humanName} has unknown type ${getTypeName(typeID)}`);
6068
5982
  }
6069
5983
  return impl;
6070
5984
  };
6071
-
6072
5985
  var emval_lookupTypes = (argCount, argTypes) => {
6073
5986
  var a = new Array(argCount);
6074
5987
  for (var i = 0; i < argCount; ++i) {
@@ -6077,23 +5990,22 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
6077
5990
  }
6078
5991
  return a;
6079
5992
  };
5993
+ var __emval_create_invoker = (argCount, argTypesPtr, kind) => {
5994
+ var [retType, ...argTypes] = emval_lookupTypes(argCount, argTypesPtr);
5995
+ var argFromPtr = argTypes.map(type => type.readValueFromPointer.bind(type));
5996
+ argCount--; // remove the extracted return type
6080
5997
 
6081
-
6082
-
6083
- var emval_returnValue = (toReturnWire, destructorsRef, handle) => {
6084
- var destructors = [];
6085
- var result = toReturnWire(destructors, handle);
6086
- if (destructors.length) {
6087
- // void, primitives and any other types w/o destructors don't need to allocate a handle
6088
- HEAPU32[((destructorsRef)>>2)] = Emval.toHandle(destructors);
6089
- }
6090
- return result;
5998
+ var signature = `${kind}${retType.isVoid ? 'f' : 't'}${argCount}`;
5999
+ var invokerFactory = emval_invokerFunctions[signature];
6000
+ assert(invokerFactory, `Missing emval invoker for signature: ${signature}`);
6001
+ var closureArgs = retType.isVoid ? argFromPtr : [retType.toWireType.bind(retType), ...argFromPtr];
6002
+ var invokerFunction = invokerFactory(...closureArgs);
6003
+ var functionName = `methodCaller<(${argTypes.map(t => t.name)}) => ${retType.name}>`;
6004
+ return emval_addMethodCaller(createNamedFunction(functionName, invokerFunction));
6091
6005
  };
6092
-
6093
-
6006
+
6094
6007
  var emval_symbols = {
6095
6008
  };
6096
-
6097
6009
  var getStringOrSymbol = (address) => {
6098
6010
  var symbol = emval_symbols[address];
6099
6011
  if (symbol === undefined) {
@@ -6101,53 +6013,6 @@ Originally allocated`); // `.stack` will add "at ..." after this sentence
6101
6013
  }
6102
6014
  return symbol;
6103
6015
  };
6104
- var __emval_create_invoker = (argCount, argTypesPtr, kind) => {
6105
- const GenericWireTypeSize = 8;
6106
-
6107
- var [retType, ...argTypes] = emval_lookupTypes(argCount, argTypesPtr);
6108
- var toReturnWire = retType.toWireType.bind(retType);
6109
- var argFromPtr = argTypes.map(type => type.readValueFromPointer.bind(type));
6110
- argCount--; // remove the extracted return type
6111
-
6112
- var captures = {'toValue': Emval.toValue};
6113
- var args = argFromPtr.map((argFromPtr, i) => {
6114
- var captureName = `argFromPtr${i}`;
6115
- captures[captureName] = argFromPtr;
6116
- return `${captureName}(args${i ? '+' + i * GenericWireTypeSize : ''})`;
6117
- });
6118
- var functionBody;
6119
- switch (kind){
6120
- case 0:
6121
- functionBody = 'toValue(handle)';
6122
- break;
6123
- case 2:
6124
- functionBody = 'new (toValue(handle))';
6125
- break;
6126
- case 3:
6127
- functionBody = '';
6128
- break;
6129
- case 1:
6130
- captures['getStringOrSymbol'] = getStringOrSymbol;
6131
- functionBody = 'toValue(handle)[getStringOrSymbol(methodName)]';
6132
- break;
6133
- }
6134
- functionBody += `(${args})`;
6135
- if (!retType.isVoid) {
6136
- captures['toReturnWire'] = toReturnWire;
6137
- captures['emval_returnValue'] = emval_returnValue;
6138
- functionBody = `return emval_returnValue(toReturnWire, destructorsRef, ${functionBody})`;
6139
- }
6140
- functionBody = `return function (handle, methodName, destructorsRef, args) {
6141
- ${functionBody}
6142
- }`;
6143
-
6144
- var invokerFunction = new Function(Object.keys(captures), functionBody)(...Object.values(captures));
6145
- var functionName = `methodCaller<(${argTypes.map(t => t.name)}) => ${retType.name}>`;
6146
- return emval_addMethodCaller(createNamedFunction(functionName, invokerFunction));
6147
- };
6148
-
6149
-
6150
-
6151
6016
  var __emval_get_global = (name) => {
6152
6017
  if (!name) {
6153
6018
  return Emval.toHandle(globalThis);
@@ -6155,34 +6020,22 @@ ${functionBody}
6155
6020
  name = getStringOrSymbol(name);
6156
6021
  return Emval.toHandle(globalThis[name]);
6157
6022
  };
6158
-
6159
-
6160
-
6161
6023
  var __emval_invoke = (caller, handle, methodName, destructorsRef, args) => {
6162
6024
  return emval_methodCallers[caller](handle, methodName, destructorsRef, args);
6163
6025
  };
6164
-
6165
-
6166
6026
  var __emval_new_cstring = (v) => Emval.toHandle(getStringOrSymbol(v));
6167
-
6168
6027
  var __emval_new_object = () => Emval.toHandle({});
6169
-
6170
-
6171
-
6172
6028
  var __emval_run_destructors = (handle) => {
6173
6029
  var destructors = Emval.toValue(handle);
6174
6030
  runDestructors(destructors);
6175
6031
  __emval_decref(handle);
6176
6032
  };
6177
-
6178
6033
  var __emval_set_property = (handle, key, value) => {
6179
6034
  handle = Emval.toValue(handle);
6180
6035
  key = Emval.toValue(key);
6181
6036
  value = Emval.toValue(value);
6182
6037
  handle[key] = value;
6183
6038
  };
6184
-
6185
-
6186
6039
  function __gmtime_js(time_low, time_high,tmPtr) {
6187
6040
  var time = convertI32PairToI53Checked(time_low, time_high);
6188
6041
 
@@ -6204,12 +6057,9 @@ ${functionBody}
6204
6057
  return 0;
6205
6058
  ;
6206
6059
  }
6207
-
6208
- var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
6209
-
6210
6060
  var MONTH_DAYS_LEAP_CUMULATIVE = [0,31,60,91,121,152,182,213,244,274,305,335];
6211
-
6212
6061
  var MONTH_DAYS_REGULAR_CUMULATIVE = [0,31,59,90,120,151,181,212,243,273,304,334];
6062
+ var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
6213
6063
  var ydayFromDate = (date) => {
6214
6064
  var leap = isLeapYear(date.getFullYear());
6215
6065
  var monthDaysCumulative = (leap ? MONTH_DAYS_LEAP_CUMULATIVE : MONTH_DAYS_REGULAR_CUMULATIVE);
@@ -6217,8 +6067,6 @@ ${functionBody}
6217
6067
 
6218
6068
  return yday;
6219
6069
  };
6220
-
6221
-
6222
6070
  function __localtime_js(time_low, time_high,tmPtr) {
6223
6071
  var time = convertI32PairToI53Checked(time_low, time_high);
6224
6072
 
@@ -6248,12 +6096,7 @@ ${functionBody}
6248
6096
  return 0;
6249
6097
  ;
6250
6098
  }
6251
-
6252
-
6253
- var _setTempRet0 = setTempRet0;
6254
-
6255
-
6256
- var __mktime_js = function(tmPtr) {
6099
+ function __mktime_js(tmPtr) {
6257
6100
 
6258
6101
  var ret = (() => {
6259
6102
  var date = new Date(HEAP32[(((tmPtr)+(20))>>2)] + 1900,
@@ -6305,11 +6148,8 @@ ${functionBody}
6305
6148
  return date.getTime() / 1000;
6306
6149
  })();
6307
6150
  return (setTempRet0((tempDouble = ret,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)), ret>>>0);
6308
- };
6309
-
6310
-
6311
-
6312
-
6151
+ }
6152
+ const TZNAME_MAX = 16;
6313
6153
  var __tzset_js = (timezone, daylight, std_name, dst_name) => {
6314
6154
  // TODO: Use (malleable) environment variables instead of system settings.
6315
6155
  var currentYear = new Date().getFullYear();
@@ -6351,42 +6191,38 @@ ${functionBody}
6351
6191
  var summerName = extractZone(summerOffset);
6352
6192
  assert(winterName);
6353
6193
  assert(summerName);
6354
- assert(lengthBytesUTF8(winterName) <= 16, `timezone name truncated to fit in TZNAME_MAX (${winterName})`);
6355
- assert(lengthBytesUTF8(summerName) <= 16, `timezone name truncated to fit in TZNAME_MAX (${summerName})`);
6194
+ assert(lengthBytesUTF8(winterName) <= TZNAME_MAX, `timezone name truncated to fit in TZNAME_MAX (${winterName})`);
6195
+ assert(lengthBytesUTF8(summerName) <= TZNAME_MAX, `timezone name truncated to fit in TZNAME_MAX (${summerName})`);
6356
6196
  if (summerOffset < winterOffset) {
6357
6197
  // Northern hemisphere
6358
- stringToUTF8(winterName, std_name, 17);
6359
- stringToUTF8(summerName, dst_name, 17);
6198
+ stringToUTF8(winterName, std_name, TZNAME_MAX + 1);
6199
+ stringToUTF8(summerName, dst_name, TZNAME_MAX + 1);
6360
6200
  } else {
6361
- stringToUTF8(winterName, dst_name, 17);
6362
- stringToUTF8(summerName, std_name, 17);
6201
+ stringToUTF8(winterName, dst_name, TZNAME_MAX + 1);
6202
+ stringToUTF8(summerName, std_name, TZNAME_MAX + 1);
6363
6203
  }
6364
6204
  };
6365
-
6366
- var _emscripten_get_now = () => performance.now();
6367
-
6205
+ const __WASI_CLOCKID_REALTIME = 0;
6206
+ const __WASI_CLOCKID_THREAD_CPUTIME_ID = 3;
6207
+ var checkWasiClock = (clock_id) => clock_id >= __WASI_CLOCKID_REALTIME && clock_id <= __WASI_CLOCKID_THREAD_CPUTIME_ID;
6208
+ const nowIsMonotonic = 1;
6368
6209
  var _emscripten_date_now = () => Date.now();
6369
-
6370
- var nowIsMonotonic = 1;
6371
-
6372
- var checkWasiClock = (clock_id) => clock_id >= 0 && clock_id <= 3;
6373
-
6374
-
6210
+ var _emscripten_get_now = () => performance.now();
6375
6211
  function _clock_time_get(clk_id,ignored_precision_low, ignored_precision_high,ptime) {
6376
6212
  var ignored_precision = convertI32PairToI53Checked(ignored_precision_low, ignored_precision_high);
6377
6213
 
6378
6214
 
6379
6215
  if (!checkWasiClock(clk_id)) {
6380
- return 28;
6216
+ return EINVAL;
6381
6217
  }
6382
6218
  var now;
6383
6219
  // all wasi clocks but realtime are monotonic
6384
- if (clk_id === 0) {
6220
+ if (clk_id === __WASI_CLOCKID_REALTIME) {
6385
6221
  now = _emscripten_date_now();
6386
6222
  } else if (nowIsMonotonic) {
6387
6223
  now = _emscripten_get_now();
6388
6224
  } else {
6389
- return 52;
6225
+ return ENOSYS;
6390
6226
  }
6391
6227
  // "now" is in ms, and wasi times are in ns.
6392
6228
  var nsec = Math.round(now * 1_000_000);
@@ -6396,19 +6232,16 @@ ${functionBody}
6396
6232
  }
6397
6233
 
6398
6234
 
6399
-
6235
+ var alignMemory = (size, alignment) => {
6236
+ assert(alignment, 'alignment argument is required');
6237
+ return Math.ceil(size / alignment) * alignment;
6238
+ };
6400
6239
  var getHeapMax = () =>
6401
6240
  // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
6402
6241
  // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
6403
6242
  // for any code that deals with heap sizes, which would require special
6404
6243
  // casing all heap size related code to treat 0 specially.
6405
6244
  65536000;
6406
-
6407
- var alignMemory = (size, alignment) => {
6408
- assert(alignment, 'alignment argument is required');
6409
- return Math.ceil(size / alignment) * alignment;
6410
- };
6411
-
6412
6245
  var growMemory = (size) => {
6413
6246
  var oldHeapSize = wasmMemory.buffer.byteLength;
6414
6247
  var pages = ((size - oldHeapSize + 65535) / 65536) | 0;
@@ -6423,7 +6256,6 @@ ${functionBody}
6423
6256
  // implicit 0 return to save code size (caller will cast 'undefined' into 0
6424
6257
  // anyhow)
6425
6258
  };
6426
-
6427
6259
  var _emscripten_resize_heap = (requestedSize) => {
6428
6260
  var oldSize = HEAPU8.length;
6429
6261
  // With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
@@ -6476,10 +6308,8 @@ ${functionBody}
6476
6308
  err(`Failed to grow the heap from ${oldSize} bytes to ${newSize} bytes, not enough memory!`);
6477
6309
  return false;
6478
6310
  };
6479
-
6480
6311
  var ENV = {
6481
6312
  };
6482
-
6483
6313
  var getExecutableName = () => thisProgram;
6484
6314
  var getEnvStrings = () => {
6485
6315
  if (!getEnvStrings.strings) {
@@ -6510,8 +6340,6 @@ ${functionBody}
6510
6340
  }
6511
6341
  return getEnvStrings.strings;
6512
6342
  };
6513
-
6514
-
6515
6343
  var _environ_get = (__environ, environ_buf) => {
6516
6344
  var bufSize = 0;
6517
6345
  var envp = 0;
@@ -6523,9 +6351,6 @@ ${functionBody}
6523
6351
  }
6524
6352
  return 0;
6525
6353
  };
6526
-
6527
-
6528
-
6529
6354
  var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
6530
6355
  var strings = getEnvStrings();
6531
6356
  HEAPU32[((penviron_count)>>2)] = strings.length;
@@ -6536,8 +6361,6 @@ ${functionBody}
6536
6361
  HEAPU32[((penviron_buf_size)>>2)] = bufSize;
6537
6362
  return 0;
6538
6363
  };
6539
-
6540
-
6541
6364
  var runtimeKeepaliveCounter = 0;
6542
6365
  var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
6543
6366
  var _proc_exit = (code) => {
@@ -6548,8 +6371,6 @@ ${functionBody}
6548
6371
  }
6549
6372
  quit_(code, new ExitStatus(code));
6550
6373
  };
6551
-
6552
-
6553
6374
  /** @param {boolean|number=} implicit */
6554
6375
  var exitJS = (status, implicit) => {
6555
6376
  EXITSTATUS = status;
@@ -6564,8 +6385,6 @@ ${functionBody}
6564
6385
 
6565
6386
  _proc_exit(status);
6566
6387
  };
6567
- var _exit = exitJS;
6568
-
6569
6388
  function _fd_close(fd) {
6570
6389
  try {
6571
6390
 
@@ -6578,10 +6397,10 @@ ${functionBody}
6578
6397
  }
6579
6398
  }
6580
6399
 
6581
-
6582
-
6583
-
6584
-
6400
+ const __WASI_FILETYPE_CHARACTER_DEVICE = 2;
6401
+ const __WASI_FILETYPE_DIRECTORY = 3;
6402
+ const __WASI_FILETYPE_REGULAR_FILE = 4;
6403
+ const __WASI_FILETYPE_SYMBOLIC_LINK = 7;
6585
6404
  function _fd_fdstat_get(fd, pbuf) {
6586
6405
  try {
6587
6406
 
@@ -6592,10 +6411,10 @@ ${functionBody}
6592
6411
  var stream = SYSCALLS.getStreamFromFD(fd);
6593
6412
  // All character devices are terminals (other things a Linux system would
6594
6413
  // assume is a character device, like the mouse, we have special APIs for).
6595
- var type = stream.tty ? 2 :
6596
- FS.isDir(stream.mode) ? 3 :
6597
- FS.isLink(stream.mode) ? 7 :
6598
- 4;
6414
+ var type = stream.tty ? __WASI_FILETYPE_CHARACTER_DEVICE :
6415
+ FS.isDir(stream.mode) ? __WASI_FILETYPE_DIRECTORY :
6416
+ FS.isLink(stream.mode) ? __WASI_FILETYPE_SYMBOLIC_LINK :
6417
+ __WASI_FILETYPE_REGULAR_FILE;
6599
6418
  }
6600
6419
  HEAP8[pbuf] = type;
6601
6420
  HEAP16[(((pbuf)+(2))>>1)] = flags;
@@ -6608,8 +6427,7 @@ ${functionBody}
6608
6427
  }
6609
6428
  }
6610
6429
 
6611
-
6612
-
6430
+ const EWOULDBLOCK = 6;
6613
6431
  /** @param {number=} offset */
6614
6432
  var doReadv = (stream, iov, iovcnt, offset) => {
6615
6433
  var ret = 0;
@@ -6624,7 +6442,7 @@ ${functionBody}
6624
6442
  // already gathered data. POSIX readv is a single gather-read: return
6625
6443
  // what we have rather than failing the whole call.
6626
6444
  if (ret > 0 && e instanceof FS.ErrnoError &&
6627
- (e.errno == 6 || e.errno == 6)) {
6445
+ (e.errno == EAGAIN || e.errno == EWOULDBLOCK)) {
6628
6446
  break;
6629
6447
  }
6630
6448
  throw e;
@@ -6638,8 +6456,6 @@ ${functionBody}
6638
6456
  }
6639
6457
  return ret;
6640
6458
  };
6641
-
6642
-
6643
6459
  function _fd_read(fd, iov, iovcnt, pnum) {
6644
6460
  try {
6645
6461
 
@@ -6653,20 +6469,17 @@ ${functionBody}
6653
6469
  }
6654
6470
  }
6655
6471
 
6656
-
6657
-
6658
-
6659
6472
  function _fd_seek(fd,offset_low, offset_high,whence,newOffset) {
6660
6473
  var offset = convertI32PairToI53Checked(offset_low, offset_high);
6661
6474
 
6662
6475
 
6663
6476
  try {
6664
6477
 
6665
- if (isNaN(offset)) return 22;
6478
+ if (isNaN(offset)) return EFBIG;
6666
6479
  var stream = SYSCALLS.getStreamFromFD(fd);
6667
6480
  FS.llseek(stream, offset, whence);
6668
6481
  (tempI64 = [stream.position>>>0,(tempDouble = stream.position,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((newOffset)>>2)] = tempI64[0],HEAP32[(((newOffset)+(4))>>2)] = tempI64[1]);
6669
- if (stream.getdents && !offset && whence === 0) stream.getdents = null; // reset readdir state
6482
+ if (stream.getdents && !offset && whence === SEEK_SET) stream.getdents = null; // reset readdir state
6670
6483
  return 0;
6671
6484
  } catch (e) {
6672
6485
  if (typeof FS === 'undefined' || !(e.name === 'ErrnoError')) throw e;
@@ -6674,9 +6487,6 @@ ${functionBody}
6674
6487
  }
6675
6488
  ;
6676
6489
  }
6677
-
6678
-
6679
-
6680
6490
  /** @param {number=} offset */
6681
6491
  var doWritev = (stream, iov, iovcnt, offset) => {
6682
6492
  // Gather all iovecs into one contiguous buffer and issue a single
@@ -6701,8 +6511,6 @@ ${functionBody}
6701
6511
  }
6702
6512
  return FS.write(stream, view, 0, total, offset);
6703
6513
  };
6704
-
6705
-
6706
6514
  function _fd_write(fd, iov, iovcnt, pnum) {
6707
6515
  try {
6708
6516
 
@@ -6716,36 +6524,24 @@ ${functionBody}
6716
6524
  }
6717
6525
  }
6718
6526
 
6719
-
6720
6527
  var _llvm_eh_typeid_for = (type) => type;
6721
-
6722
-
6723
6528
  var _random_get = (buffer, size) => randomFill(HEAPU8.subarray(buffer, buffer + size));
6724
6529
 
6725
-
6726
6530
  var getCFunc = (ident) => {
6727
6531
  var func = Module['_' + ident]; // closure exported function
6728
6532
  assert(func, `Cannot call unknown function ${ident}, make sure it is exported`);
6729
6533
  return func;
6730
6534
  };
6731
-
6732
- var writeArrayToMemory = (array, buffer) => {
6733
- assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)')
6734
- HEAP8.set(array, buffer);
6735
- };
6736
-
6737
-
6738
-
6739
6535
  var stringToUTF8OnStack = (str) => {
6740
6536
  var size = lengthBytesUTF8(str) + 1;
6741
6537
  var ret = stackAlloc(size);
6742
6538
  stringToUTF8(str, ret, size);
6743
6539
  return ret;
6744
6540
  };
6745
-
6746
-
6747
-
6748
-
6541
+ var writeArrayToMemory = (array, buffer) => {
6542
+ assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)')
6543
+ HEAP8.set(array, buffer);
6544
+ };
6749
6545
 
6750
6546
  /**
6751
6547
  * @param {string|null=} returnType
@@ -6802,7 +6598,6 @@ ${functionBody}
6802
6598
  ret = onDone(ret);
6803
6599
  return ret;
6804
6600
  };
6805
-
6806
6601
 
6807
6602
  /**
6808
6603
  * @param {string=} returnType
@@ -6813,13 +6608,17 @@ ${functionBody}
6813
6608
  return (...args) => ccall(ident, returnType, argTypes, args, opts);
6814
6609
  };
6815
6610
 
6816
-
6611
+ var syscallGetVarargP = syscallGetVarargI;
6612
+ var _setTempRet0 = setTempRet0;
6613
+ var _exit = exitJS;
6614
+
6817
6615
  FS.createPreloadedFile = FS_createPreloadedFile;
6818
6616
  FS.preloadFile = FS_preloadFile;
6819
- FS.staticInit();;
6820
- init_ClassHandle();
6821
- init_RegisteredPointer();
6822
- assert(emval_handles.length === 5 * 2);
6617
+ FS.staticInit();
6618
+ ;
6619
+ init_ClassHandle();
6620
+ init_RegisteredPointer();
6621
+ assert(emval_handles.length === EMVAL_RESERVED_HANDLES * 2);
6823
6622
  // End JS library code
6824
6623
 
6825
6624
  // include: postlibrary.js
@@ -6912,7 +6711,6 @@ if (Module['printErr']) err = Module['printErr'];
6912
6711
  'getEmptyTableSlot',
6913
6712
  'updateTableMap',
6914
6713
  'getFunctionAddress',
6915
- 'addFunction',
6916
6714
  'removeFunction',
6917
6715
  'setValue',
6918
6716
  'intArrayToString',
@@ -7019,9 +6817,9 @@ if (Module['printErr']) err = Module['printErr'];
7019
6817
  'getInheritedInstanceCount',
7020
6818
  'getLiveInheritedInstances',
7021
6819
  'getFunctionArgsName',
7022
- 'createJsInvokerSignature',
7023
6820
  'getEnumValueType',
7024
6821
  'PureVirtualError',
6822
+ 'createJsInvoker',
7025
6823
  'registerInheritedInstance',
7026
6824
  'unregisterInheritedInstance',
7027
6825
  'enumReadValueFromPointer',
@@ -7072,6 +6870,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
7072
6870
  'dynCallLegacy',
7073
6871
  'getDynCaller',
7074
6872
  'dynCall',
6873
+ 'getWasmTableEntry',
7075
6874
  'keepRuntimeAlive',
7076
6875
  'asyncLoad',
7077
6876
  'alignMemory',
@@ -7086,6 +6885,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
7086
6885
  'addOnPostRun',
7087
6886
  'freeTableIndexes',
7088
6887
  'functionsInTableMap',
6888
+ 'addFunction',
7089
6889
  'getValue',
7090
6890
  'PATH',
7091
6891
  'PATH_FS',
@@ -7154,16 +6954,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
7154
6954
  'FS_createPath',
7155
6955
  'FS_createDevice',
7156
6956
  'FS_readFile',
7157
- 'FS_root',
7158
- 'FS_mounts',
7159
- 'FS_devices',
7160
- 'FS_streams',
7161
- 'FS_nextInode',
7162
- 'FS_nameTable',
7163
- 'FS_currentPath',
7164
- 'FS_initialized',
7165
- 'FS_ignorePermissions',
7166
- 'FS_syncFSRequests',
7167
6957
  'FS_lookupPath',
7168
6958
  'FS_getPath',
7169
6959
  'FS_hashName',
@@ -7195,7 +6985,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
7195
6985
  'FS_closeStream',
7196
6986
  'FS_dupStream',
7197
6987
  'FS_doSetAttr',
7198
- 'FS_chrdev_stream_ops',
7199
6988
  'FS_major',
7200
6989
  'FS_minor',
7201
6990
  'FS_makedev',
@@ -7295,8 +7084,8 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
7295
7084
  'argsUseStackAlloc',
7296
7085
  'checkArgCount',
7297
7086
  'getRequiredArgCount',
7298
- 'createJsInvoker',
7299
7087
  'UnboundTypeError',
7088
+ 'invokerFunctions',
7300
7089
  'EmValType',
7301
7090
  'EmValOptionalType',
7302
7091
  'throwUnboundTypeError',
@@ -7339,8 +7128,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
7339
7128
  'shallowCopyInternalPointer',
7340
7129
  'downcastPointer',
7341
7130
  'upcastPointer',
7342
- 'char_0',
7343
- 'char_9',
7344
7131
  'makeLegalFunctionName',
7345
7132
  'emval_freelist',
7346
7133
  'emval_exception_decrefs',
@@ -7352,6 +7139,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
7352
7139
  'emval_lookupTypes',
7353
7140
  'emval_methodCallers',
7354
7141
  'emval_addMethodCaller',
7142
+ 'emval_invokerFunctions',
7355
7143
  ];
7356
7144
  unexportedSymbols.forEach(unexportedRuntimeSymbol);
7357
7145