sp-svg-diagram 0.1.2 → 0.1.4
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/index.js +24 -1
- package/package.json +3 -3
- package/wasm/SVGDiagramWASM.js +261 -3112
- package/wasm/SVGDiagramWASM.wasm +0 -0
package/wasm/SVGDiagramWASM.js
CHANGED
|
@@ -478,16 +478,11 @@ function initRuntime() {
|
|
|
478
478
|
|
|
479
479
|
checkStackCookie();
|
|
480
480
|
|
|
481
|
-
//
|
|
482
|
-
if (!Module['noFSInit'] && !FS.initialized) FS.init();
|
|
483
|
-
TTY.init();
|
|
484
|
-
// End ATINITS hooks
|
|
481
|
+
// No ATINITS hooks
|
|
485
482
|
|
|
486
483
|
wasmExports['__wasm_call_ctors']();
|
|
487
484
|
|
|
488
|
-
//
|
|
489
|
-
FS.ignorePermissions = false;
|
|
490
|
-
// End ATPOSTCTORS hooks
|
|
485
|
+
// No ATPOSTCTORS hooks
|
|
491
486
|
}
|
|
492
487
|
|
|
493
488
|
function postRun() {
|
|
@@ -541,6 +536,24 @@ function abort(what) {
|
|
|
541
536
|
throw e;
|
|
542
537
|
}
|
|
543
538
|
|
|
539
|
+
// show errors on likely calls to FS when it was not included
|
|
540
|
+
var FS = {
|
|
541
|
+
error() {
|
|
542
|
+
abort('Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM');
|
|
543
|
+
},
|
|
544
|
+
init() { FS.error() },
|
|
545
|
+
createDataFile() { FS.error() },
|
|
546
|
+
createPreloadedFile() { FS.error() },
|
|
547
|
+
createLazyFile() { FS.error() },
|
|
548
|
+
open() { FS.error() },
|
|
549
|
+
mkdev() { FS.error() },
|
|
550
|
+
registerDevice() { FS.error() },
|
|
551
|
+
analyzePath() { FS.error() },
|
|
552
|
+
|
|
553
|
+
ErrnoError() { FS.error() },
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
|
|
544
557
|
function createExportWrapper(name, nargs) {
|
|
545
558
|
return (...args) => {
|
|
546
559
|
assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
|
|
@@ -861,2979 +874,8 @@ async function createWasm() {
|
|
|
861
874
|
info.init(type, destructor);
|
|
862
875
|
exceptionLast = ptr;
|
|
863
876
|
uncaughtExceptionCount++;
|
|
864
|
-
assert(false, 'Exception thrown, but exception catching is not enabled. Compile with -sNO_DISABLE_EXCEPTION_CATCHING or -sEXCEPTION_CATCHING_ALLOWED=[..] to catch.');
|
|
865
|
-
};
|
|
866
|
-
|
|
867
|
-
var syscallGetVarargI = () => {
|
|
868
|
-
assert(SYSCALLS.varargs != undefined);
|
|
869
|
-
// the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
|
|
870
|
-
var ret = HEAP32[((+SYSCALLS.varargs)>>2)];
|
|
871
|
-
SYSCALLS.varargs += 4;
|
|
872
|
-
return ret;
|
|
873
|
-
};
|
|
874
|
-
var syscallGetVarargP = syscallGetVarargI;
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
var PATH = {
|
|
878
|
-
isAbs:(path) => path.charAt(0) === '/',
|
|
879
|
-
splitPath:(filename) => {
|
|
880
|
-
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
|
881
|
-
return splitPathRe.exec(filename).slice(1);
|
|
882
|
-
},
|
|
883
|
-
normalizeArray:(parts, allowAboveRoot) => {
|
|
884
|
-
// if the path tries to go above the root, `up` ends up > 0
|
|
885
|
-
var up = 0;
|
|
886
|
-
for (var i = parts.length - 1; i >= 0; i--) {
|
|
887
|
-
var last = parts[i];
|
|
888
|
-
if (last === '.') {
|
|
889
|
-
parts.splice(i, 1);
|
|
890
|
-
} else if (last === '..') {
|
|
891
|
-
parts.splice(i, 1);
|
|
892
|
-
up++;
|
|
893
|
-
} else if (up) {
|
|
894
|
-
parts.splice(i, 1);
|
|
895
|
-
up--;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
// if the path is allowed to go above the root, restore leading ..s
|
|
899
|
-
if (allowAboveRoot) {
|
|
900
|
-
for (; up; up--) {
|
|
901
|
-
parts.unshift('..');
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
return parts;
|
|
905
|
-
},
|
|
906
|
-
normalize:(path) => {
|
|
907
|
-
var isAbsolute = PATH.isAbs(path),
|
|
908
|
-
trailingSlash = path.slice(-1) === '/';
|
|
909
|
-
// Normalize the path
|
|
910
|
-
path = PATH.normalizeArray(path.split('/').filter((p) => !!p), !isAbsolute).join('/');
|
|
911
|
-
if (!path && !isAbsolute) {
|
|
912
|
-
path = '.';
|
|
913
|
-
}
|
|
914
|
-
if (path && trailingSlash) {
|
|
915
|
-
path += '/';
|
|
916
|
-
}
|
|
917
|
-
return (isAbsolute ? '/' : '') + path;
|
|
918
|
-
},
|
|
919
|
-
dirname:(path) => {
|
|
920
|
-
var result = PATH.splitPath(path),
|
|
921
|
-
root = result[0],
|
|
922
|
-
dir = result[1];
|
|
923
|
-
if (!root && !dir) {
|
|
924
|
-
// No dirname whatsoever
|
|
925
|
-
return '.';
|
|
926
|
-
}
|
|
927
|
-
if (dir) {
|
|
928
|
-
// It has a dirname, strip trailing slash
|
|
929
|
-
dir = dir.slice(0, -1);
|
|
930
|
-
}
|
|
931
|
-
return root + dir;
|
|
932
|
-
},
|
|
933
|
-
basename:(path) => path && path.match(/([^\/]+|\/)\/*$/)[1],
|
|
934
|
-
join:(...paths) => PATH.normalize(paths.join('/')),
|
|
935
|
-
join2:(l, r) => PATH.normalize(l + '/' + r),
|
|
936
|
-
};
|
|
937
|
-
|
|
938
|
-
var initRandomFill = () => {
|
|
939
|
-
// This block is not needed on v19+ since crypto.getRandomValues is builtin
|
|
940
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
941
|
-
var nodeCrypto = require('crypto');
|
|
942
|
-
return (view) => nodeCrypto.randomFillSync(view);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
return (view) => crypto.getRandomValues(view);
|
|
946
|
-
};
|
|
947
|
-
var randomFill = (view) => {
|
|
948
|
-
// Lazily init on the first invocation.
|
|
949
|
-
(randomFill = initRandomFill())(view);
|
|
950
|
-
};
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
var PATH_FS = {
|
|
955
|
-
resolve:(...args) => {
|
|
956
|
-
var resolvedPath = '',
|
|
957
|
-
resolvedAbsolute = false;
|
|
958
|
-
for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
959
|
-
var path = (i >= 0) ? args[i] : FS.cwd();
|
|
960
|
-
// Skip empty and invalid entries
|
|
961
|
-
if (typeof path != 'string') {
|
|
962
|
-
throw new TypeError('Arguments to path.resolve must be strings');
|
|
963
|
-
} else if (!path) {
|
|
964
|
-
return ''; // an invalid portion invalidates the whole thing
|
|
965
|
-
}
|
|
966
|
-
resolvedPath = path + '/' + resolvedPath;
|
|
967
|
-
resolvedAbsolute = PATH.isAbs(path);
|
|
968
|
-
}
|
|
969
|
-
// At this point the path should be resolved to a full absolute path, but
|
|
970
|
-
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
971
|
-
resolvedPath = PATH.normalizeArray(resolvedPath.split('/').filter((p) => !!p), !resolvedAbsolute).join('/');
|
|
972
|
-
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
|
973
|
-
},
|
|
974
|
-
relative:(from, to) => {
|
|
975
|
-
from = PATH_FS.resolve(from).slice(1);
|
|
976
|
-
to = PATH_FS.resolve(to).slice(1);
|
|
977
|
-
function trim(arr) {
|
|
978
|
-
var start = 0;
|
|
979
|
-
for (; start < arr.length; start++) {
|
|
980
|
-
if (arr[start] !== '') break;
|
|
981
|
-
}
|
|
982
|
-
var end = arr.length - 1;
|
|
983
|
-
for (; end >= 0; end--) {
|
|
984
|
-
if (arr[end] !== '') break;
|
|
985
|
-
}
|
|
986
|
-
if (start > end) return [];
|
|
987
|
-
return arr.slice(start, end - start + 1);
|
|
988
|
-
}
|
|
989
|
-
var fromParts = trim(from.split('/'));
|
|
990
|
-
var toParts = trim(to.split('/'));
|
|
991
|
-
var length = Math.min(fromParts.length, toParts.length);
|
|
992
|
-
var samePartsLength = length;
|
|
993
|
-
for (var i = 0; i < length; i++) {
|
|
994
|
-
if (fromParts[i] !== toParts[i]) {
|
|
995
|
-
samePartsLength = i;
|
|
996
|
-
break;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
var outputParts = [];
|
|
1000
|
-
for (var i = samePartsLength; i < fromParts.length; i++) {
|
|
1001
|
-
outputParts.push('..');
|
|
1002
|
-
}
|
|
1003
|
-
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
|
1004
|
-
return outputParts.join('/');
|
|
1005
|
-
},
|
|
1006
|
-
};
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
var UTF8Decoder = globalThis.TextDecoder && new TextDecoder();
|
|
1010
|
-
|
|
1011
|
-
var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
|
|
1012
|
-
var maxIdx = idx + maxBytesToRead;
|
|
1013
|
-
if (ignoreNul) return maxIdx;
|
|
1014
|
-
// TextDecoder needs to know the byte length in advance, it doesn't stop on
|
|
1015
|
-
// null terminator by itself.
|
|
1016
|
-
// As a tiny code save trick, compare idx against maxIdx using a negation,
|
|
1017
|
-
// so that maxBytesToRead=undefined/NaN means Infinity.
|
|
1018
|
-
while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;
|
|
1019
|
-
return idx;
|
|
1020
|
-
};
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
/**
|
|
1024
|
-
* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
|
|
1025
|
-
* array that contains uint8 values, returns a copy of that string as a
|
|
1026
|
-
* Javascript String object.
|
|
1027
|
-
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
1028
|
-
* @param {number=} idx
|
|
1029
|
-
* @param {number=} maxBytesToRead
|
|
1030
|
-
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
1031
|
-
* @return {string}
|
|
1032
|
-
*/
|
|
1033
|
-
var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
|
|
1034
|
-
|
|
1035
|
-
var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
|
|
1036
|
-
|
|
1037
|
-
// When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
|
|
1038
|
-
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
1039
|
-
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
1040
|
-
}
|
|
1041
|
-
var str = '';
|
|
1042
|
-
while (idx < endPtr) {
|
|
1043
|
-
// For UTF8 byte structure, see:
|
|
1044
|
-
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
1045
|
-
// https://www.ietf.org/rfc/rfc2279.txt
|
|
1046
|
-
// https://tools.ietf.org/html/rfc3629
|
|
1047
|
-
var u0 = heapOrArray[idx++];
|
|
1048
|
-
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
|
|
1049
|
-
var u1 = heapOrArray[idx++] & 63;
|
|
1050
|
-
if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
|
|
1051
|
-
var u2 = heapOrArray[idx++] & 63;
|
|
1052
|
-
if ((u0 & 0xF0) == 0xE0) {
|
|
1053
|
-
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
1054
|
-
} else {
|
|
1055
|
-
if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte ' + ptrToString(u0) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
|
|
1056
|
-
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
if (u0 < 0x10000) {
|
|
1060
|
-
str += String.fromCharCode(u0);
|
|
1061
|
-
} else {
|
|
1062
|
-
var ch = u0 - 0x10000;
|
|
1063
|
-
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
return str;
|
|
1067
|
-
};
|
|
1068
|
-
|
|
1069
|
-
var FS_stdin_getChar_buffer = [];
|
|
1070
|
-
|
|
1071
|
-
var lengthBytesUTF8 = (str) => {
|
|
1072
|
-
var len = 0;
|
|
1073
|
-
for (var i = 0; i < str.length; ++i) {
|
|
1074
|
-
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
1075
|
-
// unit, not a Unicode code point of the character! So decode
|
|
1076
|
-
// UTF16->UTF32->UTF8.
|
|
1077
|
-
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
1078
|
-
var c = str.charCodeAt(i); // possibly a lead surrogate
|
|
1079
|
-
if (c <= 0x7F) {
|
|
1080
|
-
len++;
|
|
1081
|
-
} else if (c <= 0x7FF) {
|
|
1082
|
-
len += 2;
|
|
1083
|
-
} else if (c >= 0xD800 && c <= 0xDFFF) {
|
|
1084
|
-
len += 4; ++i;
|
|
1085
|
-
} else {
|
|
1086
|
-
len += 3;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
return len;
|
|
1090
|
-
};
|
|
1091
|
-
|
|
1092
|
-
var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
|
|
1093
|
-
assert(typeof str === 'string', `stringToUTF8Array expects a string (got ${typeof str})`);
|
|
1094
|
-
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
|
|
1095
|
-
// undefined and false each don't write out any bytes.
|
|
1096
|
-
if (!(maxBytesToWrite > 0))
|
|
1097
|
-
return 0;
|
|
1098
|
-
|
|
1099
|
-
var startIdx = outIdx;
|
|
1100
|
-
var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
|
|
1101
|
-
for (var i = 0; i < str.length; ++i) {
|
|
1102
|
-
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
|
|
1103
|
-
// and https://www.ietf.org/rfc/rfc2279.txt
|
|
1104
|
-
// and https://tools.ietf.org/html/rfc3629
|
|
1105
|
-
var u = str.codePointAt(i);
|
|
1106
|
-
if (u <= 0x7F) {
|
|
1107
|
-
if (outIdx >= endIdx) break;
|
|
1108
|
-
heap[outIdx++] = u;
|
|
1109
|
-
} else if (u <= 0x7FF) {
|
|
1110
|
-
if (outIdx + 1 >= endIdx) break;
|
|
1111
|
-
heap[outIdx++] = 0xC0 | (u >> 6);
|
|
1112
|
-
heap[outIdx++] = 0x80 | (u & 63);
|
|
1113
|
-
} else if (u <= 0xFFFF) {
|
|
1114
|
-
if (outIdx + 2 >= endIdx) break;
|
|
1115
|
-
heap[outIdx++] = 0xE0 | (u >> 12);
|
|
1116
|
-
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
1117
|
-
heap[outIdx++] = 0x80 | (u & 63);
|
|
1118
|
-
} else {
|
|
1119
|
-
if (outIdx + 3 >= endIdx) break;
|
|
1120
|
-
if (u > 0x10FFFF) warnOnce('Invalid Unicode code point ' + ptrToString(u) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
|
|
1121
|
-
heap[outIdx++] = 0xF0 | (u >> 18);
|
|
1122
|
-
heap[outIdx++] = 0x80 | ((u >> 12) & 63);
|
|
1123
|
-
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
1124
|
-
heap[outIdx++] = 0x80 | (u & 63);
|
|
1125
|
-
// Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16.
|
|
1126
|
-
// We need to manually skip over the second code unit for correct iteration.
|
|
1127
|
-
i++;
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
// Null-terminate the pointer to the buffer.
|
|
1131
|
-
heap[outIdx] = 0;
|
|
1132
|
-
return outIdx - startIdx;
|
|
1133
|
-
};
|
|
1134
|
-
/** @type {function(string, boolean=, number=)} */
|
|
1135
|
-
var intArrayFromString = (stringy, dontAddNull, length) => {
|
|
1136
|
-
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
|
|
1137
|
-
var u8array = new Array(len);
|
|
1138
|
-
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
|
|
1139
|
-
if (dontAddNull) u8array.length = numBytesWritten;
|
|
1140
|
-
return u8array;
|
|
1141
|
-
};
|
|
1142
|
-
var FS_stdin_getChar = () => {
|
|
1143
|
-
if (!FS_stdin_getChar_buffer.length) {
|
|
1144
|
-
var result = null;
|
|
1145
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
1146
|
-
// we will read data by chunks of BUFSIZE
|
|
1147
|
-
var BUFSIZE = 256;
|
|
1148
|
-
var buf = Buffer.alloc(BUFSIZE);
|
|
1149
|
-
var bytesRead = 0;
|
|
1150
|
-
|
|
1151
|
-
// For some reason we must suppress a closure warning here, even though
|
|
1152
|
-
// fd definitely exists on process.stdin, and is even the proper way to
|
|
1153
|
-
// get the fd of stdin,
|
|
1154
|
-
// https://github.com/nodejs/help/issues/2136#issuecomment-523649904
|
|
1155
|
-
// This started to happen after moving this logic out of library_tty.js,
|
|
1156
|
-
// so it is related to the surrounding code in some unclear manner.
|
|
1157
|
-
/** @suppress {missingProperties} */
|
|
1158
|
-
var fd = process.stdin.fd;
|
|
1159
|
-
|
|
1160
|
-
try {
|
|
1161
|
-
bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
|
|
1162
|
-
} catch(e) {
|
|
1163
|
-
// Cross-platform differences: on Windows, reading EOF throws an
|
|
1164
|
-
// exception, but on other OSes, reading EOF returns 0. Uniformize
|
|
1165
|
-
// behavior by treating the EOF exception to return 0.
|
|
1166
|
-
if (e.toString().includes('EOF')) bytesRead = 0;
|
|
1167
|
-
else throw e;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
if (bytesRead > 0) {
|
|
1171
|
-
result = buf.slice(0, bytesRead).toString('utf-8');
|
|
1172
|
-
}
|
|
1173
|
-
} else
|
|
1174
|
-
if (globalThis.window?.prompt) {
|
|
1175
|
-
// Browser.
|
|
1176
|
-
result = window.prompt('Input: '); // returns null on cancel
|
|
1177
|
-
if (result !== null) {
|
|
1178
|
-
result += '\n';
|
|
1179
|
-
}
|
|
1180
|
-
} else
|
|
1181
|
-
{}
|
|
1182
|
-
if (!result) {
|
|
1183
|
-
return null;
|
|
1184
|
-
}
|
|
1185
|
-
FS_stdin_getChar_buffer = intArrayFromString(result, true);
|
|
1186
|
-
}
|
|
1187
|
-
return FS_stdin_getChar_buffer.shift();
|
|
1188
|
-
};
|
|
1189
|
-
var TTY = {
|
|
1190
|
-
ttys:[],
|
|
1191
|
-
init() {
|
|
1192
|
-
// https://github.com/emscripten-core/emscripten/pull/1555
|
|
1193
|
-
// if (ENVIRONMENT_IS_NODE) {
|
|
1194
|
-
// // currently, FS.init does not distinguish if process.stdin is a file or TTY
|
|
1195
|
-
// // device, it always assumes it's a TTY device. because of this, we're forcing
|
|
1196
|
-
// // process.stdin to UTF8 encoding to at least make stdin reading compatible
|
|
1197
|
-
// // with text files until FS.init can be refactored.
|
|
1198
|
-
// process.stdin.setEncoding('utf8');
|
|
1199
|
-
// }
|
|
1200
|
-
},
|
|
1201
|
-
shutdown() {
|
|
1202
|
-
// https://github.com/emscripten-core/emscripten/pull/1555
|
|
1203
|
-
// if (ENVIRONMENT_IS_NODE) {
|
|
1204
|
-
// // inolen: any idea as to why node -e 'process.stdin.read()' wouldn't exit immediately (with process.stdin being a tty)?
|
|
1205
|
-
// // 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
|
|
1206
|
-
// // inolen: I thought read() in that case was a synchronous operation that just grabbed some amount of buffered data if it exists?
|
|
1207
|
-
// // isaacs: it is. but it also triggers a _read() call, which calls readStart() on the handle
|
|
1208
|
-
// // isaacs: do process.stdin.pause() and i'd think it'd probably close the pending call
|
|
1209
|
-
// process.stdin.pause();
|
|
1210
|
-
// }
|
|
1211
|
-
},
|
|
1212
|
-
register(dev, ops) {
|
|
1213
|
-
TTY.ttys[dev] = { input: [], output: [], ops: ops };
|
|
1214
|
-
FS.registerDevice(dev, TTY.stream_ops);
|
|
1215
|
-
},
|
|
1216
|
-
stream_ops:{
|
|
1217
|
-
open(stream) {
|
|
1218
|
-
var tty = TTY.ttys[stream.node.rdev];
|
|
1219
|
-
if (!tty) {
|
|
1220
|
-
throw new FS.ErrnoError(43);
|
|
1221
|
-
}
|
|
1222
|
-
stream.tty = tty;
|
|
1223
|
-
stream.seekable = false;
|
|
1224
|
-
},
|
|
1225
|
-
close(stream) {
|
|
1226
|
-
// flush any pending line data
|
|
1227
|
-
stream.tty.ops.fsync(stream.tty);
|
|
1228
|
-
},
|
|
1229
|
-
fsync(stream) {
|
|
1230
|
-
stream.tty.ops.fsync(stream.tty);
|
|
1231
|
-
},
|
|
1232
|
-
read(stream, buffer, offset, length, pos /* ignored */) {
|
|
1233
|
-
if (!stream.tty || !stream.tty.ops.get_char) {
|
|
1234
|
-
throw new FS.ErrnoError(60);
|
|
1235
|
-
}
|
|
1236
|
-
var bytesRead = 0;
|
|
1237
|
-
for (var i = 0; i < length; i++) {
|
|
1238
|
-
var result;
|
|
1239
|
-
try {
|
|
1240
|
-
result = stream.tty.ops.get_char(stream.tty);
|
|
1241
|
-
} catch (e) {
|
|
1242
|
-
throw new FS.ErrnoError(29);
|
|
1243
|
-
}
|
|
1244
|
-
if (result === undefined && bytesRead === 0) {
|
|
1245
|
-
throw new FS.ErrnoError(6);
|
|
1246
|
-
}
|
|
1247
|
-
if (result === null || result === undefined) break;
|
|
1248
|
-
bytesRead++;
|
|
1249
|
-
buffer[offset+i] = result;
|
|
1250
|
-
}
|
|
1251
|
-
if (bytesRead) {
|
|
1252
|
-
stream.node.atime = Date.now();
|
|
1253
|
-
}
|
|
1254
|
-
return bytesRead;
|
|
1255
|
-
},
|
|
1256
|
-
write(stream, buffer, offset, length, pos) {
|
|
1257
|
-
if (!stream.tty || !stream.tty.ops.put_char) {
|
|
1258
|
-
throw new FS.ErrnoError(60);
|
|
1259
|
-
}
|
|
1260
|
-
try {
|
|
1261
|
-
for (var i = 0; i < length; i++) {
|
|
1262
|
-
stream.tty.ops.put_char(stream.tty, buffer[offset+i]);
|
|
1263
|
-
}
|
|
1264
|
-
} catch (e) {
|
|
1265
|
-
throw new FS.ErrnoError(29);
|
|
1266
|
-
}
|
|
1267
|
-
if (length) {
|
|
1268
|
-
stream.node.mtime = stream.node.ctime = Date.now();
|
|
1269
|
-
}
|
|
1270
|
-
return i;
|
|
1271
|
-
},
|
|
1272
|
-
},
|
|
1273
|
-
default_tty_ops:{
|
|
1274
|
-
get_char(tty) {
|
|
1275
|
-
return FS_stdin_getChar();
|
|
1276
|
-
},
|
|
1277
|
-
put_char(tty, val) {
|
|
1278
|
-
if (val === null || val === 10) {
|
|
1279
|
-
out(UTF8ArrayToString(tty.output));
|
|
1280
|
-
tty.output = [];
|
|
1281
|
-
} else {
|
|
1282
|
-
if (val != 0) tty.output.push(val); // val == 0 would cut text output off in the middle.
|
|
1283
|
-
}
|
|
1284
|
-
},
|
|
1285
|
-
fsync(tty) {
|
|
1286
|
-
if (tty.output?.length > 0) {
|
|
1287
|
-
out(UTF8ArrayToString(tty.output));
|
|
1288
|
-
tty.output = [];
|
|
1289
|
-
}
|
|
1290
|
-
},
|
|
1291
|
-
ioctl_tcgets(tty) {
|
|
1292
|
-
// typical setting
|
|
1293
|
-
return {
|
|
1294
|
-
c_iflag: 25856,
|
|
1295
|
-
c_oflag: 5,
|
|
1296
|
-
c_cflag: 191,
|
|
1297
|
-
c_lflag: 35387,
|
|
1298
|
-
c_cc: [
|
|
1299
|
-
0x03, 0x1c, 0x7f, 0x15, 0x04, 0x00, 0x01, 0x00, 0x11, 0x13, 0x1a, 0x00,
|
|
1300
|
-
0x12, 0x0f, 0x17, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
1301
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
1302
|
-
]
|
|
1303
|
-
};
|
|
1304
|
-
},
|
|
1305
|
-
ioctl_tcsets(tty, optional_actions, data) {
|
|
1306
|
-
// currently just ignore
|
|
1307
|
-
return 0;
|
|
1308
|
-
},
|
|
1309
|
-
ioctl_tiocgwinsz(tty) {
|
|
1310
|
-
return [24, 80];
|
|
1311
|
-
},
|
|
1312
|
-
},
|
|
1313
|
-
default_tty1_ops:{
|
|
1314
|
-
put_char(tty, val) {
|
|
1315
|
-
if (val === null || val === 10) {
|
|
1316
|
-
err(UTF8ArrayToString(tty.output));
|
|
1317
|
-
tty.output = [];
|
|
1318
|
-
} else {
|
|
1319
|
-
if (val != 0) tty.output.push(val);
|
|
1320
|
-
}
|
|
1321
|
-
},
|
|
1322
|
-
fsync(tty) {
|
|
1323
|
-
if (tty.output?.length > 0) {
|
|
1324
|
-
err(UTF8ArrayToString(tty.output));
|
|
1325
|
-
tty.output = [];
|
|
1326
|
-
}
|
|
1327
|
-
},
|
|
1328
|
-
},
|
|
1329
|
-
};
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
var mmapAlloc = (size) => {
|
|
1333
|
-
abort('internal error: mmapAlloc called but `emscripten_builtin_memalign` native symbol not exported');
|
|
1334
|
-
};
|
|
1335
|
-
var MEMFS = {
|
|
1336
|
-
ops_table:null,
|
|
1337
|
-
mount(mount) {
|
|
1338
|
-
return MEMFS.createNode(null, '/', 16895, 0);
|
|
1339
|
-
},
|
|
1340
|
-
createNode(parent, name, mode, dev) {
|
|
1341
|
-
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
|
|
1342
|
-
// no supported
|
|
1343
|
-
throw new FS.ErrnoError(63);
|
|
1344
|
-
}
|
|
1345
|
-
MEMFS.ops_table ||= {
|
|
1346
|
-
dir: {
|
|
1347
|
-
node: {
|
|
1348
|
-
getattr: MEMFS.node_ops.getattr,
|
|
1349
|
-
setattr: MEMFS.node_ops.setattr,
|
|
1350
|
-
lookup: MEMFS.node_ops.lookup,
|
|
1351
|
-
mknod: MEMFS.node_ops.mknod,
|
|
1352
|
-
rename: MEMFS.node_ops.rename,
|
|
1353
|
-
unlink: MEMFS.node_ops.unlink,
|
|
1354
|
-
rmdir: MEMFS.node_ops.rmdir,
|
|
1355
|
-
readdir: MEMFS.node_ops.readdir,
|
|
1356
|
-
symlink: MEMFS.node_ops.symlink
|
|
1357
|
-
},
|
|
1358
|
-
stream: {
|
|
1359
|
-
llseek: MEMFS.stream_ops.llseek
|
|
1360
|
-
}
|
|
1361
|
-
},
|
|
1362
|
-
file: {
|
|
1363
|
-
node: {
|
|
1364
|
-
getattr: MEMFS.node_ops.getattr,
|
|
1365
|
-
setattr: MEMFS.node_ops.setattr
|
|
1366
|
-
},
|
|
1367
|
-
stream: {
|
|
1368
|
-
llseek: MEMFS.stream_ops.llseek,
|
|
1369
|
-
read: MEMFS.stream_ops.read,
|
|
1370
|
-
write: MEMFS.stream_ops.write,
|
|
1371
|
-
mmap: MEMFS.stream_ops.mmap,
|
|
1372
|
-
msync: MEMFS.stream_ops.msync
|
|
1373
|
-
}
|
|
1374
|
-
},
|
|
1375
|
-
link: {
|
|
1376
|
-
node: {
|
|
1377
|
-
getattr: MEMFS.node_ops.getattr,
|
|
1378
|
-
setattr: MEMFS.node_ops.setattr,
|
|
1379
|
-
readlink: MEMFS.node_ops.readlink
|
|
1380
|
-
},
|
|
1381
|
-
stream: {}
|
|
1382
|
-
},
|
|
1383
|
-
chrdev: {
|
|
1384
|
-
node: {
|
|
1385
|
-
getattr: MEMFS.node_ops.getattr,
|
|
1386
|
-
setattr: MEMFS.node_ops.setattr
|
|
1387
|
-
},
|
|
1388
|
-
stream: FS.chrdev_stream_ops
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
var node = FS.createNode(parent, name, mode, dev);
|
|
1392
|
-
if (FS.isDir(node.mode)) {
|
|
1393
|
-
node.node_ops = MEMFS.ops_table.dir.node;
|
|
1394
|
-
node.stream_ops = MEMFS.ops_table.dir.stream;
|
|
1395
|
-
node.contents = {};
|
|
1396
|
-
} else if (FS.isFile(node.mode)) {
|
|
1397
|
-
node.node_ops = MEMFS.ops_table.file.node;
|
|
1398
|
-
node.stream_ops = MEMFS.ops_table.file.stream;
|
|
1399
|
-
node.usedBytes = 0; // The actual number of bytes used in the typed array, as opposed to contents.length which gives the whole capacity.
|
|
1400
|
-
// When the byte data of the file is populated, this will point to either a typed array, or a normal JS array. Typed arrays are preferred
|
|
1401
|
-
// for performance, and used by default. However, typed arrays are not resizable like normal JS arrays are, so there is a small disk size
|
|
1402
|
-
// penalty involved for appending file writes that continuously grow a file similar to std::vector capacity vs used -scheme.
|
|
1403
|
-
node.contents = null;
|
|
1404
|
-
} else if (FS.isLink(node.mode)) {
|
|
1405
|
-
node.node_ops = MEMFS.ops_table.link.node;
|
|
1406
|
-
node.stream_ops = MEMFS.ops_table.link.stream;
|
|
1407
|
-
} else if (FS.isChrdev(node.mode)) {
|
|
1408
|
-
node.node_ops = MEMFS.ops_table.chrdev.node;
|
|
1409
|
-
node.stream_ops = MEMFS.ops_table.chrdev.stream;
|
|
1410
|
-
}
|
|
1411
|
-
node.atime = node.mtime = node.ctime = Date.now();
|
|
1412
|
-
// add the new node to the parent
|
|
1413
|
-
if (parent) {
|
|
1414
|
-
parent.contents[name] = node;
|
|
1415
|
-
parent.atime = parent.mtime = parent.ctime = node.atime;
|
|
1416
|
-
}
|
|
1417
|
-
return node;
|
|
1418
|
-
},
|
|
1419
|
-
getFileDataAsTypedArray(node) {
|
|
1420
|
-
if (!node.contents) return new Uint8Array(0);
|
|
1421
|
-
if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes); // Make sure to not return excess unused bytes.
|
|
1422
|
-
return new Uint8Array(node.contents);
|
|
1423
|
-
},
|
|
1424
|
-
expandFileStorage(node, newCapacity) {
|
|
1425
|
-
var prevCapacity = node.contents ? node.contents.length : 0;
|
|
1426
|
-
if (prevCapacity >= newCapacity) return; // No need to expand, the storage was already large enough.
|
|
1427
|
-
// Don't expand strictly to the given requested limit if it's only a very small increase, but instead geometrically grow capacity.
|
|
1428
|
-
// For small filesizes (<1MB), perform size*2 geometric increase, but for large sizes, do a much more conservative size*1.125 increase to
|
|
1429
|
-
// avoid overshooting the allocation cap by a very large margin.
|
|
1430
|
-
var CAPACITY_DOUBLING_MAX = 1024 * 1024;
|
|
1431
|
-
newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2.0 : 1.125)) >>> 0);
|
|
1432
|
-
if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding.
|
|
1433
|
-
var oldContents = node.contents;
|
|
1434
|
-
node.contents = new Uint8Array(newCapacity); // Allocate new storage.
|
|
1435
|
-
if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0); // Copy old data over to the new storage.
|
|
1436
|
-
},
|
|
1437
|
-
resizeFileStorage(node, newSize) {
|
|
1438
|
-
if (node.usedBytes == newSize) return;
|
|
1439
|
-
if (newSize == 0) {
|
|
1440
|
-
node.contents = null; // Fully decommit when requesting a resize to zero.
|
|
1441
|
-
node.usedBytes = 0;
|
|
1442
|
-
} else {
|
|
1443
|
-
var oldContents = node.contents;
|
|
1444
|
-
node.contents = new Uint8Array(newSize); // Allocate new storage.
|
|
1445
|
-
if (oldContents) {
|
|
1446
|
-
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes))); // Copy old data over to the new storage.
|
|
1447
|
-
}
|
|
1448
|
-
node.usedBytes = newSize;
|
|
1449
|
-
}
|
|
1450
|
-
},
|
|
1451
|
-
node_ops:{
|
|
1452
|
-
getattr(node) {
|
|
1453
|
-
var attr = {};
|
|
1454
|
-
// device numbers reuse inode numbers.
|
|
1455
|
-
attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
|
|
1456
|
-
attr.ino = node.id;
|
|
1457
|
-
attr.mode = node.mode;
|
|
1458
|
-
attr.nlink = 1;
|
|
1459
|
-
attr.uid = 0;
|
|
1460
|
-
attr.gid = 0;
|
|
1461
|
-
attr.rdev = node.rdev;
|
|
1462
|
-
if (FS.isDir(node.mode)) {
|
|
1463
|
-
attr.size = 4096;
|
|
1464
|
-
} else if (FS.isFile(node.mode)) {
|
|
1465
|
-
attr.size = node.usedBytes;
|
|
1466
|
-
} else if (FS.isLink(node.mode)) {
|
|
1467
|
-
attr.size = node.link.length;
|
|
1468
|
-
} else {
|
|
1469
|
-
attr.size = 0;
|
|
1470
|
-
}
|
|
1471
|
-
attr.atime = new Date(node.atime);
|
|
1472
|
-
attr.mtime = new Date(node.mtime);
|
|
1473
|
-
attr.ctime = new Date(node.ctime);
|
|
1474
|
-
// NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
|
|
1475
|
-
// but this is not required by the standard.
|
|
1476
|
-
attr.blksize = 4096;
|
|
1477
|
-
attr.blocks = Math.ceil(attr.size / attr.blksize);
|
|
1478
|
-
return attr;
|
|
1479
|
-
},
|
|
1480
|
-
setattr(node, attr) {
|
|
1481
|
-
for (const key of ["mode", "atime", "mtime", "ctime"]) {
|
|
1482
|
-
if (attr[key] != null) {
|
|
1483
|
-
node[key] = attr[key];
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
if (attr.size !== undefined) {
|
|
1487
|
-
MEMFS.resizeFileStorage(node, attr.size);
|
|
1488
|
-
}
|
|
1489
|
-
},
|
|
1490
|
-
lookup(parent, name) {
|
|
1491
|
-
throw new FS.ErrnoError(44);
|
|
1492
|
-
},
|
|
1493
|
-
mknod(parent, name, mode, dev) {
|
|
1494
|
-
return MEMFS.createNode(parent, name, mode, dev);
|
|
1495
|
-
},
|
|
1496
|
-
rename(old_node, new_dir, new_name) {
|
|
1497
|
-
var new_node;
|
|
1498
|
-
try {
|
|
1499
|
-
new_node = FS.lookupNode(new_dir, new_name);
|
|
1500
|
-
} catch (e) {}
|
|
1501
|
-
if (new_node) {
|
|
1502
|
-
if (FS.isDir(old_node.mode)) {
|
|
1503
|
-
// if we're overwriting a directory at new_name, make sure it's empty.
|
|
1504
|
-
for (var i in new_node.contents) {
|
|
1505
|
-
throw new FS.ErrnoError(55);
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
FS.hashRemoveNode(new_node);
|
|
1509
|
-
}
|
|
1510
|
-
// do the internal rewiring
|
|
1511
|
-
delete old_node.parent.contents[old_node.name];
|
|
1512
|
-
new_dir.contents[new_name] = old_node;
|
|
1513
|
-
old_node.name = new_name;
|
|
1514
|
-
new_dir.ctime = new_dir.mtime = old_node.parent.ctime = old_node.parent.mtime = Date.now();
|
|
1515
|
-
},
|
|
1516
|
-
unlink(parent, name) {
|
|
1517
|
-
delete parent.contents[name];
|
|
1518
|
-
parent.ctime = parent.mtime = Date.now();
|
|
1519
|
-
},
|
|
1520
|
-
rmdir(parent, name) {
|
|
1521
|
-
var node = FS.lookupNode(parent, name);
|
|
1522
|
-
for (var i in node.contents) {
|
|
1523
|
-
throw new FS.ErrnoError(55);
|
|
1524
|
-
}
|
|
1525
|
-
delete parent.contents[name];
|
|
1526
|
-
parent.ctime = parent.mtime = Date.now();
|
|
1527
|
-
},
|
|
1528
|
-
readdir(node) {
|
|
1529
|
-
return ['.', '..', ...Object.keys(node.contents)];
|
|
1530
|
-
},
|
|
1531
|
-
symlink(parent, newname, oldpath) {
|
|
1532
|
-
var node = MEMFS.createNode(parent, newname, 0o777 | 40960, 0);
|
|
1533
|
-
node.link = oldpath;
|
|
1534
|
-
return node;
|
|
1535
|
-
},
|
|
1536
|
-
readlink(node) {
|
|
1537
|
-
if (!FS.isLink(node.mode)) {
|
|
1538
|
-
throw new FS.ErrnoError(28);
|
|
1539
|
-
}
|
|
1540
|
-
return node.link;
|
|
1541
|
-
},
|
|
1542
|
-
},
|
|
1543
|
-
stream_ops:{
|
|
1544
|
-
read(stream, buffer, offset, length, position) {
|
|
1545
|
-
var contents = stream.node.contents;
|
|
1546
|
-
if (position >= stream.node.usedBytes) return 0;
|
|
1547
|
-
var size = Math.min(stream.node.usedBytes - position, length);
|
|
1548
|
-
assert(size >= 0);
|
|
1549
|
-
if (size > 8 && contents.subarray) { // non-trivial, and typed array
|
|
1550
|
-
buffer.set(contents.subarray(position, position + size), offset);
|
|
1551
|
-
} else {
|
|
1552
|
-
for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
|
|
1553
|
-
}
|
|
1554
|
-
return size;
|
|
1555
|
-
},
|
|
1556
|
-
write(stream, buffer, offset, length, position, canOwn) {
|
|
1557
|
-
// The data buffer should be a typed array view
|
|
1558
|
-
assert(!(buffer instanceof ArrayBuffer));
|
|
1559
|
-
|
|
1560
|
-
if (!length) return 0;
|
|
1561
|
-
var node = stream.node;
|
|
1562
|
-
node.mtime = node.ctime = Date.now();
|
|
1563
|
-
|
|
1564
|
-
if (buffer.subarray && (!node.contents || node.contents.subarray)) { // This write is from a typed array to a typed array?
|
|
1565
|
-
if (canOwn) {
|
|
1566
|
-
assert(position === 0, 'canOwn must imply no weird position inside the file');
|
|
1567
|
-
node.contents = buffer.subarray(offset, offset + length);
|
|
1568
|
-
node.usedBytes = length;
|
|
1569
|
-
return length;
|
|
1570
|
-
} else if (node.usedBytes === 0 && position === 0) { // If this is a simple first write to an empty file, do a fast set since we don't need to care about old data.
|
|
1571
|
-
node.contents = buffer.slice(offset, offset + length);
|
|
1572
|
-
node.usedBytes = length;
|
|
1573
|
-
return length;
|
|
1574
|
-
} else if (position + length <= node.usedBytes) { // Writing to an already allocated and used subrange of the file?
|
|
1575
|
-
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
1576
|
-
return length;
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
|
-
// Appending to an existing file and we need to reallocate, or source data did not come as a typed array.
|
|
1581
|
-
MEMFS.expandFileStorage(node, position+length);
|
|
1582
|
-
if (node.contents.subarray && buffer.subarray) {
|
|
1583
|
-
// Use typed array write which is available.
|
|
1584
|
-
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
1585
|
-
} else {
|
|
1586
|
-
for (var i = 0; i < length; i++) {
|
|
1587
|
-
node.contents[position + i] = buffer[offset + i]; // Or fall back to manual write if not.
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
node.usedBytes = Math.max(node.usedBytes, position + length);
|
|
1591
|
-
return length;
|
|
1592
|
-
},
|
|
1593
|
-
llseek(stream, offset, whence) {
|
|
1594
|
-
var position = offset;
|
|
1595
|
-
if (whence === 1) {
|
|
1596
|
-
position += stream.position;
|
|
1597
|
-
} else if (whence === 2) {
|
|
1598
|
-
if (FS.isFile(stream.node.mode)) {
|
|
1599
|
-
position += stream.node.usedBytes;
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
if (position < 0) {
|
|
1603
|
-
throw new FS.ErrnoError(28);
|
|
1604
|
-
}
|
|
1605
|
-
return position;
|
|
1606
|
-
},
|
|
1607
|
-
mmap(stream, length, position, prot, flags) {
|
|
1608
|
-
if (!FS.isFile(stream.node.mode)) {
|
|
1609
|
-
throw new FS.ErrnoError(43);
|
|
1610
|
-
}
|
|
1611
|
-
var ptr;
|
|
1612
|
-
var allocated;
|
|
1613
|
-
var contents = stream.node.contents;
|
|
1614
|
-
// Only make a new copy when MAP_PRIVATE is specified.
|
|
1615
|
-
if (!(flags & 2) && contents && contents.buffer === HEAP8.buffer) {
|
|
1616
|
-
// We can't emulate MAP_SHARED when the file is not backed by the
|
|
1617
|
-
// buffer we're mapping to (e.g. the HEAP buffer).
|
|
1618
|
-
allocated = false;
|
|
1619
|
-
ptr = contents.byteOffset;
|
|
1620
|
-
} else {
|
|
1621
|
-
allocated = true;
|
|
1622
|
-
ptr = mmapAlloc(length);
|
|
1623
|
-
if (!ptr) {
|
|
1624
|
-
throw new FS.ErrnoError(48);
|
|
1625
|
-
}
|
|
1626
|
-
if (contents) {
|
|
1627
|
-
// Try to avoid unnecessary slices.
|
|
1628
|
-
if (position > 0 || position + length < contents.length) {
|
|
1629
|
-
if (contents.subarray) {
|
|
1630
|
-
contents = contents.subarray(position, position + length);
|
|
1631
|
-
} else {
|
|
1632
|
-
contents = Array.prototype.slice.call(contents, position, position + length);
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
HEAP8.set(contents, ptr);
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
return { ptr, allocated };
|
|
1639
|
-
},
|
|
1640
|
-
msync(stream, buffer, offset, length, mmapFlags) {
|
|
1641
|
-
MEMFS.stream_ops.write(stream, buffer, 0, length, offset, false);
|
|
1642
|
-
// should we check if bytesWritten and length are the same?
|
|
1643
|
-
return 0;
|
|
1644
|
-
},
|
|
1645
|
-
},
|
|
1646
|
-
};
|
|
1647
|
-
|
|
1648
|
-
var FS_modeStringToFlags = (str) => {
|
|
1649
|
-
var flagModes = {
|
|
1650
|
-
'r': 0,
|
|
1651
|
-
'r+': 2,
|
|
1652
|
-
'w': 512 | 64 | 1,
|
|
1653
|
-
'w+': 512 | 64 | 2,
|
|
1654
|
-
'a': 1024 | 64 | 1,
|
|
1655
|
-
'a+': 1024 | 64 | 2,
|
|
1656
|
-
};
|
|
1657
|
-
var flags = flagModes[str];
|
|
1658
|
-
if (typeof flags == 'undefined') {
|
|
1659
|
-
throw new Error(`Unknown file open mode: ${str}`);
|
|
1660
|
-
}
|
|
1661
|
-
return flags;
|
|
1662
|
-
};
|
|
1663
|
-
|
|
1664
|
-
var FS_getMode = (canRead, canWrite) => {
|
|
1665
|
-
var mode = 0;
|
|
1666
|
-
if (canRead) mode |= 292 | 73;
|
|
1667
|
-
if (canWrite) mode |= 146;
|
|
1668
|
-
return mode;
|
|
1669
|
-
};
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
/**
|
|
1675
|
-
* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
|
|
1676
|
-
* emscripten HEAP, returns a copy of that string as a Javascript String object.
|
|
1677
|
-
*
|
|
1678
|
-
* @param {number} ptr
|
|
1679
|
-
* @param {number=} maxBytesToRead - An optional length that specifies the
|
|
1680
|
-
* maximum number of bytes to read. You can omit this parameter to scan the
|
|
1681
|
-
* string until the first 0 byte. If maxBytesToRead is passed, and the string
|
|
1682
|
-
* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
|
|
1683
|
-
* string will cut short at that byte index.
|
|
1684
|
-
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
1685
|
-
* @return {string}
|
|
1686
|
-
*/
|
|
1687
|
-
var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => {
|
|
1688
|
-
assert(typeof ptr == 'number', `UTF8ToString expects a number (got ${typeof ptr})`);
|
|
1689
|
-
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : '';
|
|
1690
|
-
};
|
|
1691
|
-
|
|
1692
|
-
var strError = (errno) => UTF8ToString(_strerror(errno));
|
|
1693
|
-
|
|
1694
|
-
var ERRNO_CODES = {
|
|
1695
|
-
'EPERM': 63,
|
|
1696
|
-
'ENOENT': 44,
|
|
1697
|
-
'ESRCH': 71,
|
|
1698
|
-
'EINTR': 27,
|
|
1699
|
-
'EIO': 29,
|
|
1700
|
-
'ENXIO': 60,
|
|
1701
|
-
'E2BIG': 1,
|
|
1702
|
-
'ENOEXEC': 45,
|
|
1703
|
-
'EBADF': 8,
|
|
1704
|
-
'ECHILD': 12,
|
|
1705
|
-
'EAGAIN': 6,
|
|
1706
|
-
'EWOULDBLOCK': 6,
|
|
1707
|
-
'ENOMEM': 48,
|
|
1708
|
-
'EACCES': 2,
|
|
1709
|
-
'EFAULT': 21,
|
|
1710
|
-
'ENOTBLK': 105,
|
|
1711
|
-
'EBUSY': 10,
|
|
1712
|
-
'EEXIST': 20,
|
|
1713
|
-
'EXDEV': 75,
|
|
1714
|
-
'ENODEV': 43,
|
|
1715
|
-
'ENOTDIR': 54,
|
|
1716
|
-
'EISDIR': 31,
|
|
1717
|
-
'EINVAL': 28,
|
|
1718
|
-
'ENFILE': 41,
|
|
1719
|
-
'EMFILE': 33,
|
|
1720
|
-
'ENOTTY': 59,
|
|
1721
|
-
'ETXTBSY': 74,
|
|
1722
|
-
'EFBIG': 22,
|
|
1723
|
-
'ENOSPC': 51,
|
|
1724
|
-
'ESPIPE': 70,
|
|
1725
|
-
'EROFS': 69,
|
|
1726
|
-
'EMLINK': 34,
|
|
1727
|
-
'EPIPE': 64,
|
|
1728
|
-
'EDOM': 18,
|
|
1729
|
-
'ERANGE': 68,
|
|
1730
|
-
'ENOMSG': 49,
|
|
1731
|
-
'EIDRM': 24,
|
|
1732
|
-
'ECHRNG': 106,
|
|
1733
|
-
'EL2NSYNC': 156,
|
|
1734
|
-
'EL3HLT': 107,
|
|
1735
|
-
'EL3RST': 108,
|
|
1736
|
-
'ELNRNG': 109,
|
|
1737
|
-
'EUNATCH': 110,
|
|
1738
|
-
'ENOCSI': 111,
|
|
1739
|
-
'EL2HLT': 112,
|
|
1740
|
-
'EDEADLK': 16,
|
|
1741
|
-
'ENOLCK': 46,
|
|
1742
|
-
'EBADE': 113,
|
|
1743
|
-
'EBADR': 114,
|
|
1744
|
-
'EXFULL': 115,
|
|
1745
|
-
'ENOANO': 104,
|
|
1746
|
-
'EBADRQC': 103,
|
|
1747
|
-
'EBADSLT': 102,
|
|
1748
|
-
'EDEADLOCK': 16,
|
|
1749
|
-
'EBFONT': 101,
|
|
1750
|
-
'ENOSTR': 100,
|
|
1751
|
-
'ENODATA': 116,
|
|
1752
|
-
'ETIME': 117,
|
|
1753
|
-
'ENOSR': 118,
|
|
1754
|
-
'ENONET': 119,
|
|
1755
|
-
'ENOPKG': 120,
|
|
1756
|
-
'EREMOTE': 121,
|
|
1757
|
-
'ENOLINK': 47,
|
|
1758
|
-
'EADV': 122,
|
|
1759
|
-
'ESRMNT': 123,
|
|
1760
|
-
'ECOMM': 124,
|
|
1761
|
-
'EPROTO': 65,
|
|
1762
|
-
'EMULTIHOP': 36,
|
|
1763
|
-
'EDOTDOT': 125,
|
|
1764
|
-
'EBADMSG': 9,
|
|
1765
|
-
'ENOTUNIQ': 126,
|
|
1766
|
-
'EBADFD': 127,
|
|
1767
|
-
'EREMCHG': 128,
|
|
1768
|
-
'ELIBACC': 129,
|
|
1769
|
-
'ELIBBAD': 130,
|
|
1770
|
-
'ELIBSCN': 131,
|
|
1771
|
-
'ELIBMAX': 132,
|
|
1772
|
-
'ELIBEXEC': 133,
|
|
1773
|
-
'ENOSYS': 52,
|
|
1774
|
-
'ENOTEMPTY': 55,
|
|
1775
|
-
'ENAMETOOLONG': 37,
|
|
1776
|
-
'ELOOP': 32,
|
|
1777
|
-
'EOPNOTSUPP': 138,
|
|
1778
|
-
'EPFNOSUPPORT': 139,
|
|
1779
|
-
'ECONNRESET': 15,
|
|
1780
|
-
'ENOBUFS': 42,
|
|
1781
|
-
'EAFNOSUPPORT': 5,
|
|
1782
|
-
'EPROTOTYPE': 67,
|
|
1783
|
-
'ENOTSOCK': 57,
|
|
1784
|
-
'ENOPROTOOPT': 50,
|
|
1785
|
-
'ESHUTDOWN': 140,
|
|
1786
|
-
'ECONNREFUSED': 14,
|
|
1787
|
-
'EADDRINUSE': 3,
|
|
1788
|
-
'ECONNABORTED': 13,
|
|
1789
|
-
'ENETUNREACH': 40,
|
|
1790
|
-
'ENETDOWN': 38,
|
|
1791
|
-
'ETIMEDOUT': 73,
|
|
1792
|
-
'EHOSTDOWN': 142,
|
|
1793
|
-
'EHOSTUNREACH': 23,
|
|
1794
|
-
'EINPROGRESS': 26,
|
|
1795
|
-
'EALREADY': 7,
|
|
1796
|
-
'EDESTADDRREQ': 17,
|
|
1797
|
-
'EMSGSIZE': 35,
|
|
1798
|
-
'EPROTONOSUPPORT': 66,
|
|
1799
|
-
'ESOCKTNOSUPPORT': 137,
|
|
1800
|
-
'EADDRNOTAVAIL': 4,
|
|
1801
|
-
'ENETRESET': 39,
|
|
1802
|
-
'EISCONN': 30,
|
|
1803
|
-
'ENOTCONN': 53,
|
|
1804
|
-
'ETOOMANYREFS': 141,
|
|
1805
|
-
'EUSERS': 136,
|
|
1806
|
-
'EDQUOT': 19,
|
|
1807
|
-
'ESTALE': 72,
|
|
1808
|
-
'ENOTSUP': 138,
|
|
1809
|
-
'ENOMEDIUM': 148,
|
|
1810
|
-
'EILSEQ': 25,
|
|
1811
|
-
'EOVERFLOW': 61,
|
|
1812
|
-
'ECANCELED': 11,
|
|
1813
|
-
'ENOTRECOVERABLE': 56,
|
|
1814
|
-
'EOWNERDEAD': 62,
|
|
1815
|
-
'ESTRPIPE': 135,
|
|
1816
|
-
};
|
|
1817
|
-
|
|
1818
|
-
var asyncLoad = async (url) => {
|
|
1819
|
-
var arrayBuffer = await readAsync(url);
|
|
1820
|
-
assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`);
|
|
1821
|
-
return new Uint8Array(arrayBuffer);
|
|
1822
|
-
};
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
var FS_createDataFile = (...args) => FS.createDataFile(...args);
|
|
1826
|
-
|
|
1827
|
-
var getUniqueRunDependency = (id) => {
|
|
1828
|
-
var orig = id;
|
|
1829
|
-
while (1) {
|
|
1830
|
-
if (!runDependencyTracking[id]) return id;
|
|
1831
|
-
id = orig + Math.random();
|
|
1832
|
-
}
|
|
1833
|
-
};
|
|
1834
|
-
|
|
1835
|
-
var runDependencies = 0;
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
var dependenciesFulfilled = null;
|
|
1839
|
-
|
|
1840
|
-
var runDependencyTracking = {
|
|
1841
|
-
};
|
|
1842
|
-
|
|
1843
|
-
var runDependencyWatcher = null;
|
|
1844
|
-
var removeRunDependency = (id) => {
|
|
1845
|
-
runDependencies--;
|
|
1846
|
-
|
|
1847
|
-
Module['monitorRunDependencies']?.(runDependencies);
|
|
1848
|
-
|
|
1849
|
-
assert(id, 'removeRunDependency requires an ID');
|
|
1850
|
-
assert(runDependencyTracking[id]);
|
|
1851
|
-
delete runDependencyTracking[id];
|
|
1852
|
-
if (runDependencies == 0) {
|
|
1853
|
-
if (runDependencyWatcher !== null) {
|
|
1854
|
-
clearInterval(runDependencyWatcher);
|
|
1855
|
-
runDependencyWatcher = null;
|
|
1856
|
-
}
|
|
1857
|
-
if (dependenciesFulfilled) {
|
|
1858
|
-
var callback = dependenciesFulfilled;
|
|
1859
|
-
dependenciesFulfilled = null;
|
|
1860
|
-
callback(); // can add another dependenciesFulfilled
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
var addRunDependency = (id) => {
|
|
1867
|
-
runDependencies++;
|
|
1868
|
-
|
|
1869
|
-
Module['monitorRunDependencies']?.(runDependencies);
|
|
1870
|
-
|
|
1871
|
-
assert(id, 'addRunDependency requires an ID')
|
|
1872
|
-
assert(!runDependencyTracking[id]);
|
|
1873
|
-
runDependencyTracking[id] = 1;
|
|
1874
|
-
if (runDependencyWatcher === null && globalThis.setInterval) {
|
|
1875
|
-
// Check for missing dependencies every few seconds
|
|
1876
|
-
runDependencyWatcher = setInterval(() => {
|
|
1877
|
-
if (ABORT) {
|
|
1878
|
-
clearInterval(runDependencyWatcher);
|
|
1879
|
-
runDependencyWatcher = null;
|
|
1880
|
-
return;
|
|
1881
|
-
}
|
|
1882
|
-
var shown = false;
|
|
1883
|
-
for (var dep in runDependencyTracking) {
|
|
1884
|
-
if (!shown) {
|
|
1885
|
-
shown = true;
|
|
1886
|
-
err('still waiting on run dependencies:');
|
|
1887
|
-
}
|
|
1888
|
-
err(`dependency: ${dep}`);
|
|
1889
|
-
}
|
|
1890
|
-
if (shown) {
|
|
1891
|
-
err('(end of list)');
|
|
1892
|
-
}
|
|
1893
|
-
}, 10000);
|
|
1894
|
-
// Prevent this timer from keeping the runtime alive if nothing
|
|
1895
|
-
// else is.
|
|
1896
|
-
runDependencyWatcher.unref?.()
|
|
1897
|
-
}
|
|
1898
|
-
};
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
var preloadPlugins = [];
|
|
1902
|
-
var FS_handledByPreloadPlugin = async (byteArray, fullname) => {
|
|
1903
|
-
// Ensure plugins are ready.
|
|
1904
|
-
if (typeof Browser != 'undefined') Browser.init();
|
|
1905
|
-
|
|
1906
|
-
for (var plugin of preloadPlugins) {
|
|
1907
|
-
if (plugin['canHandle'](fullname)) {
|
|
1908
|
-
assert(plugin['handle'].constructor.name === 'AsyncFunction', 'Filesystem plugin handlers must be async functions (See #24914)')
|
|
1909
|
-
return plugin['handle'](byteArray, fullname);
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
// In no plugin handled this file then return the original/unmodified
|
|
1913
|
-
// byteArray.
|
|
1914
|
-
return byteArray;
|
|
1915
|
-
};
|
|
1916
|
-
var FS_preloadFile = async (parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish) => {
|
|
1917
|
-
// TODO we should allow people to just pass in a complete filename instead
|
|
1918
|
-
// of parent and name being that we just join them anyways
|
|
1919
|
-
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
|
|
1920
|
-
var dep = getUniqueRunDependency(`cp ${fullname}`); // might have several active requests for the same fullname
|
|
1921
|
-
addRunDependency(dep);
|
|
1922
|
-
|
|
1923
|
-
try {
|
|
1924
|
-
var byteArray = url;
|
|
1925
|
-
if (typeof url == 'string') {
|
|
1926
|
-
byteArray = await asyncLoad(url);
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
byteArray = await FS_handledByPreloadPlugin(byteArray, fullname);
|
|
1930
|
-
preFinish?.();
|
|
1931
|
-
if (!dontCreateFile) {
|
|
1932
|
-
FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
|
|
1933
|
-
}
|
|
1934
|
-
} finally {
|
|
1935
|
-
removeRunDependency(dep);
|
|
1936
|
-
}
|
|
1937
|
-
};
|
|
1938
|
-
var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
|
|
1939
|
-
FS_preloadFile(parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish).then(onload).catch(onerror);
|
|
1940
|
-
};
|
|
1941
|
-
var FS = {
|
|
1942
|
-
root:null,
|
|
1943
|
-
mounts:[],
|
|
1944
|
-
devices:{
|
|
1945
|
-
},
|
|
1946
|
-
streams:[],
|
|
1947
|
-
nextInode:1,
|
|
1948
|
-
nameTable:null,
|
|
1949
|
-
currentPath:"/",
|
|
1950
|
-
initialized:false,
|
|
1951
|
-
ignorePermissions:true,
|
|
1952
|
-
filesystems:null,
|
|
1953
|
-
syncFSRequests:0,
|
|
1954
|
-
readFiles:{
|
|
1955
|
-
},
|
|
1956
|
-
ErrnoError:class extends Error {
|
|
1957
|
-
name = 'ErrnoError';
|
|
1958
|
-
// We set the `name` property to be able to identify `FS.ErrnoError`
|
|
1959
|
-
// - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
|
|
1960
|
-
// - when using PROXYFS, an error can come from an underlying FS
|
|
1961
|
-
// as different FS objects have their own FS.ErrnoError each,
|
|
1962
|
-
// the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
|
|
1963
|
-
// we'll use the reliable test `err.name == "ErrnoError"` instead
|
|
1964
|
-
constructor(errno) {
|
|
1965
|
-
super(runtimeInitialized ? strError(errno) : '');
|
|
1966
|
-
this.errno = errno;
|
|
1967
|
-
for (var key in ERRNO_CODES) {
|
|
1968
|
-
if (ERRNO_CODES[key] === errno) {
|
|
1969
|
-
this.code = key;
|
|
1970
|
-
break;
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
},
|
|
1975
|
-
FSStream:class {
|
|
1976
|
-
shared = {};
|
|
1977
|
-
get object() {
|
|
1978
|
-
return this.node;
|
|
1979
|
-
}
|
|
1980
|
-
set object(val) {
|
|
1981
|
-
this.node = val;
|
|
1982
|
-
}
|
|
1983
|
-
get isRead() {
|
|
1984
|
-
return (this.flags & 2097155) !== 1;
|
|
1985
|
-
}
|
|
1986
|
-
get isWrite() {
|
|
1987
|
-
return (this.flags & 2097155) !== 0;
|
|
1988
|
-
}
|
|
1989
|
-
get isAppend() {
|
|
1990
|
-
return (this.flags & 1024);
|
|
1991
|
-
}
|
|
1992
|
-
get flags() {
|
|
1993
|
-
return this.shared.flags;
|
|
1994
|
-
}
|
|
1995
|
-
set flags(val) {
|
|
1996
|
-
this.shared.flags = val;
|
|
1997
|
-
}
|
|
1998
|
-
get position() {
|
|
1999
|
-
return this.shared.position;
|
|
2000
|
-
}
|
|
2001
|
-
set position(val) {
|
|
2002
|
-
this.shared.position = val;
|
|
2003
|
-
}
|
|
2004
|
-
},
|
|
2005
|
-
FSNode:class {
|
|
2006
|
-
node_ops = {};
|
|
2007
|
-
stream_ops = {};
|
|
2008
|
-
readMode = 292 | 73;
|
|
2009
|
-
writeMode = 146;
|
|
2010
|
-
mounted = null;
|
|
2011
|
-
constructor(parent, name, mode, rdev) {
|
|
2012
|
-
if (!parent) {
|
|
2013
|
-
parent = this; // root node sets parent to itself
|
|
2014
|
-
}
|
|
2015
|
-
this.parent = parent;
|
|
2016
|
-
this.mount = parent.mount;
|
|
2017
|
-
this.id = FS.nextInode++;
|
|
2018
|
-
this.name = name;
|
|
2019
|
-
this.mode = mode;
|
|
2020
|
-
this.rdev = rdev;
|
|
2021
|
-
this.atime = this.mtime = this.ctime = Date.now();
|
|
2022
|
-
}
|
|
2023
|
-
get read() {
|
|
2024
|
-
return (this.mode & this.readMode) === this.readMode;
|
|
2025
|
-
}
|
|
2026
|
-
set read(val) {
|
|
2027
|
-
val ? this.mode |= this.readMode : this.mode &= ~this.readMode;
|
|
2028
|
-
}
|
|
2029
|
-
get write() {
|
|
2030
|
-
return (this.mode & this.writeMode) === this.writeMode;
|
|
2031
|
-
}
|
|
2032
|
-
set write(val) {
|
|
2033
|
-
val ? this.mode |= this.writeMode : this.mode &= ~this.writeMode;
|
|
2034
|
-
}
|
|
2035
|
-
get isFolder() {
|
|
2036
|
-
return FS.isDir(this.mode);
|
|
2037
|
-
}
|
|
2038
|
-
get isDevice() {
|
|
2039
|
-
return FS.isChrdev(this.mode);
|
|
2040
|
-
}
|
|
2041
|
-
},
|
|
2042
|
-
lookupPath(path, opts = {}) {
|
|
2043
|
-
if (!path) {
|
|
2044
|
-
throw new FS.ErrnoError(44);
|
|
2045
|
-
}
|
|
2046
|
-
opts.follow_mount ??= true
|
|
2047
|
-
|
|
2048
|
-
if (!PATH.isAbs(path)) {
|
|
2049
|
-
path = FS.cwd() + '/' + path;
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
// limit max consecutive symlinks to 40 (SYMLOOP_MAX).
|
|
2053
|
-
linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
|
|
2054
|
-
// split the absolute path
|
|
2055
|
-
var parts = path.split('/').filter((p) => !!p);
|
|
2056
|
-
|
|
2057
|
-
// start at the root
|
|
2058
|
-
var current = FS.root;
|
|
2059
|
-
var current_path = '/';
|
|
2060
|
-
|
|
2061
|
-
for (var i = 0; i < parts.length; i++) {
|
|
2062
|
-
var islast = (i === parts.length-1);
|
|
2063
|
-
if (islast && opts.parent) {
|
|
2064
|
-
// stop resolving
|
|
2065
|
-
break;
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
if (parts[i] === '.') {
|
|
2069
|
-
continue;
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
if (parts[i] === '..') {
|
|
2073
|
-
current_path = PATH.dirname(current_path);
|
|
2074
|
-
if (FS.isRoot(current)) {
|
|
2075
|
-
path = current_path + '/' + parts.slice(i + 1).join('/');
|
|
2076
|
-
// We're making progress here, don't let many consecutive ..'s
|
|
2077
|
-
// lead to ELOOP
|
|
2078
|
-
nlinks--;
|
|
2079
|
-
continue linkloop;
|
|
2080
|
-
} else {
|
|
2081
|
-
current = current.parent;
|
|
2082
|
-
}
|
|
2083
|
-
continue;
|
|
2084
|
-
}
|
|
2085
|
-
|
|
2086
|
-
current_path = PATH.join2(current_path, parts[i]);
|
|
2087
|
-
try {
|
|
2088
|
-
current = FS.lookupNode(current, parts[i]);
|
|
2089
|
-
} catch (e) {
|
|
2090
|
-
// if noent_okay is true, suppress a ENOENT in the last component
|
|
2091
|
-
// and return an object with an undefined node. This is needed for
|
|
2092
|
-
// resolving symlinks in the path when creating a file.
|
|
2093
|
-
if ((e?.errno === 44) && islast && opts.noent_okay) {
|
|
2094
|
-
return { path: current_path };
|
|
2095
|
-
}
|
|
2096
|
-
throw e;
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
// jump to the mount's root node if this is a mountpoint
|
|
2100
|
-
if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) {
|
|
2101
|
-
current = current.mounted.root;
|
|
2102
|
-
}
|
|
2103
|
-
|
|
2104
|
-
// by default, lookupPath will not follow a symlink if it is the final path component.
|
|
2105
|
-
// setting opts.follow = true will override this behavior.
|
|
2106
|
-
if (FS.isLink(current.mode) && (!islast || opts.follow)) {
|
|
2107
|
-
if (!current.node_ops.readlink) {
|
|
2108
|
-
throw new FS.ErrnoError(52);
|
|
2109
|
-
}
|
|
2110
|
-
var link = current.node_ops.readlink(current);
|
|
2111
|
-
if (!PATH.isAbs(link)) {
|
|
2112
|
-
link = PATH.dirname(current_path) + '/' + link;
|
|
2113
|
-
}
|
|
2114
|
-
path = link + '/' + parts.slice(i + 1).join('/');
|
|
2115
|
-
continue linkloop;
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
return { path: current_path, node: current };
|
|
2119
|
-
}
|
|
2120
|
-
throw new FS.ErrnoError(32);
|
|
2121
|
-
},
|
|
2122
|
-
getPath(node) {
|
|
2123
|
-
var path;
|
|
2124
|
-
while (true) {
|
|
2125
|
-
if (FS.isRoot(node)) {
|
|
2126
|
-
var mount = node.mount.mountpoint;
|
|
2127
|
-
if (!path) return mount;
|
|
2128
|
-
return mount[mount.length-1] !== '/' ? `${mount}/${path}` : mount + path;
|
|
2129
|
-
}
|
|
2130
|
-
path = path ? `${node.name}/${path}` : node.name;
|
|
2131
|
-
node = node.parent;
|
|
2132
|
-
}
|
|
2133
|
-
},
|
|
2134
|
-
hashName(parentid, name) {
|
|
2135
|
-
var hash = 0;
|
|
2136
|
-
|
|
2137
|
-
for (var i = 0; i < name.length; i++) {
|
|
2138
|
-
hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
|
|
2139
|
-
}
|
|
2140
|
-
return ((parentid + hash) >>> 0) % FS.nameTable.length;
|
|
2141
|
-
},
|
|
2142
|
-
hashAddNode(node) {
|
|
2143
|
-
var hash = FS.hashName(node.parent.id, node.name);
|
|
2144
|
-
node.name_next = FS.nameTable[hash];
|
|
2145
|
-
FS.nameTable[hash] = node;
|
|
2146
|
-
},
|
|
2147
|
-
hashRemoveNode(node) {
|
|
2148
|
-
var hash = FS.hashName(node.parent.id, node.name);
|
|
2149
|
-
if (FS.nameTable[hash] === node) {
|
|
2150
|
-
FS.nameTable[hash] = node.name_next;
|
|
2151
|
-
} else {
|
|
2152
|
-
var current = FS.nameTable[hash];
|
|
2153
|
-
while (current) {
|
|
2154
|
-
if (current.name_next === node) {
|
|
2155
|
-
current.name_next = node.name_next;
|
|
2156
|
-
break;
|
|
2157
|
-
}
|
|
2158
|
-
current = current.name_next;
|
|
2159
|
-
}
|
|
2160
|
-
}
|
|
2161
|
-
},
|
|
2162
|
-
lookupNode(parent, name) {
|
|
2163
|
-
var errCode = FS.mayLookup(parent);
|
|
2164
|
-
if (errCode) {
|
|
2165
|
-
throw new FS.ErrnoError(errCode);
|
|
2166
|
-
}
|
|
2167
|
-
var hash = FS.hashName(parent.id, name);
|
|
2168
|
-
for (var node = FS.nameTable[hash]; node; node = node.name_next) {
|
|
2169
|
-
var nodeName = node.name;
|
|
2170
|
-
if (node.parent.id === parent.id && nodeName === name) {
|
|
2171
|
-
return node;
|
|
2172
|
-
}
|
|
2173
|
-
}
|
|
2174
|
-
// if we failed to find it in the cache, call into the VFS
|
|
2175
|
-
return FS.lookup(parent, name);
|
|
2176
|
-
},
|
|
2177
|
-
createNode(parent, name, mode, rdev) {
|
|
2178
|
-
assert(typeof parent == 'object')
|
|
2179
|
-
var node = new FS.FSNode(parent, name, mode, rdev);
|
|
2180
|
-
|
|
2181
|
-
FS.hashAddNode(node);
|
|
2182
|
-
|
|
2183
|
-
return node;
|
|
2184
|
-
},
|
|
2185
|
-
destroyNode(node) {
|
|
2186
|
-
FS.hashRemoveNode(node);
|
|
2187
|
-
},
|
|
2188
|
-
isRoot(node) {
|
|
2189
|
-
return node === node.parent;
|
|
2190
|
-
},
|
|
2191
|
-
isMountpoint(node) {
|
|
2192
|
-
return !!node.mounted;
|
|
2193
|
-
},
|
|
2194
|
-
isFile(mode) {
|
|
2195
|
-
return (mode & 61440) === 32768;
|
|
2196
|
-
},
|
|
2197
|
-
isDir(mode) {
|
|
2198
|
-
return (mode & 61440) === 16384;
|
|
2199
|
-
},
|
|
2200
|
-
isLink(mode) {
|
|
2201
|
-
return (mode & 61440) === 40960;
|
|
2202
|
-
},
|
|
2203
|
-
isChrdev(mode) {
|
|
2204
|
-
return (mode & 61440) === 8192;
|
|
2205
|
-
},
|
|
2206
|
-
isBlkdev(mode) {
|
|
2207
|
-
return (mode & 61440) === 24576;
|
|
2208
|
-
},
|
|
2209
|
-
isFIFO(mode) {
|
|
2210
|
-
return (mode & 61440) === 4096;
|
|
2211
|
-
},
|
|
2212
|
-
isSocket(mode) {
|
|
2213
|
-
return (mode & 49152) === 49152;
|
|
2214
|
-
},
|
|
2215
|
-
flagsToPermissionString(flag) {
|
|
2216
|
-
var perms = ['r', 'w', 'rw'][flag & 3];
|
|
2217
|
-
if ((flag & 512)) {
|
|
2218
|
-
perms += 'w';
|
|
2219
|
-
}
|
|
2220
|
-
return perms;
|
|
2221
|
-
},
|
|
2222
|
-
nodePermissions(node, perms) {
|
|
2223
|
-
if (FS.ignorePermissions) {
|
|
2224
|
-
return 0;
|
|
2225
|
-
}
|
|
2226
|
-
// return 0 if any user, group or owner bits are set.
|
|
2227
|
-
if (perms.includes('r') && !(node.mode & 292)) {
|
|
2228
|
-
return 2;
|
|
2229
|
-
} else if (perms.includes('w') && !(node.mode & 146)) {
|
|
2230
|
-
return 2;
|
|
2231
|
-
} else if (perms.includes('x') && !(node.mode & 73)) {
|
|
2232
|
-
return 2;
|
|
2233
|
-
}
|
|
2234
|
-
return 0;
|
|
2235
|
-
},
|
|
2236
|
-
mayLookup(dir) {
|
|
2237
|
-
if (!FS.isDir(dir.mode)) return 54;
|
|
2238
|
-
var errCode = FS.nodePermissions(dir, 'x');
|
|
2239
|
-
if (errCode) return errCode;
|
|
2240
|
-
if (!dir.node_ops.lookup) return 2;
|
|
2241
|
-
return 0;
|
|
2242
|
-
},
|
|
2243
|
-
mayCreate(dir, name) {
|
|
2244
|
-
if (!FS.isDir(dir.mode)) {
|
|
2245
|
-
return 54;
|
|
2246
|
-
}
|
|
2247
|
-
try {
|
|
2248
|
-
var node = FS.lookupNode(dir, name);
|
|
2249
|
-
return 20;
|
|
2250
|
-
} catch (e) {
|
|
2251
|
-
}
|
|
2252
|
-
return FS.nodePermissions(dir, 'wx');
|
|
2253
|
-
},
|
|
2254
|
-
mayDelete(dir, name, isdir) {
|
|
2255
|
-
var node;
|
|
2256
|
-
try {
|
|
2257
|
-
node = FS.lookupNode(dir, name);
|
|
2258
|
-
} catch (e) {
|
|
2259
|
-
return e.errno;
|
|
2260
|
-
}
|
|
2261
|
-
var errCode = FS.nodePermissions(dir, 'wx');
|
|
2262
|
-
if (errCode) {
|
|
2263
|
-
return errCode;
|
|
2264
|
-
}
|
|
2265
|
-
if (isdir) {
|
|
2266
|
-
if (!FS.isDir(node.mode)) {
|
|
2267
|
-
return 54;
|
|
2268
|
-
}
|
|
2269
|
-
if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
|
|
2270
|
-
return 10;
|
|
2271
|
-
}
|
|
2272
|
-
} else {
|
|
2273
|
-
if (FS.isDir(node.mode)) {
|
|
2274
|
-
return 31;
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
return 0;
|
|
2278
|
-
},
|
|
2279
|
-
mayOpen(node, flags) {
|
|
2280
|
-
if (!node) {
|
|
2281
|
-
return 44;
|
|
2282
|
-
}
|
|
2283
|
-
if (FS.isLink(node.mode)) {
|
|
2284
|
-
return 32;
|
|
2285
|
-
} else if (FS.isDir(node.mode)) {
|
|
2286
|
-
if (FS.flagsToPermissionString(flags) !== 'r' // opening for write
|
|
2287
|
-
|| (flags & (512 | 64))) { // TODO: check for O_SEARCH? (== search for dir only)
|
|
2288
|
-
return 31;
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
return FS.nodePermissions(node, FS.flagsToPermissionString(flags));
|
|
2292
|
-
},
|
|
2293
|
-
checkOpExists(op, err) {
|
|
2294
|
-
if (!op) {
|
|
2295
|
-
throw new FS.ErrnoError(err);
|
|
2296
|
-
}
|
|
2297
|
-
return op;
|
|
2298
|
-
},
|
|
2299
|
-
MAX_OPEN_FDS:4096,
|
|
2300
|
-
nextfd() {
|
|
2301
|
-
for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) {
|
|
2302
|
-
if (!FS.streams[fd]) {
|
|
2303
|
-
return fd;
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
throw new FS.ErrnoError(33);
|
|
2307
|
-
},
|
|
2308
|
-
getStreamChecked(fd) {
|
|
2309
|
-
var stream = FS.getStream(fd);
|
|
2310
|
-
if (!stream) {
|
|
2311
|
-
throw new FS.ErrnoError(8);
|
|
2312
|
-
}
|
|
2313
|
-
return stream;
|
|
2314
|
-
},
|
|
2315
|
-
getStream:(fd) => FS.streams[fd],
|
|
2316
|
-
createStream(stream, fd = -1) {
|
|
2317
|
-
assert(fd >= -1);
|
|
2318
|
-
|
|
2319
|
-
// clone it, so we can return an instance of FSStream
|
|
2320
|
-
stream = Object.assign(new FS.FSStream(), stream);
|
|
2321
|
-
if (fd == -1) {
|
|
2322
|
-
fd = FS.nextfd();
|
|
2323
|
-
}
|
|
2324
|
-
stream.fd = fd;
|
|
2325
|
-
FS.streams[fd] = stream;
|
|
2326
|
-
return stream;
|
|
2327
|
-
},
|
|
2328
|
-
closeStream(fd) {
|
|
2329
|
-
FS.streams[fd] = null;
|
|
2330
|
-
},
|
|
2331
|
-
dupStream(origStream, fd = -1) {
|
|
2332
|
-
var stream = FS.createStream(origStream, fd);
|
|
2333
|
-
stream.stream_ops?.dup?.(stream);
|
|
2334
|
-
return stream;
|
|
2335
|
-
},
|
|
2336
|
-
doSetAttr(stream, node, attr) {
|
|
2337
|
-
var setattr = stream?.stream_ops.setattr;
|
|
2338
|
-
var arg = setattr ? stream : node;
|
|
2339
|
-
setattr ??= node.node_ops.setattr;
|
|
2340
|
-
FS.checkOpExists(setattr, 63)
|
|
2341
|
-
setattr(arg, attr);
|
|
2342
|
-
},
|
|
2343
|
-
chrdev_stream_ops:{
|
|
2344
|
-
open(stream) {
|
|
2345
|
-
var device = FS.getDevice(stream.node.rdev);
|
|
2346
|
-
// override node's stream ops with the device's
|
|
2347
|
-
stream.stream_ops = device.stream_ops;
|
|
2348
|
-
// forward the open call
|
|
2349
|
-
stream.stream_ops.open?.(stream);
|
|
2350
|
-
},
|
|
2351
|
-
llseek() {
|
|
2352
|
-
throw new FS.ErrnoError(70);
|
|
2353
|
-
},
|
|
2354
|
-
},
|
|
2355
|
-
major:(dev) => ((dev) >> 8),
|
|
2356
|
-
minor:(dev) => ((dev) & 0xff),
|
|
2357
|
-
makedev:(ma, mi) => ((ma) << 8 | (mi)),
|
|
2358
|
-
registerDevice(dev, ops) {
|
|
2359
|
-
FS.devices[dev] = { stream_ops: ops };
|
|
2360
|
-
},
|
|
2361
|
-
getDevice:(dev) => FS.devices[dev],
|
|
2362
|
-
getMounts(mount) {
|
|
2363
|
-
var mounts = [];
|
|
2364
|
-
var check = [mount];
|
|
2365
|
-
|
|
2366
|
-
while (check.length) {
|
|
2367
|
-
var m = check.pop();
|
|
2368
|
-
|
|
2369
|
-
mounts.push(m);
|
|
2370
|
-
|
|
2371
|
-
check.push(...m.mounts);
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
return mounts;
|
|
2375
|
-
},
|
|
2376
|
-
syncfs(populate, callback) {
|
|
2377
|
-
if (typeof populate == 'function') {
|
|
2378
|
-
callback = populate;
|
|
2379
|
-
populate = false;
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
FS.syncFSRequests++;
|
|
2383
|
-
|
|
2384
|
-
if (FS.syncFSRequests > 1) {
|
|
2385
|
-
err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
var mounts = FS.getMounts(FS.root.mount);
|
|
2389
|
-
var completed = 0;
|
|
2390
|
-
|
|
2391
|
-
function doCallback(errCode) {
|
|
2392
|
-
assert(FS.syncFSRequests > 0);
|
|
2393
|
-
FS.syncFSRequests--;
|
|
2394
|
-
return callback(errCode);
|
|
2395
|
-
}
|
|
2396
|
-
|
|
2397
|
-
function done(errCode) {
|
|
2398
|
-
if (errCode) {
|
|
2399
|
-
if (!done.errored) {
|
|
2400
|
-
done.errored = true;
|
|
2401
|
-
return doCallback(errCode);
|
|
2402
|
-
}
|
|
2403
|
-
return;
|
|
2404
|
-
}
|
|
2405
|
-
if (++completed >= mounts.length) {
|
|
2406
|
-
doCallback(null);
|
|
2407
|
-
}
|
|
2408
|
-
};
|
|
2409
|
-
|
|
2410
|
-
// sync all mounts
|
|
2411
|
-
for (var mount of mounts) {
|
|
2412
|
-
if (mount.type.syncfs) {
|
|
2413
|
-
mount.type.syncfs(mount, populate, done);
|
|
2414
|
-
} else {
|
|
2415
|
-
done(null);
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
},
|
|
2419
|
-
mount(type, opts, mountpoint) {
|
|
2420
|
-
if (typeof type == 'string') {
|
|
2421
|
-
// The filesystem was not included, and instead we have an error
|
|
2422
|
-
// message stored in the variable.
|
|
2423
|
-
throw type;
|
|
2424
|
-
}
|
|
2425
|
-
var root = mountpoint === '/';
|
|
2426
|
-
var pseudo = !mountpoint;
|
|
2427
|
-
var node;
|
|
2428
|
-
|
|
2429
|
-
if (root && FS.root) {
|
|
2430
|
-
throw new FS.ErrnoError(10);
|
|
2431
|
-
} else if (!root && !pseudo) {
|
|
2432
|
-
var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
|
|
2433
|
-
|
|
2434
|
-
mountpoint = lookup.path; // use the absolute path
|
|
2435
|
-
node = lookup.node;
|
|
2436
|
-
|
|
2437
|
-
if (FS.isMountpoint(node)) {
|
|
2438
|
-
throw new FS.ErrnoError(10);
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
if (!FS.isDir(node.mode)) {
|
|
2442
|
-
throw new FS.ErrnoError(54);
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
var mount = {
|
|
2447
|
-
type,
|
|
2448
|
-
opts,
|
|
2449
|
-
mountpoint,
|
|
2450
|
-
mounts: []
|
|
2451
|
-
};
|
|
2452
|
-
|
|
2453
|
-
// create a root node for the fs
|
|
2454
|
-
var mountRoot = type.mount(mount);
|
|
2455
|
-
mountRoot.mount = mount;
|
|
2456
|
-
mount.root = mountRoot;
|
|
2457
|
-
|
|
2458
|
-
if (root) {
|
|
2459
|
-
FS.root = mountRoot;
|
|
2460
|
-
} else if (node) {
|
|
2461
|
-
// set as a mountpoint
|
|
2462
|
-
node.mounted = mount;
|
|
2463
|
-
|
|
2464
|
-
// add the new mount to the current mount's children
|
|
2465
|
-
if (node.mount) {
|
|
2466
|
-
node.mount.mounts.push(mount);
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
|
|
2470
|
-
return mountRoot;
|
|
2471
|
-
},
|
|
2472
|
-
unmount(mountpoint) {
|
|
2473
|
-
var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
|
|
2474
|
-
|
|
2475
|
-
if (!FS.isMountpoint(lookup.node)) {
|
|
2476
|
-
throw new FS.ErrnoError(28);
|
|
2477
|
-
}
|
|
2478
|
-
|
|
2479
|
-
// destroy the nodes for this mount, and all its child mounts
|
|
2480
|
-
var node = lookup.node;
|
|
2481
|
-
var mount = node.mounted;
|
|
2482
|
-
var mounts = FS.getMounts(mount);
|
|
2483
|
-
|
|
2484
|
-
for (var [hash, current] of Object.entries(FS.nameTable)) {
|
|
2485
|
-
while (current) {
|
|
2486
|
-
var next = current.name_next;
|
|
2487
|
-
|
|
2488
|
-
if (mounts.includes(current.mount)) {
|
|
2489
|
-
FS.destroyNode(current);
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
current = next;
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
|
|
2496
|
-
// no longer a mountpoint
|
|
2497
|
-
node.mounted = null;
|
|
2498
|
-
|
|
2499
|
-
// remove this mount from the child mounts
|
|
2500
|
-
var idx = node.mount.mounts.indexOf(mount);
|
|
2501
|
-
assert(idx !== -1);
|
|
2502
|
-
node.mount.mounts.splice(idx, 1);
|
|
2503
|
-
},
|
|
2504
|
-
lookup(parent, name) {
|
|
2505
|
-
return parent.node_ops.lookup(parent, name);
|
|
2506
|
-
},
|
|
2507
|
-
mknod(path, mode, dev) {
|
|
2508
|
-
var lookup = FS.lookupPath(path, { parent: true });
|
|
2509
|
-
var parent = lookup.node;
|
|
2510
|
-
var name = PATH.basename(path);
|
|
2511
|
-
if (!name) {
|
|
2512
|
-
throw new FS.ErrnoError(28);
|
|
2513
|
-
}
|
|
2514
|
-
if (name === '.' || name === '..') {
|
|
2515
|
-
throw new FS.ErrnoError(20);
|
|
2516
|
-
}
|
|
2517
|
-
var errCode = FS.mayCreate(parent, name);
|
|
2518
|
-
if (errCode) {
|
|
2519
|
-
throw new FS.ErrnoError(errCode);
|
|
2520
|
-
}
|
|
2521
|
-
if (!parent.node_ops.mknod) {
|
|
2522
|
-
throw new FS.ErrnoError(63);
|
|
2523
|
-
}
|
|
2524
|
-
return parent.node_ops.mknod(parent, name, mode, dev);
|
|
2525
|
-
},
|
|
2526
|
-
statfs(path) {
|
|
2527
|
-
return FS.statfsNode(FS.lookupPath(path, {follow: true}).node);
|
|
2528
|
-
},
|
|
2529
|
-
statfsStream(stream) {
|
|
2530
|
-
// We keep a separate statfsStream function because noderawfs overrides
|
|
2531
|
-
// it. In noderawfs, stream.node is sometimes null. Instead, we need to
|
|
2532
|
-
// look at stream.path.
|
|
2533
|
-
return FS.statfsNode(stream.node);
|
|
2534
|
-
},
|
|
2535
|
-
statfsNode(node) {
|
|
2536
|
-
// NOTE: None of the defaults here are true. We're just returning safe and
|
|
2537
|
-
// sane values. Currently nodefs and rawfs replace these defaults,
|
|
2538
|
-
// other file systems leave them alone.
|
|
2539
|
-
var rtn = {
|
|
2540
|
-
bsize: 4096,
|
|
2541
|
-
frsize: 4096,
|
|
2542
|
-
blocks: 1e6,
|
|
2543
|
-
bfree: 5e5,
|
|
2544
|
-
bavail: 5e5,
|
|
2545
|
-
files: FS.nextInode,
|
|
2546
|
-
ffree: FS.nextInode - 1,
|
|
2547
|
-
fsid: 42,
|
|
2548
|
-
flags: 2,
|
|
2549
|
-
namelen: 255,
|
|
2550
|
-
};
|
|
2551
|
-
|
|
2552
|
-
if (node.node_ops.statfs) {
|
|
2553
|
-
Object.assign(rtn, node.node_ops.statfs(node.mount.opts.root));
|
|
2554
|
-
}
|
|
2555
|
-
return rtn;
|
|
2556
|
-
},
|
|
2557
|
-
create(path, mode = 0o666) {
|
|
2558
|
-
mode &= 4095;
|
|
2559
|
-
mode |= 32768;
|
|
2560
|
-
return FS.mknod(path, mode, 0);
|
|
2561
|
-
},
|
|
2562
|
-
mkdir(path, mode = 0o777) {
|
|
2563
|
-
mode &= 511 | 512;
|
|
2564
|
-
mode |= 16384;
|
|
2565
|
-
return FS.mknod(path, mode, 0);
|
|
2566
|
-
},
|
|
2567
|
-
mkdirTree(path, mode) {
|
|
2568
|
-
var dirs = path.split('/');
|
|
2569
|
-
var d = '';
|
|
2570
|
-
for (var dir of dirs) {
|
|
2571
|
-
if (!dir) continue;
|
|
2572
|
-
if (d || PATH.isAbs(path)) d += '/';
|
|
2573
|
-
d += dir;
|
|
2574
|
-
try {
|
|
2575
|
-
FS.mkdir(d, mode);
|
|
2576
|
-
} catch(e) {
|
|
2577
|
-
if (e.errno != 20) throw e;
|
|
2578
|
-
}
|
|
2579
|
-
}
|
|
2580
|
-
},
|
|
2581
|
-
mkdev(path, mode, dev) {
|
|
2582
|
-
if (typeof dev == 'undefined') {
|
|
2583
|
-
dev = mode;
|
|
2584
|
-
mode = 0o666;
|
|
2585
|
-
}
|
|
2586
|
-
mode |= 8192;
|
|
2587
|
-
return FS.mknod(path, mode, dev);
|
|
2588
|
-
},
|
|
2589
|
-
symlink(oldpath, newpath) {
|
|
2590
|
-
if (!PATH_FS.resolve(oldpath)) {
|
|
2591
|
-
throw new FS.ErrnoError(44);
|
|
2592
|
-
}
|
|
2593
|
-
var lookup = FS.lookupPath(newpath, { parent: true });
|
|
2594
|
-
var parent = lookup.node;
|
|
2595
|
-
if (!parent) {
|
|
2596
|
-
throw new FS.ErrnoError(44);
|
|
2597
|
-
}
|
|
2598
|
-
var newname = PATH.basename(newpath);
|
|
2599
|
-
var errCode = FS.mayCreate(parent, newname);
|
|
2600
|
-
if (errCode) {
|
|
2601
|
-
throw new FS.ErrnoError(errCode);
|
|
2602
|
-
}
|
|
2603
|
-
if (!parent.node_ops.symlink) {
|
|
2604
|
-
throw new FS.ErrnoError(63);
|
|
2605
|
-
}
|
|
2606
|
-
return parent.node_ops.symlink(parent, newname, oldpath);
|
|
2607
|
-
},
|
|
2608
|
-
rename(old_path, new_path) {
|
|
2609
|
-
var old_dirname = PATH.dirname(old_path);
|
|
2610
|
-
var new_dirname = PATH.dirname(new_path);
|
|
2611
|
-
var old_name = PATH.basename(old_path);
|
|
2612
|
-
var new_name = PATH.basename(new_path);
|
|
2613
|
-
// parents must exist
|
|
2614
|
-
var lookup, old_dir, new_dir;
|
|
2615
|
-
|
|
2616
|
-
// let the errors from non existent directories percolate up
|
|
2617
|
-
lookup = FS.lookupPath(old_path, { parent: true });
|
|
2618
|
-
old_dir = lookup.node;
|
|
2619
|
-
lookup = FS.lookupPath(new_path, { parent: true });
|
|
2620
|
-
new_dir = lookup.node;
|
|
2621
|
-
|
|
2622
|
-
if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
|
|
2623
|
-
// need to be part of the same mount
|
|
2624
|
-
if (old_dir.mount !== new_dir.mount) {
|
|
2625
|
-
throw new FS.ErrnoError(75);
|
|
2626
|
-
}
|
|
2627
|
-
// source must exist
|
|
2628
|
-
var old_node = FS.lookupNode(old_dir, old_name);
|
|
2629
|
-
// old path should not be an ancestor of the new path
|
|
2630
|
-
var relative = PATH_FS.relative(old_path, new_dirname);
|
|
2631
|
-
if (relative.charAt(0) !== '.') {
|
|
2632
|
-
throw new FS.ErrnoError(28);
|
|
2633
|
-
}
|
|
2634
|
-
// new path should not be an ancestor of the old path
|
|
2635
|
-
relative = PATH_FS.relative(new_path, old_dirname);
|
|
2636
|
-
if (relative.charAt(0) !== '.') {
|
|
2637
|
-
throw new FS.ErrnoError(55);
|
|
2638
|
-
}
|
|
2639
|
-
// see if the new path already exists
|
|
2640
|
-
var new_node;
|
|
2641
|
-
try {
|
|
2642
|
-
new_node = FS.lookupNode(new_dir, new_name);
|
|
2643
|
-
} catch (e) {
|
|
2644
|
-
// not fatal
|
|
2645
|
-
}
|
|
2646
|
-
// early out if nothing needs to change
|
|
2647
|
-
if (old_node === new_node) {
|
|
2648
|
-
return;
|
|
2649
|
-
}
|
|
2650
|
-
// we'll need to delete the old entry
|
|
2651
|
-
var isdir = FS.isDir(old_node.mode);
|
|
2652
|
-
var errCode = FS.mayDelete(old_dir, old_name, isdir);
|
|
2653
|
-
if (errCode) {
|
|
2654
|
-
throw new FS.ErrnoError(errCode);
|
|
2655
|
-
}
|
|
2656
|
-
// need delete permissions if we'll be overwriting.
|
|
2657
|
-
// need create permissions if new doesn't already exist.
|
|
2658
|
-
errCode = new_node ?
|
|
2659
|
-
FS.mayDelete(new_dir, new_name, isdir) :
|
|
2660
|
-
FS.mayCreate(new_dir, new_name);
|
|
2661
|
-
if (errCode) {
|
|
2662
|
-
throw new FS.ErrnoError(errCode);
|
|
2663
|
-
}
|
|
2664
|
-
if (!old_dir.node_ops.rename) {
|
|
2665
|
-
throw new FS.ErrnoError(63);
|
|
2666
|
-
}
|
|
2667
|
-
if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
|
|
2668
|
-
throw new FS.ErrnoError(10);
|
|
2669
|
-
}
|
|
2670
|
-
// if we are going to change the parent, check write permissions
|
|
2671
|
-
if (new_dir !== old_dir) {
|
|
2672
|
-
errCode = FS.nodePermissions(old_dir, 'w');
|
|
2673
|
-
if (errCode) {
|
|
2674
|
-
throw new FS.ErrnoError(errCode);
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
// remove the node from the lookup hash
|
|
2678
|
-
FS.hashRemoveNode(old_node);
|
|
2679
|
-
// do the underlying fs rename
|
|
2680
|
-
try {
|
|
2681
|
-
old_dir.node_ops.rename(old_node, new_dir, new_name);
|
|
2682
|
-
// update old node (we do this here to avoid each backend
|
|
2683
|
-
// needing to)
|
|
2684
|
-
old_node.parent = new_dir;
|
|
2685
|
-
} catch (e) {
|
|
2686
|
-
throw e;
|
|
2687
|
-
} finally {
|
|
2688
|
-
// add the node back to the hash (in case node_ops.rename
|
|
2689
|
-
// changed its name)
|
|
2690
|
-
FS.hashAddNode(old_node);
|
|
2691
|
-
}
|
|
2692
|
-
},
|
|
2693
|
-
rmdir(path) {
|
|
2694
|
-
var lookup = FS.lookupPath(path, { parent: true });
|
|
2695
|
-
var parent = lookup.node;
|
|
2696
|
-
var name = PATH.basename(path);
|
|
2697
|
-
var node = FS.lookupNode(parent, name);
|
|
2698
|
-
var errCode = FS.mayDelete(parent, name, true);
|
|
2699
|
-
if (errCode) {
|
|
2700
|
-
throw new FS.ErrnoError(errCode);
|
|
2701
|
-
}
|
|
2702
|
-
if (!parent.node_ops.rmdir) {
|
|
2703
|
-
throw new FS.ErrnoError(63);
|
|
2704
|
-
}
|
|
2705
|
-
if (FS.isMountpoint(node)) {
|
|
2706
|
-
throw new FS.ErrnoError(10);
|
|
2707
|
-
}
|
|
2708
|
-
parent.node_ops.rmdir(parent, name);
|
|
2709
|
-
FS.destroyNode(node);
|
|
2710
|
-
},
|
|
2711
|
-
readdir(path) {
|
|
2712
|
-
var lookup = FS.lookupPath(path, { follow: true });
|
|
2713
|
-
var node = lookup.node;
|
|
2714
|
-
var readdir = FS.checkOpExists(node.node_ops.readdir, 54);
|
|
2715
|
-
return readdir(node);
|
|
2716
|
-
},
|
|
2717
|
-
unlink(path) {
|
|
2718
|
-
var lookup = FS.lookupPath(path, { parent: true });
|
|
2719
|
-
var parent = lookup.node;
|
|
2720
|
-
if (!parent) {
|
|
2721
|
-
throw new FS.ErrnoError(44);
|
|
2722
|
-
}
|
|
2723
|
-
var name = PATH.basename(path);
|
|
2724
|
-
var node = FS.lookupNode(parent, name);
|
|
2725
|
-
var errCode = FS.mayDelete(parent, name, false);
|
|
2726
|
-
if (errCode) {
|
|
2727
|
-
// According to POSIX, we should map EISDIR to EPERM, but
|
|
2728
|
-
// we instead do what Linux does (and we must, as we use
|
|
2729
|
-
// the musl linux libc).
|
|
2730
|
-
throw new FS.ErrnoError(errCode);
|
|
2731
|
-
}
|
|
2732
|
-
if (!parent.node_ops.unlink) {
|
|
2733
|
-
throw new FS.ErrnoError(63);
|
|
2734
|
-
}
|
|
2735
|
-
if (FS.isMountpoint(node)) {
|
|
2736
|
-
throw new FS.ErrnoError(10);
|
|
2737
|
-
}
|
|
2738
|
-
parent.node_ops.unlink(parent, name);
|
|
2739
|
-
FS.destroyNode(node);
|
|
2740
|
-
},
|
|
2741
|
-
readlink(path) {
|
|
2742
|
-
var lookup = FS.lookupPath(path);
|
|
2743
|
-
var link = lookup.node;
|
|
2744
|
-
if (!link) {
|
|
2745
|
-
throw new FS.ErrnoError(44);
|
|
2746
|
-
}
|
|
2747
|
-
if (!link.node_ops.readlink) {
|
|
2748
|
-
throw new FS.ErrnoError(28);
|
|
2749
|
-
}
|
|
2750
|
-
return link.node_ops.readlink(link);
|
|
2751
|
-
},
|
|
2752
|
-
stat(path, dontFollow) {
|
|
2753
|
-
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
|
2754
|
-
var node = lookup.node;
|
|
2755
|
-
var getattr = FS.checkOpExists(node.node_ops.getattr, 63);
|
|
2756
|
-
return getattr(node);
|
|
2757
|
-
},
|
|
2758
|
-
fstat(fd) {
|
|
2759
|
-
var stream = FS.getStreamChecked(fd);
|
|
2760
|
-
var node = stream.node;
|
|
2761
|
-
var getattr = stream.stream_ops.getattr;
|
|
2762
|
-
var arg = getattr ? stream : node;
|
|
2763
|
-
getattr ??= node.node_ops.getattr;
|
|
2764
|
-
FS.checkOpExists(getattr, 63)
|
|
2765
|
-
return getattr(arg);
|
|
2766
|
-
},
|
|
2767
|
-
lstat(path) {
|
|
2768
|
-
return FS.stat(path, true);
|
|
2769
|
-
},
|
|
2770
|
-
doChmod(stream, node, mode, dontFollow) {
|
|
2771
|
-
FS.doSetAttr(stream, node, {
|
|
2772
|
-
mode: (mode & 4095) | (node.mode & ~4095),
|
|
2773
|
-
ctime: Date.now(),
|
|
2774
|
-
dontFollow
|
|
2775
|
-
});
|
|
2776
|
-
},
|
|
2777
|
-
chmod(path, mode, dontFollow) {
|
|
2778
|
-
var node;
|
|
2779
|
-
if (typeof path == 'string') {
|
|
2780
|
-
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
|
2781
|
-
node = lookup.node;
|
|
2782
|
-
} else {
|
|
2783
|
-
node = path;
|
|
2784
|
-
}
|
|
2785
|
-
FS.doChmod(null, node, mode, dontFollow);
|
|
2786
|
-
},
|
|
2787
|
-
lchmod(path, mode) {
|
|
2788
|
-
FS.chmod(path, mode, true);
|
|
2789
|
-
},
|
|
2790
|
-
fchmod(fd, mode) {
|
|
2791
|
-
var stream = FS.getStreamChecked(fd);
|
|
2792
|
-
FS.doChmod(stream, stream.node, mode, false);
|
|
2793
|
-
},
|
|
2794
|
-
doChown(stream, node, dontFollow) {
|
|
2795
|
-
FS.doSetAttr(stream, node, {
|
|
2796
|
-
timestamp: Date.now(),
|
|
2797
|
-
dontFollow
|
|
2798
|
-
// we ignore the uid / gid for now
|
|
2799
|
-
});
|
|
2800
|
-
},
|
|
2801
|
-
chown(path, uid, gid, dontFollow) {
|
|
2802
|
-
var node;
|
|
2803
|
-
if (typeof path == 'string') {
|
|
2804
|
-
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
|
2805
|
-
node = lookup.node;
|
|
2806
|
-
} else {
|
|
2807
|
-
node = path;
|
|
2808
|
-
}
|
|
2809
|
-
FS.doChown(null, node, dontFollow);
|
|
2810
|
-
},
|
|
2811
|
-
lchown(path, uid, gid) {
|
|
2812
|
-
FS.chown(path, uid, gid, true);
|
|
2813
|
-
},
|
|
2814
|
-
fchown(fd, uid, gid) {
|
|
2815
|
-
var stream = FS.getStreamChecked(fd);
|
|
2816
|
-
FS.doChown(stream, stream.node, false);
|
|
2817
|
-
},
|
|
2818
|
-
doTruncate(stream, node, len) {
|
|
2819
|
-
if (FS.isDir(node.mode)) {
|
|
2820
|
-
throw new FS.ErrnoError(31);
|
|
2821
|
-
}
|
|
2822
|
-
if (!FS.isFile(node.mode)) {
|
|
2823
|
-
throw new FS.ErrnoError(28);
|
|
2824
|
-
}
|
|
2825
|
-
var errCode = FS.nodePermissions(node, 'w');
|
|
2826
|
-
if (errCode) {
|
|
2827
|
-
throw new FS.ErrnoError(errCode);
|
|
2828
|
-
}
|
|
2829
|
-
FS.doSetAttr(stream, node, {
|
|
2830
|
-
size: len,
|
|
2831
|
-
timestamp: Date.now()
|
|
2832
|
-
});
|
|
2833
|
-
},
|
|
2834
|
-
truncate(path, len) {
|
|
2835
|
-
if (len < 0) {
|
|
2836
|
-
throw new FS.ErrnoError(28);
|
|
2837
|
-
}
|
|
2838
|
-
var node;
|
|
2839
|
-
if (typeof path == 'string') {
|
|
2840
|
-
var lookup = FS.lookupPath(path, { follow: true });
|
|
2841
|
-
node = lookup.node;
|
|
2842
|
-
} else {
|
|
2843
|
-
node = path;
|
|
2844
|
-
}
|
|
2845
|
-
FS.doTruncate(null, node, len);
|
|
2846
|
-
},
|
|
2847
|
-
ftruncate(fd, len) {
|
|
2848
|
-
var stream = FS.getStreamChecked(fd);
|
|
2849
|
-
if (len < 0 || (stream.flags & 2097155) === 0) {
|
|
2850
|
-
throw new FS.ErrnoError(28);
|
|
2851
|
-
}
|
|
2852
|
-
FS.doTruncate(stream, stream.node, len);
|
|
2853
|
-
},
|
|
2854
|
-
utime(path, atime, mtime) {
|
|
2855
|
-
var lookup = FS.lookupPath(path, { follow: true });
|
|
2856
|
-
var node = lookup.node;
|
|
2857
|
-
var setattr = FS.checkOpExists(node.node_ops.setattr, 63);
|
|
2858
|
-
setattr(node, {
|
|
2859
|
-
atime: atime,
|
|
2860
|
-
mtime: mtime
|
|
2861
|
-
});
|
|
2862
|
-
},
|
|
2863
|
-
open(path, flags, mode = 0o666) {
|
|
2864
|
-
if (path === "") {
|
|
2865
|
-
throw new FS.ErrnoError(44);
|
|
2866
|
-
}
|
|
2867
|
-
flags = typeof flags == 'string' ? FS_modeStringToFlags(flags) : flags;
|
|
2868
|
-
if ((flags & 64)) {
|
|
2869
|
-
mode = (mode & 4095) | 32768;
|
|
2870
|
-
} else {
|
|
2871
|
-
mode = 0;
|
|
2872
|
-
}
|
|
2873
|
-
var node;
|
|
2874
|
-
var isDirPath;
|
|
2875
|
-
if (typeof path == 'object') {
|
|
2876
|
-
node = path;
|
|
2877
|
-
} else {
|
|
2878
|
-
isDirPath = path.endsWith("/");
|
|
2879
|
-
// noent_okay makes it so that if the final component of the path
|
|
2880
|
-
// doesn't exist, lookupPath returns `node: undefined`. `path` will be
|
|
2881
|
-
// updated to point to the target of all symlinks.
|
|
2882
|
-
var lookup = FS.lookupPath(path, {
|
|
2883
|
-
follow: !(flags & 131072),
|
|
2884
|
-
noent_okay: true
|
|
2885
|
-
});
|
|
2886
|
-
node = lookup.node;
|
|
2887
|
-
path = lookup.path;
|
|
2888
|
-
}
|
|
2889
|
-
// perhaps we need to create the node
|
|
2890
|
-
var created = false;
|
|
2891
|
-
if ((flags & 64)) {
|
|
2892
|
-
if (node) {
|
|
2893
|
-
// if O_CREAT and O_EXCL are set, error out if the node already exists
|
|
2894
|
-
if ((flags & 128)) {
|
|
2895
|
-
throw new FS.ErrnoError(20);
|
|
2896
|
-
}
|
|
2897
|
-
} else if (isDirPath) {
|
|
2898
|
-
throw new FS.ErrnoError(31);
|
|
2899
|
-
} else {
|
|
2900
|
-
// node doesn't exist, try to create it
|
|
2901
|
-
// Ignore the permission bits here to ensure we can `open` this new
|
|
2902
|
-
// file below. We use chmod below the apply the permissions once the
|
|
2903
|
-
// file is open.
|
|
2904
|
-
node = FS.mknod(path, mode | 0o777, 0);
|
|
2905
|
-
created = true;
|
|
2906
|
-
}
|
|
2907
|
-
}
|
|
2908
|
-
if (!node) {
|
|
2909
|
-
throw new FS.ErrnoError(44);
|
|
2910
|
-
}
|
|
2911
|
-
// can't truncate a device
|
|
2912
|
-
if (FS.isChrdev(node.mode)) {
|
|
2913
|
-
flags &= ~512;
|
|
2914
|
-
}
|
|
2915
|
-
// if asked only for a directory, then this must be one
|
|
2916
|
-
if ((flags & 65536) && !FS.isDir(node.mode)) {
|
|
2917
|
-
throw new FS.ErrnoError(54);
|
|
2918
|
-
}
|
|
2919
|
-
// check permissions, if this is not a file we just created now (it is ok to
|
|
2920
|
-
// create and write to a file with read-only permissions; it is read-only
|
|
2921
|
-
// for later use)
|
|
2922
|
-
if (!created) {
|
|
2923
|
-
var errCode = FS.mayOpen(node, flags);
|
|
2924
|
-
if (errCode) {
|
|
2925
|
-
throw new FS.ErrnoError(errCode);
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
// do truncation if necessary
|
|
2929
|
-
if ((flags & 512) && !created) {
|
|
2930
|
-
FS.truncate(node, 0);
|
|
2931
|
-
}
|
|
2932
|
-
// we've already handled these, don't pass down to the underlying vfs
|
|
2933
|
-
flags &= ~(128 | 512 | 131072);
|
|
2934
|
-
|
|
2935
|
-
// register the stream with the filesystem
|
|
2936
|
-
var stream = FS.createStream({
|
|
2937
|
-
node,
|
|
2938
|
-
path: FS.getPath(node), // we want the absolute path to the node
|
|
2939
|
-
flags,
|
|
2940
|
-
seekable: true,
|
|
2941
|
-
position: 0,
|
|
2942
|
-
stream_ops: node.stream_ops,
|
|
2943
|
-
// used by the file family libc calls (fopen, fwrite, ferror, etc.)
|
|
2944
|
-
ungotten: [],
|
|
2945
|
-
error: false
|
|
2946
|
-
});
|
|
2947
|
-
// call the new stream's open function
|
|
2948
|
-
if (stream.stream_ops.open) {
|
|
2949
|
-
stream.stream_ops.open(stream);
|
|
2950
|
-
}
|
|
2951
|
-
if (created) {
|
|
2952
|
-
FS.chmod(node, mode & 0o777);
|
|
2953
|
-
}
|
|
2954
|
-
if (Module['logReadFiles'] && !(flags & 1)) {
|
|
2955
|
-
if (!(path in FS.readFiles)) {
|
|
2956
|
-
FS.readFiles[path] = 1;
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
return stream;
|
|
2960
|
-
},
|
|
2961
|
-
close(stream) {
|
|
2962
|
-
if (FS.isClosed(stream)) {
|
|
2963
|
-
throw new FS.ErrnoError(8);
|
|
2964
|
-
}
|
|
2965
|
-
if (stream.getdents) stream.getdents = null; // free readdir state
|
|
2966
|
-
try {
|
|
2967
|
-
if (stream.stream_ops.close) {
|
|
2968
|
-
stream.stream_ops.close(stream);
|
|
2969
|
-
}
|
|
2970
|
-
} catch (e) {
|
|
2971
|
-
throw e;
|
|
2972
|
-
} finally {
|
|
2973
|
-
FS.closeStream(stream.fd);
|
|
2974
|
-
}
|
|
2975
|
-
stream.fd = null;
|
|
2976
|
-
},
|
|
2977
|
-
isClosed(stream) {
|
|
2978
|
-
return stream.fd === null;
|
|
2979
|
-
},
|
|
2980
|
-
llseek(stream, offset, whence) {
|
|
2981
|
-
if (FS.isClosed(stream)) {
|
|
2982
|
-
throw new FS.ErrnoError(8);
|
|
2983
|
-
}
|
|
2984
|
-
if (!stream.seekable || !stream.stream_ops.llseek) {
|
|
2985
|
-
throw new FS.ErrnoError(70);
|
|
2986
|
-
}
|
|
2987
|
-
if (whence != 0 && whence != 1 && whence != 2) {
|
|
2988
|
-
throw new FS.ErrnoError(28);
|
|
2989
|
-
}
|
|
2990
|
-
stream.position = stream.stream_ops.llseek(stream, offset, whence);
|
|
2991
|
-
stream.ungotten = [];
|
|
2992
|
-
return stream.position;
|
|
2993
|
-
},
|
|
2994
|
-
read(stream, buffer, offset, length, position) {
|
|
2995
|
-
assert(offset >= 0);
|
|
2996
|
-
if (length < 0 || position < 0) {
|
|
2997
|
-
throw new FS.ErrnoError(28);
|
|
2998
|
-
}
|
|
2999
|
-
if (FS.isClosed(stream)) {
|
|
3000
|
-
throw new FS.ErrnoError(8);
|
|
3001
|
-
}
|
|
3002
|
-
if ((stream.flags & 2097155) === 1) {
|
|
3003
|
-
throw new FS.ErrnoError(8);
|
|
3004
|
-
}
|
|
3005
|
-
if (FS.isDir(stream.node.mode)) {
|
|
3006
|
-
throw new FS.ErrnoError(31);
|
|
3007
|
-
}
|
|
3008
|
-
if (!stream.stream_ops.read) {
|
|
3009
|
-
throw new FS.ErrnoError(28);
|
|
3010
|
-
}
|
|
3011
|
-
var seeking = typeof position != 'undefined';
|
|
3012
|
-
if (!seeking) {
|
|
3013
|
-
position = stream.position;
|
|
3014
|
-
} else if (!stream.seekable) {
|
|
3015
|
-
throw new FS.ErrnoError(70);
|
|
3016
|
-
}
|
|
3017
|
-
var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
|
|
3018
|
-
if (!seeking) stream.position += bytesRead;
|
|
3019
|
-
return bytesRead;
|
|
3020
|
-
},
|
|
3021
|
-
write(stream, buffer, offset, length, position, canOwn) {
|
|
3022
|
-
assert(offset >= 0);
|
|
3023
|
-
if (length < 0 || position < 0) {
|
|
3024
|
-
throw new FS.ErrnoError(28);
|
|
3025
|
-
}
|
|
3026
|
-
if (FS.isClosed(stream)) {
|
|
3027
|
-
throw new FS.ErrnoError(8);
|
|
3028
|
-
}
|
|
3029
|
-
if ((stream.flags & 2097155) === 0) {
|
|
3030
|
-
throw new FS.ErrnoError(8);
|
|
3031
|
-
}
|
|
3032
|
-
if (FS.isDir(stream.node.mode)) {
|
|
3033
|
-
throw new FS.ErrnoError(31);
|
|
3034
|
-
}
|
|
3035
|
-
if (!stream.stream_ops.write) {
|
|
3036
|
-
throw new FS.ErrnoError(28);
|
|
3037
|
-
}
|
|
3038
|
-
if (stream.seekable && stream.flags & 1024) {
|
|
3039
|
-
// seek to the end before writing in append mode
|
|
3040
|
-
FS.llseek(stream, 0, 2);
|
|
3041
|
-
}
|
|
3042
|
-
var seeking = typeof position != 'undefined';
|
|
3043
|
-
if (!seeking) {
|
|
3044
|
-
position = stream.position;
|
|
3045
|
-
} else if (!stream.seekable) {
|
|
3046
|
-
throw new FS.ErrnoError(70);
|
|
3047
|
-
}
|
|
3048
|
-
var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
|
|
3049
|
-
if (!seeking) stream.position += bytesWritten;
|
|
3050
|
-
return bytesWritten;
|
|
3051
|
-
},
|
|
3052
|
-
mmap(stream, length, position, prot, flags) {
|
|
3053
|
-
// User requests writing to file (prot & PROT_WRITE != 0).
|
|
3054
|
-
// Checking if we have permissions to write to the file unless
|
|
3055
|
-
// MAP_PRIVATE flag is set. According to POSIX spec it is possible
|
|
3056
|
-
// to write to file opened in read-only mode with MAP_PRIVATE flag,
|
|
3057
|
-
// as all modifications will be visible only in the memory of
|
|
3058
|
-
// the current process.
|
|
3059
|
-
if ((prot & 2) !== 0
|
|
3060
|
-
&& (flags & 2) === 0
|
|
3061
|
-
&& (stream.flags & 2097155) !== 2) {
|
|
3062
|
-
throw new FS.ErrnoError(2);
|
|
3063
|
-
}
|
|
3064
|
-
if ((stream.flags & 2097155) === 1) {
|
|
3065
|
-
throw new FS.ErrnoError(2);
|
|
3066
|
-
}
|
|
3067
|
-
if (!stream.stream_ops.mmap) {
|
|
3068
|
-
throw new FS.ErrnoError(43);
|
|
3069
|
-
}
|
|
3070
|
-
if (!length) {
|
|
3071
|
-
throw new FS.ErrnoError(28);
|
|
3072
|
-
}
|
|
3073
|
-
return stream.stream_ops.mmap(stream, length, position, prot, flags);
|
|
3074
|
-
},
|
|
3075
|
-
msync(stream, buffer, offset, length, mmapFlags) {
|
|
3076
|
-
assert(offset >= 0);
|
|
3077
|
-
if (!stream.stream_ops.msync) {
|
|
3078
|
-
return 0;
|
|
3079
|
-
}
|
|
3080
|
-
return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
|
|
3081
|
-
},
|
|
3082
|
-
ioctl(stream, cmd, arg) {
|
|
3083
|
-
if (!stream.stream_ops.ioctl) {
|
|
3084
|
-
throw new FS.ErrnoError(59);
|
|
3085
|
-
}
|
|
3086
|
-
return stream.stream_ops.ioctl(stream, cmd, arg);
|
|
3087
|
-
},
|
|
3088
|
-
readFile(path, opts = {}) {
|
|
3089
|
-
opts.flags = opts.flags || 0;
|
|
3090
|
-
opts.encoding = opts.encoding || 'binary';
|
|
3091
|
-
if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
|
|
3092
|
-
abort(`Invalid encoding type "${opts.encoding}"`);
|
|
3093
|
-
}
|
|
3094
|
-
var stream = FS.open(path, opts.flags);
|
|
3095
|
-
var stat = FS.stat(path);
|
|
3096
|
-
var length = stat.size;
|
|
3097
|
-
var buf = new Uint8Array(length);
|
|
3098
|
-
FS.read(stream, buf, 0, length, 0);
|
|
3099
|
-
if (opts.encoding === 'utf8') {
|
|
3100
|
-
buf = UTF8ArrayToString(buf);
|
|
3101
|
-
}
|
|
3102
|
-
FS.close(stream);
|
|
3103
|
-
return buf;
|
|
3104
|
-
},
|
|
3105
|
-
writeFile(path, data, opts = {}) {
|
|
3106
|
-
opts.flags = opts.flags || 577;
|
|
3107
|
-
var stream = FS.open(path, opts.flags, opts.mode);
|
|
3108
|
-
if (typeof data == 'string') {
|
|
3109
|
-
data = new Uint8Array(intArrayFromString(data, true));
|
|
3110
|
-
}
|
|
3111
|
-
if (ArrayBuffer.isView(data)) {
|
|
3112
|
-
FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
|
|
3113
|
-
} else {
|
|
3114
|
-
abort('Unsupported data type');
|
|
3115
|
-
}
|
|
3116
|
-
FS.close(stream);
|
|
3117
|
-
},
|
|
3118
|
-
cwd:() => FS.currentPath,
|
|
3119
|
-
chdir(path) {
|
|
3120
|
-
var lookup = FS.lookupPath(path, { follow: true });
|
|
3121
|
-
if (lookup.node === null) {
|
|
3122
|
-
throw new FS.ErrnoError(44);
|
|
3123
|
-
}
|
|
3124
|
-
if (!FS.isDir(lookup.node.mode)) {
|
|
3125
|
-
throw new FS.ErrnoError(54);
|
|
3126
|
-
}
|
|
3127
|
-
var errCode = FS.nodePermissions(lookup.node, 'x');
|
|
3128
|
-
if (errCode) {
|
|
3129
|
-
throw new FS.ErrnoError(errCode);
|
|
3130
|
-
}
|
|
3131
|
-
FS.currentPath = lookup.path;
|
|
3132
|
-
},
|
|
3133
|
-
createDefaultDirectories() {
|
|
3134
|
-
FS.mkdir('/tmp');
|
|
3135
|
-
FS.mkdir('/home');
|
|
3136
|
-
FS.mkdir('/home/web_user');
|
|
3137
|
-
},
|
|
3138
|
-
createDefaultDevices() {
|
|
3139
|
-
// create /dev
|
|
3140
|
-
FS.mkdir('/dev');
|
|
3141
|
-
// setup /dev/null
|
|
3142
|
-
FS.registerDevice(FS.makedev(1, 3), {
|
|
3143
|
-
read: () => 0,
|
|
3144
|
-
write: (stream, buffer, offset, length, pos) => length,
|
|
3145
|
-
llseek: () => 0,
|
|
3146
|
-
});
|
|
3147
|
-
FS.mkdev('/dev/null', FS.makedev(1, 3));
|
|
3148
|
-
// setup /dev/tty and /dev/tty1
|
|
3149
|
-
// stderr needs to print output using err() rather than out()
|
|
3150
|
-
// so we register a second tty just for it.
|
|
3151
|
-
TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
|
|
3152
|
-
TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
|
|
3153
|
-
FS.mkdev('/dev/tty', FS.makedev(5, 0));
|
|
3154
|
-
FS.mkdev('/dev/tty1', FS.makedev(6, 0));
|
|
3155
|
-
// setup /dev/[u]random
|
|
3156
|
-
// use a buffer to avoid overhead of individual crypto calls per byte
|
|
3157
|
-
var randomBuffer = new Uint8Array(1024), randomLeft = 0;
|
|
3158
|
-
var randomByte = () => {
|
|
3159
|
-
if (randomLeft === 0) {
|
|
3160
|
-
randomFill(randomBuffer);
|
|
3161
|
-
randomLeft = randomBuffer.byteLength;
|
|
3162
|
-
}
|
|
3163
|
-
return randomBuffer[--randomLeft];
|
|
3164
|
-
};
|
|
3165
|
-
FS.createDevice('/dev', 'random', randomByte);
|
|
3166
|
-
FS.createDevice('/dev', 'urandom', randomByte);
|
|
3167
|
-
// we're not going to emulate the actual shm device,
|
|
3168
|
-
// just create the tmp dirs that reside in it commonly
|
|
3169
|
-
FS.mkdir('/dev/shm');
|
|
3170
|
-
FS.mkdir('/dev/shm/tmp');
|
|
3171
|
-
},
|
|
3172
|
-
createSpecialDirectories() {
|
|
3173
|
-
// create /proc/self/fd which allows /proc/self/fd/6 => readlink gives the
|
|
3174
|
-
// name of the stream for fd 6 (see test_unistd_ttyname)
|
|
3175
|
-
FS.mkdir('/proc');
|
|
3176
|
-
var proc_self = FS.mkdir('/proc/self');
|
|
3177
|
-
FS.mkdir('/proc/self/fd');
|
|
3178
|
-
FS.mount({
|
|
3179
|
-
mount() {
|
|
3180
|
-
var node = FS.createNode(proc_self, 'fd', 16895, 73);
|
|
3181
|
-
node.stream_ops = {
|
|
3182
|
-
llseek: MEMFS.stream_ops.llseek,
|
|
3183
|
-
};
|
|
3184
|
-
node.node_ops = {
|
|
3185
|
-
lookup(parent, name) {
|
|
3186
|
-
var fd = +name;
|
|
3187
|
-
var stream = FS.getStreamChecked(fd);
|
|
3188
|
-
var ret = {
|
|
3189
|
-
parent: null,
|
|
3190
|
-
mount: { mountpoint: 'fake' },
|
|
3191
|
-
node_ops: { readlink: () => stream.path },
|
|
3192
|
-
id: fd + 1,
|
|
3193
|
-
};
|
|
3194
|
-
ret.parent = ret; // make it look like a simple root node
|
|
3195
|
-
return ret;
|
|
3196
|
-
},
|
|
3197
|
-
readdir() {
|
|
3198
|
-
return Array.from(FS.streams.entries())
|
|
3199
|
-
.filter(([k, v]) => v)
|
|
3200
|
-
.map(([k, v]) => k.toString());
|
|
3201
|
-
}
|
|
3202
|
-
};
|
|
3203
|
-
return node;
|
|
3204
|
-
}
|
|
3205
|
-
}, {}, '/proc/self/fd');
|
|
3206
|
-
},
|
|
3207
|
-
createStandardStreams(input, output, error) {
|
|
3208
|
-
// TODO deprecate the old functionality of a single
|
|
3209
|
-
// input / output callback and that utilizes FS.createDevice
|
|
3210
|
-
// and instead require a unique set of stream ops
|
|
3211
|
-
|
|
3212
|
-
// by default, we symlink the standard streams to the
|
|
3213
|
-
// default tty devices. however, if the standard streams
|
|
3214
|
-
// have been overwritten we create a unique device for
|
|
3215
|
-
// them instead.
|
|
3216
|
-
if (input) {
|
|
3217
|
-
FS.createDevice('/dev', 'stdin', input);
|
|
3218
|
-
} else {
|
|
3219
|
-
FS.symlink('/dev/tty', '/dev/stdin');
|
|
3220
|
-
}
|
|
3221
|
-
if (output) {
|
|
3222
|
-
FS.createDevice('/dev', 'stdout', null, output);
|
|
3223
|
-
} else {
|
|
3224
|
-
FS.symlink('/dev/tty', '/dev/stdout');
|
|
3225
|
-
}
|
|
3226
|
-
if (error) {
|
|
3227
|
-
FS.createDevice('/dev', 'stderr', null, error);
|
|
3228
|
-
} else {
|
|
3229
|
-
FS.symlink('/dev/tty1', '/dev/stderr');
|
|
3230
|
-
}
|
|
3231
|
-
|
|
3232
|
-
// open default streams for the stdin, stdout and stderr devices
|
|
3233
|
-
var stdin = FS.open('/dev/stdin', 0);
|
|
3234
|
-
var stdout = FS.open('/dev/stdout', 1);
|
|
3235
|
-
var stderr = FS.open('/dev/stderr', 1);
|
|
3236
|
-
assert(stdin.fd === 0, `invalid handle for stdin (${stdin.fd})`);
|
|
3237
|
-
assert(stdout.fd === 1, `invalid handle for stdout (${stdout.fd})`);
|
|
3238
|
-
assert(stderr.fd === 2, `invalid handle for stderr (${stderr.fd})`);
|
|
3239
|
-
},
|
|
3240
|
-
staticInit() {
|
|
3241
|
-
FS.nameTable = new Array(4096);
|
|
3242
|
-
|
|
3243
|
-
FS.mount(MEMFS, {}, '/');
|
|
3244
|
-
|
|
3245
|
-
FS.createDefaultDirectories();
|
|
3246
|
-
FS.createDefaultDevices();
|
|
3247
|
-
FS.createSpecialDirectories();
|
|
3248
|
-
|
|
3249
|
-
FS.filesystems = {
|
|
3250
|
-
'MEMFS': MEMFS,
|
|
3251
|
-
};
|
|
3252
|
-
},
|
|
3253
|
-
init(input, output, error) {
|
|
3254
|
-
assert(!FS.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)');
|
|
3255
|
-
FS.initialized = true;
|
|
3256
|
-
|
|
3257
|
-
// Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
|
|
3258
|
-
input ??= Module['stdin'];
|
|
3259
|
-
output ??= Module['stdout'];
|
|
3260
|
-
error ??= Module['stderr'];
|
|
3261
|
-
|
|
3262
|
-
FS.createStandardStreams(input, output, error);
|
|
3263
|
-
},
|
|
3264
|
-
quit() {
|
|
3265
|
-
FS.initialized = false;
|
|
3266
|
-
// force-flush all streams, so we get musl std streams printed out
|
|
3267
|
-
_fflush(0);
|
|
3268
|
-
// close all of our streams
|
|
3269
|
-
for (var stream of FS.streams) {
|
|
3270
|
-
if (stream) {
|
|
3271
|
-
FS.close(stream);
|
|
3272
|
-
}
|
|
3273
|
-
}
|
|
3274
|
-
},
|
|
3275
|
-
findObject(path, dontResolveLastLink) {
|
|
3276
|
-
var ret = FS.analyzePath(path, dontResolveLastLink);
|
|
3277
|
-
if (!ret.exists) {
|
|
3278
|
-
return null;
|
|
3279
|
-
}
|
|
3280
|
-
return ret.object;
|
|
3281
|
-
},
|
|
3282
|
-
analyzePath(path, dontResolveLastLink) {
|
|
3283
|
-
// operate from within the context of the symlink's target
|
|
3284
|
-
try {
|
|
3285
|
-
var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
|
|
3286
|
-
path = lookup.path;
|
|
3287
|
-
} catch (e) {
|
|
3288
|
-
}
|
|
3289
|
-
var ret = {
|
|
3290
|
-
isRoot: false, exists: false, error: 0, name: null, path: null, object: null,
|
|
3291
|
-
parentExists: false, parentPath: null, parentObject: null
|
|
3292
|
-
};
|
|
3293
|
-
try {
|
|
3294
|
-
var lookup = FS.lookupPath(path, { parent: true });
|
|
3295
|
-
ret.parentExists = true;
|
|
3296
|
-
ret.parentPath = lookup.path;
|
|
3297
|
-
ret.parentObject = lookup.node;
|
|
3298
|
-
ret.name = PATH.basename(path);
|
|
3299
|
-
lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
|
|
3300
|
-
ret.exists = true;
|
|
3301
|
-
ret.path = lookup.path;
|
|
3302
|
-
ret.object = lookup.node;
|
|
3303
|
-
ret.name = lookup.node.name;
|
|
3304
|
-
ret.isRoot = lookup.path === '/';
|
|
3305
|
-
} catch (e) {
|
|
3306
|
-
ret.error = e.errno;
|
|
3307
|
-
};
|
|
3308
|
-
return ret;
|
|
3309
|
-
},
|
|
3310
|
-
createPath(parent, path, canRead, canWrite) {
|
|
3311
|
-
parent = typeof parent == 'string' ? parent : FS.getPath(parent);
|
|
3312
|
-
var parts = path.split('/').reverse();
|
|
3313
|
-
while (parts.length) {
|
|
3314
|
-
var part = parts.pop();
|
|
3315
|
-
if (!part) continue;
|
|
3316
|
-
var current = PATH.join2(parent, part);
|
|
3317
|
-
try {
|
|
3318
|
-
FS.mkdir(current);
|
|
3319
|
-
} catch (e) {
|
|
3320
|
-
if (e.errno != 20) throw e;
|
|
3321
|
-
}
|
|
3322
|
-
parent = current;
|
|
3323
|
-
}
|
|
3324
|
-
return current;
|
|
3325
|
-
},
|
|
3326
|
-
createFile(parent, name, properties, canRead, canWrite) {
|
|
3327
|
-
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
|
|
3328
|
-
var mode = FS_getMode(canRead, canWrite);
|
|
3329
|
-
return FS.create(path, mode);
|
|
3330
|
-
},
|
|
3331
|
-
createDataFile(parent, name, data, canRead, canWrite, canOwn) {
|
|
3332
|
-
var path = name;
|
|
3333
|
-
if (parent) {
|
|
3334
|
-
parent = typeof parent == 'string' ? parent : FS.getPath(parent);
|
|
3335
|
-
path = name ? PATH.join2(parent, name) : parent;
|
|
3336
|
-
}
|
|
3337
|
-
var mode = FS_getMode(canRead, canWrite);
|
|
3338
|
-
var node = FS.create(path, mode);
|
|
3339
|
-
if (data) {
|
|
3340
|
-
if (typeof data == 'string') {
|
|
3341
|
-
var arr = new Array(data.length);
|
|
3342
|
-
for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
|
|
3343
|
-
data = arr;
|
|
3344
|
-
}
|
|
3345
|
-
// make sure we can write to the file
|
|
3346
|
-
FS.chmod(node, mode | 146);
|
|
3347
|
-
var stream = FS.open(node, 577);
|
|
3348
|
-
FS.write(stream, data, 0, data.length, 0, canOwn);
|
|
3349
|
-
FS.close(stream);
|
|
3350
|
-
FS.chmod(node, mode);
|
|
3351
|
-
}
|
|
3352
|
-
},
|
|
3353
|
-
createDevice(parent, name, input, output) {
|
|
3354
|
-
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
|
|
3355
|
-
var mode = FS_getMode(!!input, !!output);
|
|
3356
|
-
FS.createDevice.major ??= 64;
|
|
3357
|
-
var dev = FS.makedev(FS.createDevice.major++, 0);
|
|
3358
|
-
// Create a fake device that a set of stream ops to emulate
|
|
3359
|
-
// the old behavior.
|
|
3360
|
-
FS.registerDevice(dev, {
|
|
3361
|
-
open(stream) {
|
|
3362
|
-
stream.seekable = false;
|
|
3363
|
-
},
|
|
3364
|
-
close(stream) {
|
|
3365
|
-
// flush any pending line data
|
|
3366
|
-
if (output?.buffer?.length) {
|
|
3367
|
-
output(10);
|
|
3368
|
-
}
|
|
3369
|
-
},
|
|
3370
|
-
read(stream, buffer, offset, length, pos /* ignored */) {
|
|
3371
|
-
var bytesRead = 0;
|
|
3372
|
-
for (var i = 0; i < length; i++) {
|
|
3373
|
-
var result;
|
|
3374
|
-
try {
|
|
3375
|
-
result = input();
|
|
3376
|
-
} catch (e) {
|
|
3377
|
-
throw new FS.ErrnoError(29);
|
|
3378
|
-
}
|
|
3379
|
-
if (result === undefined && bytesRead === 0) {
|
|
3380
|
-
throw new FS.ErrnoError(6);
|
|
3381
|
-
}
|
|
3382
|
-
if (result === null || result === undefined) break;
|
|
3383
|
-
bytesRead++;
|
|
3384
|
-
buffer[offset+i] = result;
|
|
3385
|
-
}
|
|
3386
|
-
if (bytesRead) {
|
|
3387
|
-
stream.node.atime = Date.now();
|
|
3388
|
-
}
|
|
3389
|
-
return bytesRead;
|
|
3390
|
-
},
|
|
3391
|
-
write(stream, buffer, offset, length, pos) {
|
|
3392
|
-
for (var i = 0; i < length; i++) {
|
|
3393
|
-
try {
|
|
3394
|
-
output(buffer[offset+i]);
|
|
3395
|
-
} catch (e) {
|
|
3396
|
-
throw new FS.ErrnoError(29);
|
|
3397
|
-
}
|
|
3398
|
-
}
|
|
3399
|
-
if (length) {
|
|
3400
|
-
stream.node.mtime = stream.node.ctime = Date.now();
|
|
3401
|
-
}
|
|
3402
|
-
return i;
|
|
3403
|
-
}
|
|
3404
|
-
});
|
|
3405
|
-
return FS.mkdev(path, mode, dev);
|
|
3406
|
-
},
|
|
3407
|
-
forceLoadFile(obj) {
|
|
3408
|
-
if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
|
|
3409
|
-
if (globalThis.XMLHttpRequest) {
|
|
3410
|
-
abort("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
|
|
3411
|
-
} else { // Command-line.
|
|
3412
|
-
try {
|
|
3413
|
-
obj.contents = readBinary(obj.url);
|
|
3414
|
-
} catch (e) {
|
|
3415
|
-
throw new FS.ErrnoError(29);
|
|
3416
|
-
}
|
|
3417
|
-
}
|
|
3418
|
-
},
|
|
3419
|
-
createLazyFile(parent, name, url, canRead, canWrite) {
|
|
3420
|
-
// Lazy chunked Uint8Array (implements get and length from Uint8Array).
|
|
3421
|
-
// Actual getting is abstracted away for eventual reuse.
|
|
3422
|
-
class LazyUint8Array {
|
|
3423
|
-
lengthKnown = false;
|
|
3424
|
-
chunks = []; // Loaded chunks. Index is the chunk number
|
|
3425
|
-
get(idx) {
|
|
3426
|
-
if (idx > this.length-1 || idx < 0) {
|
|
3427
|
-
return undefined;
|
|
3428
|
-
}
|
|
3429
|
-
var chunkOffset = idx % this.chunkSize;
|
|
3430
|
-
var chunkNum = (idx / this.chunkSize)|0;
|
|
3431
|
-
return this.getter(chunkNum)[chunkOffset];
|
|
3432
|
-
}
|
|
3433
|
-
setDataGetter(getter) {
|
|
3434
|
-
this.getter = getter;
|
|
3435
|
-
}
|
|
3436
|
-
cacheLength() {
|
|
3437
|
-
// Find length
|
|
3438
|
-
var xhr = new XMLHttpRequest();
|
|
3439
|
-
xhr.open('HEAD', url, false);
|
|
3440
|
-
xhr.send(null);
|
|
3441
|
-
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3442
|
-
var datalength = Number(xhr.getResponseHeader("Content-length"));
|
|
3443
|
-
var header;
|
|
3444
|
-
var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
|
|
3445
|
-
var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
|
|
3446
|
-
|
|
3447
|
-
var chunkSize = 1024*1024; // Chunk size in bytes
|
|
3448
|
-
|
|
3449
|
-
if (!hasByteServing) chunkSize = datalength;
|
|
3450
|
-
|
|
3451
|
-
// Function to get a range from the remote URL.
|
|
3452
|
-
var doXHR = (from, to) => {
|
|
3453
|
-
if (from > to) abort("invalid range (" + from + ", " + to + ") or no bytes requested!");
|
|
3454
|
-
if (to > datalength-1) abort("only " + datalength + " bytes available! programmer error!");
|
|
3455
|
-
|
|
3456
|
-
// TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
|
|
3457
|
-
var xhr = new XMLHttpRequest();
|
|
3458
|
-
xhr.open('GET', url, false);
|
|
3459
|
-
if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
|
|
3460
|
-
|
|
3461
|
-
// Some hints to the browser that we want binary data.
|
|
3462
|
-
xhr.responseType = 'arraybuffer';
|
|
3463
|
-
if (xhr.overrideMimeType) {
|
|
3464
|
-
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
|
3465
|
-
}
|
|
3466
|
-
|
|
3467
|
-
xhr.send(null);
|
|
3468
|
-
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3469
|
-
if (xhr.response !== undefined) {
|
|
3470
|
-
return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
|
|
3471
|
-
}
|
|
3472
|
-
return intArrayFromString(xhr.responseText || '', true);
|
|
3473
|
-
};
|
|
3474
|
-
var lazyArray = this;
|
|
3475
|
-
lazyArray.setDataGetter((chunkNum) => {
|
|
3476
|
-
var start = chunkNum * chunkSize;
|
|
3477
|
-
var end = (chunkNum+1) * chunkSize - 1; // including this byte
|
|
3478
|
-
end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
|
|
3479
|
-
if (typeof lazyArray.chunks[chunkNum] == 'undefined') {
|
|
3480
|
-
lazyArray.chunks[chunkNum] = doXHR(start, end);
|
|
3481
|
-
}
|
|
3482
|
-
if (typeof lazyArray.chunks[chunkNum] == 'undefined') abort('doXHR failed!');
|
|
3483
|
-
return lazyArray.chunks[chunkNum];
|
|
3484
|
-
});
|
|
3485
|
-
|
|
3486
|
-
if (usesGzip || !datalength) {
|
|
3487
|
-
// if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length
|
|
3488
|
-
chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file
|
|
3489
|
-
datalength = this.getter(0).length;
|
|
3490
|
-
chunkSize = datalength;
|
|
3491
|
-
out("LazyFiles on gzip forces download of the whole file when length is accessed");
|
|
3492
|
-
}
|
|
3493
|
-
|
|
3494
|
-
this._length = datalength;
|
|
3495
|
-
this._chunkSize = chunkSize;
|
|
3496
|
-
this.lengthKnown = true;
|
|
3497
|
-
}
|
|
3498
|
-
get length() {
|
|
3499
|
-
if (!this.lengthKnown) {
|
|
3500
|
-
this.cacheLength();
|
|
3501
|
-
}
|
|
3502
|
-
return this._length;
|
|
3503
|
-
}
|
|
3504
|
-
get chunkSize() {
|
|
3505
|
-
if (!this.lengthKnown) {
|
|
3506
|
-
this.cacheLength();
|
|
3507
|
-
}
|
|
3508
|
-
return this._chunkSize;
|
|
3509
|
-
}
|
|
3510
|
-
}
|
|
3511
|
-
|
|
3512
|
-
if (globalThis.XMLHttpRequest) {
|
|
3513
|
-
if (!ENVIRONMENT_IS_WORKER) abort('Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc');
|
|
3514
|
-
var lazyArray = new LazyUint8Array();
|
|
3515
|
-
var properties = { isDevice: false, contents: lazyArray };
|
|
3516
|
-
} else {
|
|
3517
|
-
var properties = { isDevice: false, url: url };
|
|
3518
|
-
}
|
|
3519
|
-
|
|
3520
|
-
var node = FS.createFile(parent, name, properties, canRead, canWrite);
|
|
3521
|
-
// This is a total hack, but I want to get this lazy file code out of the
|
|
3522
|
-
// core of MEMFS. If we want to keep this lazy file concept I feel it should
|
|
3523
|
-
// be its own thin LAZYFS proxying calls to MEMFS.
|
|
3524
|
-
if (properties.contents) {
|
|
3525
|
-
node.contents = properties.contents;
|
|
3526
|
-
} else if (properties.url) {
|
|
3527
|
-
node.contents = null;
|
|
3528
|
-
node.url = properties.url;
|
|
3529
|
-
}
|
|
3530
|
-
// Add a function that defers querying the file size until it is asked the first time.
|
|
3531
|
-
Object.defineProperties(node, {
|
|
3532
|
-
usedBytes: {
|
|
3533
|
-
get: function() { return this.contents.length; }
|
|
3534
|
-
}
|
|
3535
|
-
});
|
|
3536
|
-
// override each stream op with one that tries to force load the lazy file first
|
|
3537
|
-
var stream_ops = {};
|
|
3538
|
-
for (const [key, fn] of Object.entries(node.stream_ops)) {
|
|
3539
|
-
stream_ops[key] = (...args) => {
|
|
3540
|
-
FS.forceLoadFile(node);
|
|
3541
|
-
return fn(...args);
|
|
3542
|
-
};
|
|
3543
|
-
}
|
|
3544
|
-
function writeChunks(stream, buffer, offset, length, position) {
|
|
3545
|
-
var contents = stream.node.contents;
|
|
3546
|
-
if (position >= contents.length)
|
|
3547
|
-
return 0;
|
|
3548
|
-
var size = Math.min(contents.length - position, length);
|
|
3549
|
-
assert(size >= 0);
|
|
3550
|
-
if (contents.slice) { // normal array
|
|
3551
|
-
for (var i = 0; i < size; i++) {
|
|
3552
|
-
buffer[offset + i] = contents[position + i];
|
|
3553
|
-
}
|
|
3554
|
-
} else {
|
|
3555
|
-
for (var i = 0; i < size; i++) { // LazyUint8Array from sync binary XHR
|
|
3556
|
-
buffer[offset + i] = contents.get(position + i);
|
|
3557
|
-
}
|
|
3558
|
-
}
|
|
3559
|
-
return size;
|
|
3560
|
-
}
|
|
3561
|
-
// use a custom read function
|
|
3562
|
-
stream_ops.read = (stream, buffer, offset, length, position) => {
|
|
3563
|
-
FS.forceLoadFile(node);
|
|
3564
|
-
return writeChunks(stream, buffer, offset, length, position)
|
|
3565
|
-
};
|
|
3566
|
-
// use a custom mmap function
|
|
3567
|
-
stream_ops.mmap = (stream, length, position, prot, flags) => {
|
|
3568
|
-
FS.forceLoadFile(node);
|
|
3569
|
-
var ptr = mmapAlloc(length);
|
|
3570
|
-
if (!ptr) {
|
|
3571
|
-
throw new FS.ErrnoError(48);
|
|
3572
|
-
}
|
|
3573
|
-
writeChunks(stream, HEAP8, ptr, length, position);
|
|
3574
|
-
return { ptr, allocated: true };
|
|
3575
|
-
};
|
|
3576
|
-
node.stream_ops = stream_ops;
|
|
3577
|
-
return node;
|
|
3578
|
-
},
|
|
3579
|
-
absolutePath() {
|
|
3580
|
-
abort('FS.absolutePath has been removed; use PATH_FS.resolve instead');
|
|
3581
|
-
},
|
|
3582
|
-
createFolder() {
|
|
3583
|
-
abort('FS.createFolder has been removed; use FS.mkdir instead');
|
|
3584
|
-
},
|
|
3585
|
-
createLink() {
|
|
3586
|
-
abort('FS.createLink has been removed; use FS.symlink instead');
|
|
3587
|
-
},
|
|
3588
|
-
joinPath() {
|
|
3589
|
-
abort('FS.joinPath has been removed; use PATH.join instead');
|
|
3590
|
-
},
|
|
3591
|
-
mmapAlloc() {
|
|
3592
|
-
abort('FS.mmapAlloc has been replaced by the top level function mmapAlloc');
|
|
3593
|
-
},
|
|
3594
|
-
standardizePath() {
|
|
3595
|
-
abort('FS.standardizePath has been removed; use PATH.normalize instead');
|
|
3596
|
-
},
|
|
3597
|
-
};
|
|
3598
|
-
|
|
3599
|
-
var SYSCALLS = {
|
|
3600
|
-
DEFAULT_POLLMASK:5,
|
|
3601
|
-
calculateAt(dirfd, path, allowEmpty) {
|
|
3602
|
-
if (PATH.isAbs(path)) {
|
|
3603
|
-
return path;
|
|
3604
|
-
}
|
|
3605
|
-
// relative path
|
|
3606
|
-
var dir;
|
|
3607
|
-
if (dirfd === -100) {
|
|
3608
|
-
dir = FS.cwd();
|
|
3609
|
-
} else {
|
|
3610
|
-
var dirstream = SYSCALLS.getStreamFromFD(dirfd);
|
|
3611
|
-
dir = dirstream.path;
|
|
3612
|
-
}
|
|
3613
|
-
if (path.length == 0) {
|
|
3614
|
-
if (!allowEmpty) {
|
|
3615
|
-
throw new FS.ErrnoError(44);;
|
|
3616
|
-
}
|
|
3617
|
-
return dir;
|
|
3618
|
-
}
|
|
3619
|
-
return dir + '/' + path;
|
|
3620
|
-
},
|
|
3621
|
-
writeStat(buf, stat) {
|
|
3622
|
-
HEAPU32[((buf)>>2)] = stat.dev;
|
|
3623
|
-
HEAPU32[(((buf)+(4))>>2)] = stat.mode;
|
|
3624
|
-
HEAPU32[(((buf)+(8))>>2)] = stat.nlink;
|
|
3625
|
-
HEAPU32[(((buf)+(12))>>2)] = stat.uid;
|
|
3626
|
-
HEAPU32[(((buf)+(16))>>2)] = stat.gid;
|
|
3627
|
-
HEAPU32[(((buf)+(20))>>2)] = stat.rdev;
|
|
3628
|
-
HEAP64[(((buf)+(24))>>3)] = BigInt(stat.size);
|
|
3629
|
-
HEAP32[(((buf)+(32))>>2)] = 4096;
|
|
3630
|
-
HEAP32[(((buf)+(36))>>2)] = stat.blocks;
|
|
3631
|
-
var atime = stat.atime.getTime();
|
|
3632
|
-
var mtime = stat.mtime.getTime();
|
|
3633
|
-
var ctime = stat.ctime.getTime();
|
|
3634
|
-
HEAP64[(((buf)+(40))>>3)] = BigInt(Math.floor(atime / 1000));
|
|
3635
|
-
HEAPU32[(((buf)+(48))>>2)] = (atime % 1000) * 1000 * 1000;
|
|
3636
|
-
HEAP64[(((buf)+(56))>>3)] = BigInt(Math.floor(mtime / 1000));
|
|
3637
|
-
HEAPU32[(((buf)+(64))>>2)] = (mtime % 1000) * 1000 * 1000;
|
|
3638
|
-
HEAP64[(((buf)+(72))>>3)] = BigInt(Math.floor(ctime / 1000));
|
|
3639
|
-
HEAPU32[(((buf)+(80))>>2)] = (ctime % 1000) * 1000 * 1000;
|
|
3640
|
-
HEAP64[(((buf)+(88))>>3)] = BigInt(stat.ino);
|
|
3641
|
-
return 0;
|
|
3642
|
-
},
|
|
3643
|
-
writeStatFs(buf, stats) {
|
|
3644
|
-
HEAPU32[(((buf)+(4))>>2)] = stats.bsize;
|
|
3645
|
-
HEAPU32[(((buf)+(60))>>2)] = stats.bsize;
|
|
3646
|
-
HEAP64[(((buf)+(8))>>3)] = BigInt(stats.blocks);
|
|
3647
|
-
HEAP64[(((buf)+(16))>>3)] = BigInt(stats.bfree);
|
|
3648
|
-
HEAP64[(((buf)+(24))>>3)] = BigInt(stats.bavail);
|
|
3649
|
-
HEAP64[(((buf)+(32))>>3)] = BigInt(stats.files);
|
|
3650
|
-
HEAP64[(((buf)+(40))>>3)] = BigInt(stats.ffree);
|
|
3651
|
-
HEAPU32[(((buf)+(48))>>2)] = stats.fsid;
|
|
3652
|
-
HEAPU32[(((buf)+(64))>>2)] = stats.flags; // ST_NOSUID
|
|
3653
|
-
HEAPU32[(((buf)+(56))>>2)] = stats.namelen;
|
|
3654
|
-
},
|
|
3655
|
-
doMsync(addr, stream, len, flags, offset) {
|
|
3656
|
-
if (!FS.isFile(stream.node.mode)) {
|
|
3657
|
-
throw new FS.ErrnoError(43);
|
|
3658
|
-
}
|
|
3659
|
-
if (flags & 2) {
|
|
3660
|
-
// MAP_PRIVATE calls need not to be synced back to underlying fs
|
|
3661
|
-
return 0;
|
|
3662
|
-
}
|
|
3663
|
-
var buffer = HEAPU8.slice(addr, addr + len);
|
|
3664
|
-
FS.msync(stream, buffer, offset, len, flags);
|
|
3665
|
-
},
|
|
3666
|
-
getStreamFromFD(fd) {
|
|
3667
|
-
var stream = FS.getStreamChecked(fd);
|
|
3668
|
-
return stream;
|
|
3669
|
-
},
|
|
3670
|
-
varargs:undefined,
|
|
3671
|
-
getStr(ptr) {
|
|
3672
|
-
var ret = UTF8ToString(ptr);
|
|
3673
|
-
return ret;
|
|
3674
|
-
},
|
|
3675
|
-
};
|
|
3676
|
-
function ___syscall_fcntl64(fd, cmd, varargs) {
|
|
3677
|
-
SYSCALLS.varargs = varargs;
|
|
3678
|
-
try {
|
|
3679
|
-
|
|
3680
|
-
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
3681
|
-
switch (cmd) {
|
|
3682
|
-
case 0: {
|
|
3683
|
-
var arg = syscallGetVarargI();
|
|
3684
|
-
if (arg < 0) {
|
|
3685
|
-
return -28;
|
|
3686
|
-
}
|
|
3687
|
-
while (FS.streams[arg]) {
|
|
3688
|
-
arg++;
|
|
3689
|
-
}
|
|
3690
|
-
var newStream;
|
|
3691
|
-
newStream = FS.dupStream(stream, arg);
|
|
3692
|
-
return newStream.fd;
|
|
3693
|
-
}
|
|
3694
|
-
case 1:
|
|
3695
|
-
case 2:
|
|
3696
|
-
return 0; // FD_CLOEXEC makes no sense for a single process.
|
|
3697
|
-
case 3:
|
|
3698
|
-
return stream.flags;
|
|
3699
|
-
case 4: {
|
|
3700
|
-
var arg = syscallGetVarargI();
|
|
3701
|
-
stream.flags |= arg;
|
|
3702
|
-
return 0;
|
|
3703
|
-
}
|
|
3704
|
-
case 12: {
|
|
3705
|
-
var arg = syscallGetVarargP();
|
|
3706
|
-
var offset = 0;
|
|
3707
|
-
// We're always unlocked.
|
|
3708
|
-
HEAP16[(((arg)+(offset))>>1)] = 2;
|
|
3709
|
-
return 0;
|
|
3710
|
-
}
|
|
3711
|
-
case 13:
|
|
3712
|
-
case 14:
|
|
3713
|
-
// Pretend that the locking is successful. These are process-level locks,
|
|
3714
|
-
// and Emscripten programs are a single process. If we supported linking a
|
|
3715
|
-
// filesystem between programs, we'd need to do more here.
|
|
3716
|
-
// See https://github.com/emscripten-core/emscripten/issues/23697
|
|
3717
|
-
return 0;
|
|
3718
|
-
}
|
|
3719
|
-
return -28;
|
|
3720
|
-
} catch (e) {
|
|
3721
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
3722
|
-
return -e.errno;
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
function ___syscall_ioctl(fd, op, varargs) {
|
|
3728
|
-
SYSCALLS.varargs = varargs;
|
|
3729
|
-
try {
|
|
3730
|
-
|
|
3731
|
-
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
3732
|
-
switch (op) {
|
|
3733
|
-
case 21509: {
|
|
3734
|
-
if (!stream.tty) return -59;
|
|
3735
|
-
return 0;
|
|
3736
|
-
}
|
|
3737
|
-
case 21505: {
|
|
3738
|
-
if (!stream.tty) return -59;
|
|
3739
|
-
if (stream.tty.ops.ioctl_tcgets) {
|
|
3740
|
-
var termios = stream.tty.ops.ioctl_tcgets(stream);
|
|
3741
|
-
var argp = syscallGetVarargP();
|
|
3742
|
-
HEAP32[((argp)>>2)] = termios.c_iflag || 0;
|
|
3743
|
-
HEAP32[(((argp)+(4))>>2)] = termios.c_oflag || 0;
|
|
3744
|
-
HEAP32[(((argp)+(8))>>2)] = termios.c_cflag || 0;
|
|
3745
|
-
HEAP32[(((argp)+(12))>>2)] = termios.c_lflag || 0;
|
|
3746
|
-
for (var i = 0; i < 32; i++) {
|
|
3747
|
-
HEAP8[(argp + i)+(17)] = termios.c_cc[i] || 0;
|
|
3748
|
-
}
|
|
3749
|
-
return 0;
|
|
3750
|
-
}
|
|
3751
|
-
return 0;
|
|
3752
|
-
}
|
|
3753
|
-
case 21510:
|
|
3754
|
-
case 21511:
|
|
3755
|
-
case 21512: {
|
|
3756
|
-
if (!stream.tty) return -59;
|
|
3757
|
-
return 0; // no-op, not actually adjusting terminal settings
|
|
3758
|
-
}
|
|
3759
|
-
case 21506:
|
|
3760
|
-
case 21507:
|
|
3761
|
-
case 21508: {
|
|
3762
|
-
if (!stream.tty) return -59;
|
|
3763
|
-
if (stream.tty.ops.ioctl_tcsets) {
|
|
3764
|
-
var argp = syscallGetVarargP();
|
|
3765
|
-
var c_iflag = HEAP32[((argp)>>2)];
|
|
3766
|
-
var c_oflag = HEAP32[(((argp)+(4))>>2)];
|
|
3767
|
-
var c_cflag = HEAP32[(((argp)+(8))>>2)];
|
|
3768
|
-
var c_lflag = HEAP32[(((argp)+(12))>>2)];
|
|
3769
|
-
var c_cc = []
|
|
3770
|
-
for (var i = 0; i < 32; i++) {
|
|
3771
|
-
c_cc.push(HEAP8[(argp + i)+(17)]);
|
|
3772
|
-
}
|
|
3773
|
-
return stream.tty.ops.ioctl_tcsets(stream.tty, op, { c_iflag, c_oflag, c_cflag, c_lflag, c_cc });
|
|
3774
|
-
}
|
|
3775
|
-
return 0; // no-op, not actually adjusting terminal settings
|
|
3776
|
-
}
|
|
3777
|
-
case 21519: {
|
|
3778
|
-
if (!stream.tty) return -59;
|
|
3779
|
-
var argp = syscallGetVarargP();
|
|
3780
|
-
HEAP32[((argp)>>2)] = 0;
|
|
3781
|
-
return 0;
|
|
3782
|
-
}
|
|
3783
|
-
case 21520: {
|
|
3784
|
-
if (!stream.tty) return -59;
|
|
3785
|
-
return -28; // not supported
|
|
3786
|
-
}
|
|
3787
|
-
case 21537:
|
|
3788
|
-
case 21531: {
|
|
3789
|
-
var argp = syscallGetVarargP();
|
|
3790
|
-
return FS.ioctl(stream, op, argp);
|
|
3791
|
-
}
|
|
3792
|
-
case 21523: {
|
|
3793
|
-
// TODO: in theory we should write to the winsize struct that gets
|
|
3794
|
-
// passed in, but for now musl doesn't read anything on it
|
|
3795
|
-
if (!stream.tty) return -59;
|
|
3796
|
-
if (stream.tty.ops.ioctl_tiocgwinsz) {
|
|
3797
|
-
var winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty);
|
|
3798
|
-
var argp = syscallGetVarargP();
|
|
3799
|
-
HEAP16[((argp)>>1)] = winsize[0];
|
|
3800
|
-
HEAP16[(((argp)+(2))>>1)] = winsize[1];
|
|
3801
|
-
}
|
|
3802
|
-
return 0;
|
|
3803
|
-
}
|
|
3804
|
-
case 21524: {
|
|
3805
|
-
// TODO: technically, this ioctl call should change the window size.
|
|
3806
|
-
// but, since emscripten doesn't have any concept of a terminal window
|
|
3807
|
-
// yet, we'll just silently throw it away as we do TIOCGWINSZ
|
|
3808
|
-
if (!stream.tty) return -59;
|
|
3809
|
-
return 0;
|
|
3810
|
-
}
|
|
3811
|
-
case 21515: {
|
|
3812
|
-
if (!stream.tty) return -59;
|
|
3813
|
-
return 0;
|
|
3814
|
-
}
|
|
3815
|
-
default: return -28; // not supported
|
|
3816
|
-
}
|
|
3817
|
-
} catch (e) {
|
|
3818
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
3819
|
-
return -e.errno;
|
|
3820
|
-
}
|
|
3821
|
-
}
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
function ___syscall_openat(dirfd, path, flags, varargs) {
|
|
3825
|
-
SYSCALLS.varargs = varargs;
|
|
3826
|
-
try {
|
|
3827
|
-
|
|
3828
|
-
path = SYSCALLS.getStr(path);
|
|
3829
|
-
path = SYSCALLS.calculateAt(dirfd, path);
|
|
3830
|
-
var mode = varargs ? syscallGetVarargI() : 0;
|
|
3831
|
-
return FS.open(path, flags, mode).fd;
|
|
3832
|
-
} catch (e) {
|
|
3833
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
3834
|
-
return -e.errno;
|
|
3835
|
-
}
|
|
3836
|
-
}
|
|
877
|
+
assert(false, 'Exception thrown, but exception catching is not enabled. Compile with -sNO_DISABLE_EXCEPTION_CATCHING or -sEXCEPTION_CATCHING_ALLOWED=[..] to catch.');
|
|
878
|
+
};
|
|
3837
879
|
|
|
3838
880
|
var __abort_js = () =>
|
|
3839
881
|
abort('native code called abort()');
|
|
@@ -5103,6 +2145,16 @@ async function createWasm() {
|
|
|
5103
2145
|
};
|
|
5104
2146
|
|
|
5105
2147
|
|
|
2148
|
+
var __embind_register_constant = (name, type, value) => {
|
|
2149
|
+
name = AsciiToString(name);
|
|
2150
|
+
whenDependentTypesAreResolved([], [type], (type) => {
|
|
2151
|
+
type = type[0];
|
|
2152
|
+
Module[name] = type.fromWireType(value);
|
|
2153
|
+
return [];
|
|
2154
|
+
});
|
|
2155
|
+
};
|
|
2156
|
+
|
|
2157
|
+
|
|
5106
2158
|
var emval_freelist = [];
|
|
5107
2159
|
|
|
5108
2160
|
var emval_handles = [0,1,,1,null,1,true,1,false,1];
|
|
@@ -5194,6 +2246,32 @@ async function createWasm() {
|
|
|
5194
2246
|
|
|
5195
2247
|
|
|
5196
2248
|
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
var __embind_register_function = (name, argCount, rawArgTypesAddr, signature, rawInvoker, fn, isAsync, isNonnullReturn) => {
|
|
2254
|
+
var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
|
2255
|
+
name = AsciiToString(name);
|
|
2256
|
+
name = getFunctionName(name);
|
|
2257
|
+
|
|
2258
|
+
rawInvoker = embind__requireFunction(signature, rawInvoker, isAsync);
|
|
2259
|
+
|
|
2260
|
+
exposePublicSymbol(name, function() {
|
|
2261
|
+
throwUnboundTypeError(`Cannot call ${name} due to unbound types`, argTypes);
|
|
2262
|
+
}, argCount - 1);
|
|
2263
|
+
|
|
2264
|
+
whenDependentTypesAreResolved([], argTypes, (argTypes) => {
|
|
2265
|
+
var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
|
|
2266
|
+
replacePublicSymbol(name, craftInvokerFunction(name, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn, isAsync), argCount - 1);
|
|
2267
|
+
return [];
|
|
2268
|
+
});
|
|
2269
|
+
};
|
|
2270
|
+
|
|
2271
|
+
|
|
2272
|
+
|
|
2273
|
+
|
|
2274
|
+
|
|
5197
2275
|
/** @suppress {globalThis} */
|
|
5198
2276
|
var __embind_register_integer = (primitiveType, name, size, minRange, maxRange) => {
|
|
5199
2277
|
name = AsciiToString(name);
|
|
@@ -5300,14 +2378,153 @@ async function createWasm() {
|
|
|
5300
2378
|
|
|
5301
2379
|
|
|
5302
2380
|
|
|
2381
|
+
var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
|
|
2382
|
+
assert(typeof str === 'string', `stringToUTF8Array expects a string (got ${typeof str})`);
|
|
2383
|
+
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
|
|
2384
|
+
// undefined and false each don't write out any bytes.
|
|
2385
|
+
if (!(maxBytesToWrite > 0))
|
|
2386
|
+
return 0;
|
|
2387
|
+
|
|
2388
|
+
var startIdx = outIdx;
|
|
2389
|
+
var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
|
|
2390
|
+
for (var i = 0; i < str.length; ++i) {
|
|
2391
|
+
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
|
|
2392
|
+
// and https://www.ietf.org/rfc/rfc2279.txt
|
|
2393
|
+
// and https://tools.ietf.org/html/rfc3629
|
|
2394
|
+
var u = str.codePointAt(i);
|
|
2395
|
+
if (u <= 0x7F) {
|
|
2396
|
+
if (outIdx >= endIdx) break;
|
|
2397
|
+
heap[outIdx++] = u;
|
|
2398
|
+
} else if (u <= 0x7FF) {
|
|
2399
|
+
if (outIdx + 1 >= endIdx) break;
|
|
2400
|
+
heap[outIdx++] = 0xC0 | (u >> 6);
|
|
2401
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
2402
|
+
} else if (u <= 0xFFFF) {
|
|
2403
|
+
if (outIdx + 2 >= endIdx) break;
|
|
2404
|
+
heap[outIdx++] = 0xE0 | (u >> 12);
|
|
2405
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
2406
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
2407
|
+
} else {
|
|
2408
|
+
if (outIdx + 3 >= endIdx) break;
|
|
2409
|
+
if (u > 0x10FFFF) warnOnce('Invalid Unicode code point ' + ptrToString(u) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
|
|
2410
|
+
heap[outIdx++] = 0xF0 | (u >> 18);
|
|
2411
|
+
heap[outIdx++] = 0x80 | ((u >> 12) & 63);
|
|
2412
|
+
heap[outIdx++] = 0x80 | ((u >> 6) & 63);
|
|
2413
|
+
heap[outIdx++] = 0x80 | (u & 63);
|
|
2414
|
+
// Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16.
|
|
2415
|
+
// We need to manually skip over the second code unit for correct iteration.
|
|
2416
|
+
i++;
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
// Null-terminate the pointer to the buffer.
|
|
2420
|
+
heap[outIdx] = 0;
|
|
2421
|
+
return outIdx - startIdx;
|
|
2422
|
+
};
|
|
5303
2423
|
var stringToUTF8 = (str, outPtr, maxBytesToWrite) => {
|
|
5304
2424
|
assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
|
|
5305
2425
|
return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
|
|
5306
2426
|
};
|
|
5307
2427
|
|
|
2428
|
+
var lengthBytesUTF8 = (str) => {
|
|
2429
|
+
var len = 0;
|
|
2430
|
+
for (var i = 0; i < str.length; ++i) {
|
|
2431
|
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
|
|
2432
|
+
// unit, not a Unicode code point of the character! So decode
|
|
2433
|
+
// UTF16->UTF32->UTF8.
|
|
2434
|
+
// See http://unicode.org/faq/utf_bom.html#utf16-3
|
|
2435
|
+
var c = str.charCodeAt(i); // possibly a lead surrogate
|
|
2436
|
+
if (c <= 0x7F) {
|
|
2437
|
+
len++;
|
|
2438
|
+
} else if (c <= 0x7FF) {
|
|
2439
|
+
len += 2;
|
|
2440
|
+
} else if (c >= 0xD800 && c <= 0xDFFF) {
|
|
2441
|
+
len += 4; ++i;
|
|
2442
|
+
} else {
|
|
2443
|
+
len += 3;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
return len;
|
|
2447
|
+
};
|
|
2448
|
+
|
|
2449
|
+
|
|
2450
|
+
|
|
2451
|
+
var UTF8Decoder = globalThis.TextDecoder && new TextDecoder();
|
|
2452
|
+
|
|
2453
|
+
var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
|
|
2454
|
+
var maxIdx = idx + maxBytesToRead;
|
|
2455
|
+
if (ignoreNul) return maxIdx;
|
|
2456
|
+
// TextDecoder needs to know the byte length in advance, it doesn't stop on
|
|
2457
|
+
// null terminator by itself.
|
|
2458
|
+
// As a tiny code save trick, compare idx against maxIdx using a negation,
|
|
2459
|
+
// so that maxBytesToRead=undefined/NaN means Infinity.
|
|
2460
|
+
while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;
|
|
2461
|
+
return idx;
|
|
2462
|
+
};
|
|
2463
|
+
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
|
|
2467
|
+
* array that contains uint8 values, returns a copy of that string as a
|
|
2468
|
+
* Javascript String object.
|
|
2469
|
+
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
2470
|
+
* @param {number=} idx
|
|
2471
|
+
* @param {number=} maxBytesToRead
|
|
2472
|
+
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
2473
|
+
* @return {string}
|
|
2474
|
+
*/
|
|
2475
|
+
var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
|
|
2476
|
+
|
|
2477
|
+
var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
|
|
5308
2478
|
|
|
2479
|
+
// When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
|
|
2480
|
+
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
2481
|
+
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
2482
|
+
}
|
|
2483
|
+
var str = '';
|
|
2484
|
+
while (idx < endPtr) {
|
|
2485
|
+
// For UTF8 byte structure, see:
|
|
2486
|
+
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
2487
|
+
// https://www.ietf.org/rfc/rfc2279.txt
|
|
2488
|
+
// https://tools.ietf.org/html/rfc3629
|
|
2489
|
+
var u0 = heapOrArray[idx++];
|
|
2490
|
+
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
|
|
2491
|
+
var u1 = heapOrArray[idx++] & 63;
|
|
2492
|
+
if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
|
|
2493
|
+
var u2 = heapOrArray[idx++] & 63;
|
|
2494
|
+
if ((u0 & 0xF0) == 0xE0) {
|
|
2495
|
+
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
2496
|
+
} else {
|
|
2497
|
+
if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte ' + ptrToString(u0) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
|
|
2498
|
+
u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
2499
|
+
}
|
|
5309
2500
|
|
|
2501
|
+
if (u0 < 0x10000) {
|
|
2502
|
+
str += String.fromCharCode(u0);
|
|
2503
|
+
} else {
|
|
2504
|
+
var ch = u0 - 0x10000;
|
|
2505
|
+
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
return str;
|
|
2509
|
+
};
|
|
5310
2510
|
|
|
2511
|
+
/**
|
|
2512
|
+
* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
|
|
2513
|
+
* emscripten HEAP, returns a copy of that string as a Javascript String object.
|
|
2514
|
+
*
|
|
2515
|
+
* @param {number} ptr
|
|
2516
|
+
* @param {number=} maxBytesToRead - An optional length that specifies the
|
|
2517
|
+
* maximum number of bytes to read. You can omit this parameter to scan the
|
|
2518
|
+
* string until the first 0 byte. If maxBytesToRead is passed, and the string
|
|
2519
|
+
* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
|
|
2520
|
+
* string will cut short at that byte index.
|
|
2521
|
+
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
2522
|
+
* @return {string}
|
|
2523
|
+
*/
|
|
2524
|
+
var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => {
|
|
2525
|
+
assert(typeof ptr == 'number', `UTF8ToString expects a number (got ${typeof ptr})`);
|
|
2526
|
+
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : '';
|
|
2527
|
+
};
|
|
5311
2528
|
var __embind_register_std_string = (rawType, name) => {
|
|
5312
2529
|
name = AsciiToString(name);
|
|
5313
2530
|
var stdStringIsUTF8 = true;
|
|
@@ -5785,50 +3002,17 @@ async function createWasm() {
|
|
|
5785
3002
|
return 0;
|
|
5786
3003
|
};
|
|
5787
3004
|
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
}
|
|
5798
|
-
}
|
|
5799
|
-
|
|
5800
|
-
/** @param {number=} offset */
|
|
5801
|
-
var doReadv = (stream, iov, iovcnt, offset) => {
|
|
5802
|
-
var ret = 0;
|
|
5803
|
-
for (var i = 0; i < iovcnt; i++) {
|
|
5804
|
-
var ptr = HEAPU32[((iov)>>2)];
|
|
5805
|
-
var len = HEAPU32[(((iov)+(4))>>2)];
|
|
5806
|
-
iov += 8;
|
|
5807
|
-
var curr = FS.read(stream, HEAP8, ptr, len, offset);
|
|
5808
|
-
if (curr < 0) return -1;
|
|
5809
|
-
ret += curr;
|
|
5810
|
-
if (curr < len) break; // nothing more to read
|
|
5811
|
-
if (typeof offset != 'undefined') {
|
|
5812
|
-
offset += curr;
|
|
5813
|
-
}
|
|
5814
|
-
}
|
|
5815
|
-
return ret;
|
|
3005
|
+
var SYSCALLS = {
|
|
3006
|
+
varargs:undefined,
|
|
3007
|
+
getStr(ptr) {
|
|
3008
|
+
var ret = UTF8ToString(ptr);
|
|
3009
|
+
return ret;
|
|
3010
|
+
},
|
|
3011
|
+
};
|
|
3012
|
+
var _fd_close = (fd) => {
|
|
3013
|
+
abort('fd_close called without SYSCALLS_REQUIRE_FILESYSTEM');
|
|
5816
3014
|
};
|
|
5817
|
-
|
|
5818
|
-
function _fd_read(fd, iov, iovcnt, pnum) {
|
|
5819
|
-
try {
|
|
5820
|
-
|
|
5821
|
-
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
5822
|
-
var num = doReadv(stream, iov, iovcnt);
|
|
5823
|
-
HEAPU32[((pnum)>>2)] = num;
|
|
5824
|
-
return 0;
|
|
5825
|
-
} catch (e) {
|
|
5826
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5827
|
-
return e.errno;
|
|
5828
|
-
}
|
|
5829
|
-
}
|
|
5830
3015
|
|
|
5831
|
-
|
|
5832
3016
|
var INT53_MAX = 9007199254740992;
|
|
5833
3017
|
|
|
5834
3018
|
var INT53_MIN = -9007199254740992;
|
|
@@ -5837,58 +3021,46 @@ async function createWasm() {
|
|
|
5837
3021
|
offset = bigintToI53Checked(offset);
|
|
5838
3022
|
|
|
5839
3023
|
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
if (isNaN(offset)) return 61;
|
|
5843
|
-
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
5844
|
-
FS.llseek(stream, offset, whence);
|
|
5845
|
-
HEAP64[((newOffset)>>3)] = BigInt(stream.position);
|
|
5846
|
-
if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state
|
|
5847
|
-
return 0;
|
|
5848
|
-
} catch (e) {
|
|
5849
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5850
|
-
return e.errno;
|
|
5851
|
-
}
|
|
5852
|
-
;
|
|
3024
|
+
return 70;
|
|
3025
|
+
;
|
|
5853
3026
|
}
|
|
5854
3027
|
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
3028
|
+
var printCharBuffers = [null,[],[]];
|
|
3029
|
+
|
|
3030
|
+
var printChar = (stream, curr) => {
|
|
3031
|
+
var buffer = printCharBuffers[stream];
|
|
3032
|
+
assert(buffer);
|
|
3033
|
+
if (curr === 0 || curr === 10) {
|
|
3034
|
+
(stream === 1 ? out : err)(UTF8ArrayToString(buffer));
|
|
3035
|
+
buffer.length = 0;
|
|
3036
|
+
} else {
|
|
3037
|
+
buffer.push(curr);
|
|
3038
|
+
}
|
|
3039
|
+
};
|
|
3040
|
+
|
|
3041
|
+
var flush_NO_FILESYSTEM = () => {
|
|
3042
|
+
// flush anything remaining in the buffers during shutdown
|
|
3043
|
+
_fflush(0);
|
|
3044
|
+
if (printCharBuffers[1].length) printChar(1, 10);
|
|
3045
|
+
if (printCharBuffers[2].length) printChar(2, 10);
|
|
3046
|
+
};
|
|
3047
|
+
|
|
3048
|
+
|
|
3049
|
+
var _fd_write = (fd, iov, iovcnt, pnum) => {
|
|
3050
|
+
// hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
|
|
3051
|
+
var num = 0;
|
|
5858
3052
|
for (var i = 0; i < iovcnt; i++) {
|
|
5859
3053
|
var ptr = HEAPU32[((iov)>>2)];
|
|
5860
3054
|
var len = HEAPU32[(((iov)+(4))>>2)];
|
|
5861
3055
|
iov += 8;
|
|
5862
|
-
var
|
|
5863
|
-
|
|
5864
|
-
ret += curr;
|
|
5865
|
-
if (curr < len) {
|
|
5866
|
-
// No more space to write.
|
|
5867
|
-
break;
|
|
5868
|
-
}
|
|
5869
|
-
if (typeof offset != 'undefined') {
|
|
5870
|
-
offset += curr;
|
|
3056
|
+
for (var j = 0; j < len; j++) {
|
|
3057
|
+
printChar(fd, HEAPU8[ptr+j]);
|
|
5871
3058
|
}
|
|
3059
|
+
num += len;
|
|
5872
3060
|
}
|
|
5873
|
-
return ret;
|
|
5874
|
-
};
|
|
5875
|
-
|
|
5876
|
-
function _fd_write(fd, iov, iovcnt, pnum) {
|
|
5877
|
-
try {
|
|
5878
|
-
|
|
5879
|
-
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
5880
|
-
var num = doWritev(stream, iov, iovcnt);
|
|
5881
3061
|
HEAPU32[((pnum)>>2)] = num;
|
|
5882
3062
|
return 0;
|
|
5883
|
-
}
|
|
5884
|
-
if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
|
|
5885
|
-
return e.errno;
|
|
5886
|
-
}
|
|
5887
|
-
}
|
|
5888
|
-
|
|
5889
|
-
FS.createPreloadedFile = FS_createPreloadedFile;
|
|
5890
|
-
FS.preloadFile = FS_preloadFile;
|
|
5891
|
-
FS.staticInit();;
|
|
3063
|
+
};
|
|
5892
3064
|
init_ClassHandle();
|
|
5893
3065
|
init_RegisteredPointer();
|
|
5894
3066
|
assert(emval_handles.length === 5 * 2);
|
|
@@ -5902,10 +3074,13 @@ assert(emval_handles.length === 5 * 2);
|
|
|
5902
3074
|
|
|
5903
3075
|
// Begin ATMODULES hooks
|
|
5904
3076
|
if (Module['noExitRuntime']) noExitRuntime = Module['noExitRuntime'];
|
|
5905
|
-
if (Module['preloadPlugins']) preloadPlugins = Module['preloadPlugins'];
|
|
5906
3077
|
if (Module['print']) out = Module['print'];
|
|
5907
3078
|
if (Module['printErr']) err = Module['printErr'];
|
|
5908
3079
|
if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
3080
|
+
|
|
3081
|
+
Module['FS_createDataFile'] = FS.createDataFile;
|
|
3082
|
+
Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
|
|
3083
|
+
|
|
5909
3084
|
// End ATMODULES hooks
|
|
5910
3085
|
|
|
5911
3086
|
checkIncomingModuleAPI();
|
|
@@ -5958,6 +3133,7 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
|
5958
3133
|
'getHeapMax',
|
|
5959
3134
|
'growMemory',
|
|
5960
3135
|
'withStackSave',
|
|
3136
|
+
'strError',
|
|
5961
3137
|
'inetPton4',
|
|
5962
3138
|
'inetNtop4',
|
|
5963
3139
|
'inetPton6',
|
|
@@ -5975,9 +3151,14 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
|
5975
3151
|
'runtimeKeepalivePop',
|
|
5976
3152
|
'callUserCallback',
|
|
5977
3153
|
'maybeExit',
|
|
3154
|
+
'asyncLoad',
|
|
5978
3155
|
'asmjsMangle',
|
|
5979
3156
|
'alignMemory',
|
|
3157
|
+
'mmapAlloc',
|
|
5980
3158
|
'HandleAllocator',
|
|
3159
|
+
'getUniqueRunDependency',
|
|
3160
|
+
'addRunDependency',
|
|
3161
|
+
'removeRunDependency',
|
|
5981
3162
|
'addOnInit',
|
|
5982
3163
|
'addOnPostCtor',
|
|
5983
3164
|
'addOnPreMain',
|
|
@@ -5994,6 +3175,7 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
|
5994
3175
|
'getFunctionAddress',
|
|
5995
3176
|
'addFunction',
|
|
5996
3177
|
'removeFunction',
|
|
3178
|
+
'intArrayFromString',
|
|
5997
3179
|
'intArrayToString',
|
|
5998
3180
|
'stringToAscii',
|
|
5999
3181
|
'stringToNewUTF8',
|
|
@@ -6045,6 +3227,8 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
|
6045
3227
|
'checkWasiClock',
|
|
6046
3228
|
'wasiRightsToMuslOFlags',
|
|
6047
3229
|
'wasiOFlagsToMuslOFlags',
|
|
3230
|
+
'initRandomFill',
|
|
3231
|
+
'randomFill',
|
|
6048
3232
|
'safeSetTimeout',
|
|
6049
3233
|
'setImmediateWrapped',
|
|
6050
3234
|
'safeRequestAnimationFrame',
|
|
@@ -6063,6 +3247,11 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
|
|
|
6063
3247
|
'addDays',
|
|
6064
3248
|
'getSocketFromFD',
|
|
6065
3249
|
'getSocketAddress',
|
|
3250
|
+
'FS_createPreloadedFile',
|
|
3251
|
+
'FS_preloadFile',
|
|
3252
|
+
'FS_modeStringToFlags',
|
|
3253
|
+
'FS_getMode',
|
|
3254
|
+
'FS_stdin_getChar',
|
|
6066
3255
|
'FS_mkdirTree',
|
|
6067
3256
|
'_setNetworkCallback',
|
|
6068
3257
|
'heapObjectForWebGLType',
|
|
@@ -6140,7 +3329,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
|
|
|
6140
3329
|
'abortOnCannotGrowMemory',
|
|
6141
3330
|
'ENV',
|
|
6142
3331
|
'ERRNO_CODES',
|
|
6143
|
-
'strError',
|
|
6144
3332
|
'DNS',
|
|
6145
3333
|
'Protocols',
|
|
6146
3334
|
'Sockets',
|
|
@@ -6148,14 +3336,9 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
|
|
|
6148
3336
|
'warnOnce',
|
|
6149
3337
|
'readEmAsmArgsArray',
|
|
6150
3338
|
'getExecutableName',
|
|
6151
|
-
'asyncLoad',
|
|
6152
|
-
'mmapAlloc',
|
|
6153
3339
|
'wasmTable',
|
|
6154
3340
|
'wasmMemory',
|
|
6155
|
-
'getUniqueRunDependency',
|
|
6156
3341
|
'noExitRuntime',
|
|
6157
|
-
'addRunDependency',
|
|
6158
|
-
'removeRunDependency',
|
|
6159
3342
|
'addOnPreRun',
|
|
6160
3343
|
'addOnPostRun',
|
|
6161
3344
|
'freeTableIndexes',
|
|
@@ -6170,7 +3353,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
|
|
|
6170
3353
|
'stringToUTF8Array',
|
|
6171
3354
|
'stringToUTF8',
|
|
6172
3355
|
'lengthBytesUTF8',
|
|
6173
|
-
'intArrayFromString',
|
|
6174
3356
|
'AsciiToString',
|
|
6175
3357
|
'UTF16Decoder',
|
|
6176
3358
|
'UTF16ToString',
|
|
@@ -6187,10 +3369,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
|
|
|
6187
3369
|
'UNWIND_CACHE',
|
|
6188
3370
|
'ExitStatus',
|
|
6189
3371
|
'getEnvStrings',
|
|
6190
|
-
'
|
|
6191
|
-
'doWritev',
|
|
6192
|
-
'initRandomFill',
|
|
6193
|
-
'randomFill',
|
|
3372
|
+
'flush_NO_FILESYSTEM',
|
|
6194
3373
|
'emSetImmediate',
|
|
6195
3374
|
'emClearImmediate_deps',
|
|
6196
3375
|
'emClearImmediate',
|
|
@@ -6213,12 +3392,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
|
|
|
6213
3392
|
'MONTH_DAYS_LEAP_CUMULATIVE',
|
|
6214
3393
|
'SYSCALLS',
|
|
6215
3394
|
'preloadPlugins',
|
|
6216
|
-
'FS_createPreloadedFile',
|
|
6217
|
-
'FS_preloadFile',
|
|
6218
|
-
'FS_modeStringToFlags',
|
|
6219
|
-
'FS_getMode',
|
|
6220
3395
|
'FS_stdin_getChar_buffer',
|
|
6221
|
-
'FS_stdin_getChar',
|
|
6222
3396
|
'FS_unlink',
|
|
6223
3397
|
'FS_createPath',
|
|
6224
3398
|
'FS_createDevice',
|
|
@@ -6494,12 +3668,6 @@ var wasmImports = {
|
|
|
6494
3668
|
/** @export */
|
|
6495
3669
|
__cxa_throw: ___cxa_throw,
|
|
6496
3670
|
/** @export */
|
|
6497
|
-
__syscall_fcntl64: ___syscall_fcntl64,
|
|
6498
|
-
/** @export */
|
|
6499
|
-
__syscall_ioctl: ___syscall_ioctl,
|
|
6500
|
-
/** @export */
|
|
6501
|
-
__syscall_openat: ___syscall_openat,
|
|
6502
|
-
/** @export */
|
|
6503
3671
|
_abort_js: __abort_js,
|
|
6504
3672
|
/** @export */
|
|
6505
3673
|
_embind_register_bigint: __embind_register_bigint,
|
|
@@ -6512,10 +3680,14 @@ var wasmImports = {
|
|
|
6512
3680
|
/** @export */
|
|
6513
3681
|
_embind_register_class_function: __embind_register_class_function,
|
|
6514
3682
|
/** @export */
|
|
3683
|
+
_embind_register_constant: __embind_register_constant,
|
|
3684
|
+
/** @export */
|
|
6515
3685
|
_embind_register_emval: __embind_register_emval,
|
|
6516
3686
|
/** @export */
|
|
6517
3687
|
_embind_register_float: __embind_register_float,
|
|
6518
3688
|
/** @export */
|
|
3689
|
+
_embind_register_function: __embind_register_function,
|
|
3690
|
+
/** @export */
|
|
6519
3691
|
_embind_register_integer: __embind_register_integer,
|
|
6520
3692
|
/** @export */
|
|
6521
3693
|
_embind_register_memory_view: __embind_register_memory_view,
|
|
@@ -6548,8 +3720,6 @@ var wasmImports = {
|
|
|
6548
3720
|
/** @export */
|
|
6549
3721
|
fd_close: _fd_close,
|
|
6550
3722
|
/** @export */
|
|
6551
|
-
fd_read: _fd_read,
|
|
6552
|
-
/** @export */
|
|
6553
3723
|
fd_seek: _fd_seek,
|
|
6554
3724
|
/** @export */
|
|
6555
3725
|
fd_write: _fd_write
|
|
@@ -6572,21 +3742,10 @@ function stackCheckInit() {
|
|
|
6572
3742
|
|
|
6573
3743
|
function run() {
|
|
6574
3744
|
|
|
6575
|
-
if (runDependencies > 0) {
|
|
6576
|
-
dependenciesFulfilled = run;
|
|
6577
|
-
return;
|
|
6578
|
-
}
|
|
6579
|
-
|
|
6580
3745
|
stackCheckInit();
|
|
6581
3746
|
|
|
6582
3747
|
preRun();
|
|
6583
3748
|
|
|
6584
|
-
// a preRun added a dependency, run will be called later
|
|
6585
|
-
if (runDependencies > 0) {
|
|
6586
|
-
dependenciesFulfilled = run;
|
|
6587
|
-
return;
|
|
6588
|
-
}
|
|
6589
|
-
|
|
6590
3749
|
function doRun() {
|
|
6591
3750
|
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
6592
3751
|
// or while the async setStatus time below was happening
|
|
@@ -6639,23 +3798,13 @@ function checkUnflushedContent() {
|
|
|
6639
3798
|
has = true;
|
|
6640
3799
|
}
|
|
6641
3800
|
try { // it doesn't matter if it fails
|
|
6642
|
-
|
|
6643
|
-
// also flush in the JS FS layer
|
|
6644
|
-
for (var name of ['stdout', 'stderr']) {
|
|
6645
|
-
var info = FS.analyzePath('/dev/' + name);
|
|
6646
|
-
if (!info) return;
|
|
6647
|
-
var stream = info.object;
|
|
6648
|
-
var rdev = stream.rdev;
|
|
6649
|
-
var tty = TTY.ttys[rdev];
|
|
6650
|
-
if (tty?.output?.length) {
|
|
6651
|
-
has = true;
|
|
6652
|
-
}
|
|
6653
|
-
}
|
|
3801
|
+
flush_NO_FILESYSTEM();
|
|
6654
3802
|
} catch(e) {}
|
|
6655
3803
|
out = oldOut;
|
|
6656
3804
|
err = oldErr;
|
|
6657
3805
|
if (has) {
|
|
6658
3806
|
warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the Emscripten FAQ), or make sure to emit a newline when you printf etc.');
|
|
3807
|
+
warnOnce('(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)');
|
|
6659
3808
|
}
|
|
6660
3809
|
}
|
|
6661
3810
|
|