stegano.js 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481
  1. // The Module object: Our interface to the outside world. We import
  2. // and export values on it. There are various ways Module can be used:
  3. // 1. Not defined. We create it here
  4. // 2. A function parameter, function(Module) { ..generated code.. }
  5. // 3. pre-run appended it, var Module = {}; ..generated code..
  6. // 4. External script tag defines var Module.
  7. // We need to check if Module already exists (e.g. case 3 above).
  8. // Substitution will be replaced with actual code on later stage of the build,
  9. // this way Closure Compiler will not mangle it (e.g. case 4. above).
  10. // Note that if you want to run closure, and also to use Module
  11. // after the generated code, you will need to define var Module = {};
  12. // before the code. Then that object will be used in the code, and you
  13. // can continue to use Module afterwards as well.
  14. var Module = typeof Module != 'undefined' ? Module : {};
  15. // See https://caniuse.com/mdn-javascript_builtins_object_assign
  16. // See https://caniuse.com/mdn-javascript_builtins_bigint64array
  17. // --pre-jses are emitted after the Module integration code, so that they can
  18. // refer to Module (if they choose; they can also define Module)
  19. // {{PRE_JSES}}
  20. // Sometimes an existing Module object exists with properties
  21. // meant to overwrite the default module functionality. Here
  22. // we collect those properties and reapply _after_ we configure
  23. // the current environment's defaults to avoid having to be so
  24. // defensive during initialization.
  25. var moduleOverrides = Object.assign({}, Module);
  26. var arguments_ = [];
  27. var thisProgram = './this.program';
  28. var quit_ = (status, toThrow) => {
  29. throw toThrow;
  30. };
  31. // Determine the runtime environment we are in. You can customize this by
  32. // setting the ENVIRONMENT setting at compile time (see settings.js).
  33. // Attempt to auto-detect the environment
  34. var ENVIRONMENT_IS_WEB = typeof window == 'object';
  35. var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
  36. // N.b. Electron.js environment is simultaneously a NODE-environment, but
  37. // also a web environment.
  38. var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
  39. var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  40. if (Module['ENVIRONMENT']) {
  41. throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
  42. }
  43. // `/` should be present at the end if `scriptDirectory` is not empty
  44. var scriptDirectory = '';
  45. function locateFile(path) {
  46. if (Module['locateFile']) {
  47. return Module['locateFile'](path, scriptDirectory);
  48. }
  49. return scriptDirectory + path;
  50. }
  51. // Hooks that are implemented differently in different runtime environments.
  52. var read_,
  53. readAsync,
  54. readBinary,
  55. setWindowTitle;
  56. // Normally we don't log exceptions but instead let them bubble out the top
  57. // level where the embedding environment (e.g. the browser) can handle
  58. // them.
  59. // However under v8 and node we sometimes exit the process direcly in which case
  60. // its up to use us to log the exception before exiting.
  61. // If we fix https://github.com/emscripten-core/emscripten/issues/15080
  62. // this may no longer be needed under node.
  63. function logExceptionOnExit(e) {
  64. if (e instanceof ExitStatus) return;
  65. let toLog = e;
  66. if (e && typeof e == 'object' && e.stack) {
  67. toLog = [e, e.stack];
  68. }
  69. err('exiting due to exception: ' + toLog);
  70. }
  71. var fs;
  72. var nodePath;
  73. var requireNodeFS;
  74. if (ENVIRONMENT_IS_NODE) {
  75. if (typeof process == 'undefined' || !process.release || process.release.name !== 'node') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
  76. if (ENVIRONMENT_IS_WORKER) {
  77. scriptDirectory = require('path').dirname(scriptDirectory) + '/';
  78. } else {
  79. scriptDirectory = __dirname + '/';
  80. }
  81. // include: node_shell_read.js
  82. requireNodeFS = () => {
  83. // Use nodePath as the indicator for these not being initialized,
  84. // since in some environments a global fs may have already been
  85. // created.
  86. if (!nodePath) {
  87. fs = require('fs');
  88. nodePath = require('path');
  89. }
  90. };
  91. read_ = function shell_read(filename, binary) {
  92. requireNodeFS();
  93. filename = nodePath['normalize'](filename);
  94. return fs.readFileSync(filename, binary ? undefined : 'utf8');
  95. };
  96. readBinary = (filename) => {
  97. var ret = read_(filename, true);
  98. if (!ret.buffer) {
  99. ret = new Uint8Array(ret);
  100. }
  101. assert(ret.buffer);
  102. return ret;
  103. };
  104. readAsync = (filename, onload, onerror) => {
  105. requireNodeFS();
  106. filename = nodePath['normalize'](filename);
  107. fs.readFile(filename, function(err, data) {
  108. if (err) onerror(err);
  109. else onload(data.buffer);
  110. });
  111. };
  112. // end include: node_shell_read.js
  113. if (process['argv'].length > 1) {
  114. thisProgram = process['argv'][1].replace(/\\/g, '/');
  115. }
  116. arguments_ = process['argv'].slice(2);
  117. if (typeof module != 'undefined') {
  118. module['exports'] = Module;
  119. }
  120. process['on']('uncaughtException', function(ex) {
  121. // suppress ExitStatus exceptions from showing an error
  122. if (!(ex instanceof ExitStatus)) {
  123. throw ex;
  124. }
  125. });
  126. // Without this older versions of node (< v15) will log unhandled rejections
  127. // but return 0, which is not normally the desired behaviour. This is
  128. // not be needed with node v15 and about because it is now the default
  129. // behaviour:
  130. // See https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode
  131. process['on']('unhandledRejection', function(reason) { throw reason; });
  132. quit_ = (status, toThrow) => {
  133. if (keepRuntimeAlive()) {
  134. process['exitCode'] = status;
  135. throw toThrow;
  136. }
  137. logExceptionOnExit(toThrow);
  138. process['exit'](status);
  139. };
  140. Module['inspect'] = function () { return '[Emscripten Module object]'; };
  141. } else
  142. if (ENVIRONMENT_IS_SHELL) {
  143. if ((typeof process == 'object' && typeof require === 'function') || typeof window == 'object' || typeof importScripts == 'function') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
  144. if (typeof read != 'undefined') {
  145. read_ = function shell_read(f) {
  146. return read(f);
  147. };
  148. }
  149. readBinary = function readBinary(f) {
  150. let data;
  151. if (typeof readbuffer == 'function') {
  152. return new Uint8Array(readbuffer(f));
  153. }
  154. data = read(f, 'binary');
  155. assert(typeof data == 'object');
  156. return data;
  157. };
  158. readAsync = function readAsync(f, onload, onerror) {
  159. setTimeout(() => onload(readBinary(f)), 0);
  160. };
  161. if (typeof scriptArgs != 'undefined') {
  162. arguments_ = scriptArgs;
  163. } else if (typeof arguments != 'undefined') {
  164. arguments_ = arguments;
  165. }
  166. if (typeof quit == 'function') {
  167. quit_ = (status, toThrow) => {
  168. logExceptionOnExit(toThrow);
  169. quit(status);
  170. };
  171. }
  172. if (typeof print != 'undefined') {
  173. // Prefer to use print/printErr where they exist, as they usually work better.
  174. if (typeof console == 'undefined') console = /** @type{!Console} */({});
  175. console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
  176. console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr != 'undefined' ? printErr : print);
  177. }
  178. } else
  179. // Note that this includes Node.js workers when relevant (pthreads is enabled).
  180. // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
  181. // ENVIRONMENT_IS_NODE.
  182. if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  183. if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
  184. scriptDirectory = self.location.href;
  185. } else if (typeof document != 'undefined' && document.currentScript) { // web
  186. scriptDirectory = document.currentScript.src;
  187. }
  188. // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
  189. // otherwise, slice off the final part of the url to find the script directory.
  190. // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
  191. // and scriptDirectory will correctly be replaced with an empty string.
  192. // If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
  193. // they are removed because they could contain a slash.
  194. if (scriptDirectory.indexOf('blob:') !== 0) {
  195. scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf('/')+1);
  196. } else {
  197. scriptDirectory = '';
  198. }
  199. if (!(typeof window == 'object' || typeof importScripts == 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
  200. // Differentiate the Web Worker from the Node Worker case, as reading must
  201. // be done differently.
  202. {
  203. // include: web_or_worker_shell_read.js
  204. read_ = (url) => {
  205. var xhr = new XMLHttpRequest();
  206. xhr.open('GET', url, false);
  207. xhr.send(null);
  208. return xhr.responseText;
  209. }
  210. if (ENVIRONMENT_IS_WORKER) {
  211. readBinary = (url) => {
  212. var xhr = new XMLHttpRequest();
  213. xhr.open('GET', url, false);
  214. xhr.responseType = 'arraybuffer';
  215. xhr.send(null);
  216. return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
  217. };
  218. }
  219. readAsync = (url, onload, onerror) => {
  220. var xhr = new XMLHttpRequest();
  221. xhr.open('GET', url, true);
  222. xhr.responseType = 'arraybuffer';
  223. xhr.onload = () => {
  224. if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
  225. onload(xhr.response);
  226. return;
  227. }
  228. onerror();
  229. };
  230. xhr.onerror = onerror;
  231. xhr.send(null);
  232. }
  233. // end include: web_or_worker_shell_read.js
  234. }
  235. setWindowTitle = (title) => document.title = title;
  236. } else
  237. {
  238. throw new Error('environment detection error');
  239. }
  240. var out = Module['print'] || console.log.bind(console);
  241. var err = Module['printErr'] || console.warn.bind(console);
  242. // Merge back in the overrides
  243. Object.assign(Module, moduleOverrides);
  244. // Free the object hierarchy contained in the overrides, this lets the GC
  245. // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
  246. moduleOverrides = null;
  247. checkIncomingModuleAPI();
  248. // Emit code to handle expected values on the Module object. This applies Module.x
  249. // to the proper local x. This has two benefits: first, we only emit it if it is
  250. // expected to arrive, and second, by using a local everywhere else that can be
  251. // minified.
  252. if (Module['arguments']) arguments_ = Module['arguments'];legacyModuleProp('arguments', 'arguments_');
  253. if (Module['thisProgram']) thisProgram = Module['thisProgram'];legacyModuleProp('thisProgram', 'thisProgram');
  254. if (Module['quit']) quit_ = Module['quit'];legacyModuleProp('quit', 'quit_');
  255. // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
  256. // Assertions on removed incoming Module JS APIs.
  257. assert(typeof Module['memoryInitializerPrefixURL'] == 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
  258. assert(typeof Module['pthreadMainPrefixURL'] == 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
  259. assert(typeof Module['cdInitializerPrefixURL'] == 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
  260. assert(typeof Module['filePackagePrefixURL'] == 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
  261. assert(typeof Module['read'] == 'undefined', 'Module.read option was removed (modify read_ in JS)');
  262. assert(typeof Module['readAsync'] == 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)');
  263. assert(typeof Module['readBinary'] == 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)');
  264. assert(typeof Module['setWindowTitle'] == 'undefined', 'Module.setWindowTitle option was removed (modify setWindowTitle in JS)');
  265. assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
  266. legacyModuleProp('read', 'read_');
  267. legacyModuleProp('readAsync', 'readAsync');
  268. legacyModuleProp('readBinary', 'readBinary');
  269. legacyModuleProp('setWindowTitle', 'setWindowTitle');
  270. var IDBFS = 'IDBFS is no longer included by default; build with -lidbfs.js';
  271. var PROXYFS = 'PROXYFS is no longer included by default; build with -lproxyfs.js';
  272. var WORKERFS = 'WORKERFS is no longer included by default; build with -lworkerfs.js';
  273. var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
  274. assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable.");
  275. var STACK_ALIGN = 16;
  276. var POINTER_SIZE = 4;
  277. function getNativeTypeSize(type) {
  278. switch (type) {
  279. case 'i1': case 'i8': case 'u8': return 1;
  280. case 'i16': case 'u16': return 2;
  281. case 'i32': case 'u32': return 4;
  282. case 'i64': case 'u64': return 8;
  283. case 'float': return 4;
  284. case 'double': return 8;
  285. default: {
  286. if (type[type.length - 1] === '*') {
  287. return POINTER_SIZE;
  288. }
  289. if (type[0] === 'i') {
  290. const bits = Number(type.substr(1));
  291. assert(bits % 8 === 0, 'getNativeTypeSize invalid bits ' + bits + ', type ' + type);
  292. return bits / 8;
  293. }
  294. return 0;
  295. }
  296. }
  297. }
  298. // include: runtime_debug.js
  299. function legacyModuleProp(prop, newName) {
  300. if (!Object.getOwnPropertyDescriptor(Module, prop)) {
  301. Object.defineProperty(Module, prop, {
  302. configurable: true,
  303. get: function() {
  304. abort('Module.' + prop + ' has been replaced with plain ' + newName + ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)');
  305. }
  306. });
  307. }
  308. }
  309. function ignoredModuleProp(prop) {
  310. if (Object.getOwnPropertyDescriptor(Module, prop)) {
  311. abort('`Module.' + prop + '` was supplied but `' + prop + '` not included in INCOMING_MODULE_JS_API');
  312. }
  313. }
  314. // forcing the filesystem exports a few things by default
  315. function isExportedByForceFilesystem(name) {
  316. return name === 'FS_createPath' ||
  317. name === 'FS_createDataFile' ||
  318. name === 'FS_createPreloadedFile' ||
  319. name === 'FS_unlink' ||
  320. name === 'addRunDependency' ||
  321. // The old FS has some functionality that WasmFS lacks.
  322. name === 'FS_createLazyFile' ||
  323. name === 'FS_createDevice' ||
  324. name === 'removeRunDependency';
  325. }
  326. function missingLibrarySymbol(sym) {
  327. if (typeof globalThis !== 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
  328. Object.defineProperty(globalThis, sym, {
  329. configurable: true,
  330. get: function() {
  331. // Can't `abort()` here because it would break code that does runtime
  332. // checks. e.g. `if (typeof SDL === 'undefined')`.
  333. var msg = '`' + sym + '` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line';
  334. if (isExportedByForceFilesystem(sym)) {
  335. msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
  336. }
  337. warnOnce(msg);
  338. return undefined;
  339. }
  340. });
  341. }
  342. }
  343. function unexportedRuntimeSymbol(sym) {
  344. if (!Object.getOwnPropertyDescriptor(Module, sym)) {
  345. Object.defineProperty(Module, sym, {
  346. configurable: true,
  347. get: function() {
  348. var msg = "'" + sym + "' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";
  349. if (isExportedByForceFilesystem(sym)) {
  350. msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
  351. }
  352. abort(msg);
  353. }
  354. });
  355. }
  356. }
  357. // end include: runtime_debug.js
  358. // === Preamble library stuff ===
  359. // Documentation for the public APIs defined in this file must be updated in:
  360. // site/source/docs/api_reference/preamble.js.rst
  361. // A prebuilt local version of the documentation is available at:
  362. // site/build/text/docs/api_reference/preamble.js.txt
  363. // You can also build docs locally as HTML or other formats in site/
  364. // An online HTML version (which may be of a different version of Emscripten)
  365. // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
  366. var wasmBinary;
  367. if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];legacyModuleProp('wasmBinary', 'wasmBinary');
  368. var noExitRuntime = Module['noExitRuntime'] || true;legacyModuleProp('noExitRuntime', 'noExitRuntime');
  369. if (typeof WebAssembly != 'object') {
  370. abort('no native wasm support detected');
  371. }
  372. // Wasm globals
  373. var wasmMemory;
  374. //========================================
  375. // Runtime essentials
  376. //========================================
  377. // whether we are quitting the application. no code should run after this.
  378. // set in exit() and abort()
  379. var ABORT = false;
  380. // set by exit() and abort(). Passed to 'onExit' handler.
  381. // NOTE: This is also used as the process return code code in shell environments
  382. // but only when noExitRuntime is false.
  383. var EXITSTATUS;
  384. /** @type {function(*, string=)} */
  385. function assert(condition, text) {
  386. if (!condition) {
  387. abort('Assertion failed' + (text ? ': ' + text : ''));
  388. }
  389. }
  390. // We used to include malloc/free by default in the past. Show a helpful error in
  391. // builds with assertions.
  392. // include: runtime_strings.js
  393. // runtime_strings.js: Strings related runtime functions that are part of both MINIMAL_RUNTIME and regular runtime.
  394. var UTF8Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf8') : undefined;
  395. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
  396. // a copy of that string as a Javascript String object.
  397. /**
  398. * heapOrArray is either a regular array, or a JavaScript typed array view.
  399. * @param {number} idx
  400. * @param {number=} maxBytesToRead
  401. * @return {string}
  402. */
  403. function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead) {
  404. var endIdx = idx + maxBytesToRead;
  405. var endPtr = idx;
  406. // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
  407. // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
  408. // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
  409. while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
  410. if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
  411. return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
  412. }
  413. var str = '';
  414. // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
  415. while (idx < endPtr) {
  416. // For UTF8 byte structure, see:
  417. // http://en.wikipedia.org/wiki/UTF-8#Description
  418. // https://www.ietf.org/rfc/rfc2279.txt
  419. // https://tools.ietf.org/html/rfc3629
  420. var u0 = heapOrArray[idx++];
  421. if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
  422. var u1 = heapOrArray[idx++] & 63;
  423. if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
  424. var u2 = heapOrArray[idx++] & 63;
  425. if ((u0 & 0xF0) == 0xE0) {
  426. u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
  427. } else {
  428. if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte 0x' + u0.toString(16) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
  429. u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
  430. }
  431. if (u0 < 0x10000) {
  432. str += String.fromCharCode(u0);
  433. } else {
  434. var ch = u0 - 0x10000;
  435. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  436. }
  437. }
  438. return str;
  439. }
  440. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
  441. // copy of that string as a Javascript String object.
  442. // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
  443. // this parameter to scan the string until the first \0 byte. If maxBytesToRead is
  444. // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
  445. // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
  446. // not produce a string of exact length [ptr, ptr+maxBytesToRead[)
  447. // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
  448. // throw JS JIT optimizations off, so it is worth to consider consistently using one
  449. // style or the other.
  450. /**
  451. * @param {number} ptr
  452. * @param {number=} maxBytesToRead
  453. * @return {string}
  454. */
  455. function UTF8ToString(ptr, maxBytesToRead) {
  456. return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
  457. }
  458. // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
  459. // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  460. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  461. // Parameters:
  462. // str: the Javascript string to copy.
  463. // heap: the array to copy to. Each index in this array is assumed to be one 8-byte element.
  464. // outIdx: The starting offset in the array to begin the copying.
  465. // maxBytesToWrite: The maximum number of bytes this function can write to the array.
  466. // This count should include the null terminator,
  467. // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
  468. // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
  469. // Returns the number of bytes written, EXCLUDING the null terminator.
  470. function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
  471. if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
  472. return 0;
  473. var startIdx = outIdx;
  474. var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
  475. for (var i = 0; i < str.length; ++i) {
  476. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
  477. // See http://unicode.org/faq/utf_bom.html#utf16-3
  478. // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
  479. var u = str.charCodeAt(i); // possibly a lead surrogate
  480. if (u >= 0xD800 && u <= 0xDFFF) {
  481. var u1 = str.charCodeAt(++i);
  482. u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
  483. }
  484. if (u <= 0x7F) {
  485. if (outIdx >= endIdx) break;
  486. heap[outIdx++] = u;
  487. } else if (u <= 0x7FF) {
  488. if (outIdx + 1 >= endIdx) break;
  489. heap[outIdx++] = 0xC0 | (u >> 6);
  490. heap[outIdx++] = 0x80 | (u & 63);
  491. } else if (u <= 0xFFFF) {
  492. if (outIdx + 2 >= endIdx) break;
  493. heap[outIdx++] = 0xE0 | (u >> 12);
  494. heap[outIdx++] = 0x80 | ((u >> 6) & 63);
  495. heap[outIdx++] = 0x80 | (u & 63);
  496. } else {
  497. if (outIdx + 3 >= endIdx) break;
  498. if (u > 0x10FFFF) warnOnce('Invalid Unicode code point 0x' + u.toString(16) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
  499. heap[outIdx++] = 0xF0 | (u >> 18);
  500. heap[outIdx++] = 0x80 | ((u >> 12) & 63);
  501. heap[outIdx++] = 0x80 | ((u >> 6) & 63);
  502. heap[outIdx++] = 0x80 | (u & 63);
  503. }
  504. }
  505. // Null-terminate the pointer to the buffer.
  506. heap[outIdx] = 0;
  507. return outIdx - startIdx;
  508. }
  509. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  510. // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  511. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  512. // Returns the number of bytes written, EXCLUDING the null terminator.
  513. function stringToUTF8(str, outPtr, maxBytesToWrite) {
  514. assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  515. return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite);
  516. }
  517. // Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte.
  518. function lengthBytesUTF8(str) {
  519. var len = 0;
  520. for (var i = 0; i < str.length; ++i) {
  521. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
  522. // See http://unicode.org/faq/utf_bom.html#utf16-3
  523. var c = str.charCodeAt(i); // possibly a lead surrogate
  524. if (c <= 0x7F) {
  525. len++;
  526. } else if (c <= 0x7FF) {
  527. len += 2;
  528. } else if (c >= 0xD800 && c <= 0xDFFF) {
  529. len += 4; ++i;
  530. } else {
  531. len += 3;
  532. }
  533. }
  534. return len;
  535. }
  536. // end include: runtime_strings.js
  537. // Memory management
  538. var HEAP,
  539. /** @type {!ArrayBuffer} */
  540. buffer,
  541. /** @type {!Int8Array} */
  542. HEAP8,
  543. /** @type {!Uint8Array} */
  544. HEAPU8,
  545. /** @type {!Int16Array} */
  546. HEAP16,
  547. /** @type {!Uint16Array} */
  548. HEAPU16,
  549. /** @type {!Int32Array} */
  550. HEAP32,
  551. /** @type {!Uint32Array} */
  552. HEAPU32,
  553. /** @type {!Float32Array} */
  554. HEAPF32,
  555. /** @type {!Float64Array} */
  556. HEAPF64;
  557. function updateGlobalBufferAndViews(buf) {
  558. buffer = buf;
  559. Module['HEAP8'] = HEAP8 = new Int8Array(buf);
  560. Module['HEAP16'] = HEAP16 = new Int16Array(buf);
  561. Module['HEAP32'] = HEAP32 = new Int32Array(buf);
  562. Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf);
  563. Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf);
  564. Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf);
  565. Module['HEAPF32'] = HEAPF32 = new Float32Array(buf);
  566. Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
  567. }
  568. var TOTAL_STACK = 5242880;
  569. if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime')
  570. var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216;legacyModuleProp('INITIAL_MEMORY', 'INITIAL_MEMORY');
  571. assert(INITIAL_MEMORY >= TOTAL_STACK, 'INITIAL_MEMORY should be larger than TOTAL_STACK, was ' + INITIAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')');
  572. // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
  573. assert(typeof Int32Array != 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined,
  574. 'JS engine does not provide full typed array support');
  575. // If memory is defined in wasm, the user can't provide it.
  576. assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally');
  577. assert(INITIAL_MEMORY == 16777216, 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically');
  578. // include: runtime_init_table.js
  579. // In regular non-RELOCATABLE mode the table is exported
  580. // from the wasm module and this will be assigned once
  581. // the exports are available.
  582. var wasmTable;
  583. // end include: runtime_init_table.js
  584. // include: runtime_stack_check.js
  585. // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
  586. function writeStackCookie() {
  587. var max = _emscripten_stack_get_end();
  588. assert((max & 3) == 0);
  589. // The stack grow downwards towards _emscripten_stack_get_end.
  590. // We write cookies to the final two words in the stack and detect if they are
  591. // ever overwritten.
  592. HEAPU32[((max)>>2)] = 0x2135467;
  593. HEAPU32[(((max)+(4))>>2)] = 0x89BACDFE;
  594. // Also test the global address 0 for integrity.
  595. HEAPU32[0] = 0x63736d65; /* 'emsc' */
  596. }
  597. function checkStackCookie() {
  598. if (ABORT) return;
  599. var max = _emscripten_stack_get_end();
  600. var cookie1 = HEAPU32[((max)>>2)];
  601. var cookie2 = HEAPU32[(((max)+(4))>>2)];
  602. if (cookie1 != 0x2135467 || cookie2 != 0x89BACDFE) {
  603. abort('Stack overflow! Stack cookie has been overwritten at 0x' + max.toString(16) + ', expected hex dwords 0x89BACDFE and 0x2135467, but received 0x' + cookie2.toString(16) + ' 0x' + cookie1.toString(16));
  604. }
  605. // Also test the global address 0 for integrity.
  606. if (HEAPU32[0] !== 0x63736d65 /* 'emsc' */) abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
  607. }
  608. // end include: runtime_stack_check.js
  609. // include: runtime_assertions.js
  610. // Endianness check
  611. (function() {
  612. var h16 = new Int16Array(1);
  613. var h8 = new Int8Array(h16.buffer);
  614. h16[0] = 0x6373;
  615. if (h8[0] !== 0x73 || h8[1] !== 0x63) throw 'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)';
  616. })();
  617. // end include: runtime_assertions.js
  618. var __ATPRERUN__ = []; // functions called before the runtime is initialized
  619. var __ATINIT__ = []; // functions called during startup
  620. var __ATEXIT__ = []; // functions called during shutdown
  621. var __ATPOSTRUN__ = []; // functions called after the main() is called
  622. var runtimeInitialized = false;
  623. function keepRuntimeAlive() {
  624. return noExitRuntime;
  625. }
  626. function preRun() {
  627. if (Module['preRun']) {
  628. if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
  629. while (Module['preRun'].length) {
  630. addOnPreRun(Module['preRun'].shift());
  631. }
  632. }
  633. callRuntimeCallbacks(__ATPRERUN__);
  634. }
  635. function initRuntime() {
  636. assert(!runtimeInitialized);
  637. runtimeInitialized = true;
  638. checkStackCookie();
  639. callRuntimeCallbacks(__ATINIT__);
  640. }
  641. function postRun() {
  642. checkStackCookie();
  643. if (Module['postRun']) {
  644. if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
  645. while (Module['postRun'].length) {
  646. addOnPostRun(Module['postRun'].shift());
  647. }
  648. }
  649. callRuntimeCallbacks(__ATPOSTRUN__);
  650. }
  651. function addOnPreRun(cb) {
  652. __ATPRERUN__.unshift(cb);
  653. }
  654. function addOnInit(cb) {
  655. __ATINIT__.unshift(cb);
  656. }
  657. function addOnExit(cb) {
  658. }
  659. function addOnPostRun(cb) {
  660. __ATPOSTRUN__.unshift(cb);
  661. }
  662. // include: runtime_math.js
  663. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
  664. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
  665. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
  666. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
  667. assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  668. assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  669. assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  670. assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  671. // end include: runtime_math.js
  672. // A counter of dependencies for calling run(). If we need to
  673. // do asynchronous work before running, increment this and
  674. // decrement it. Incrementing must happen in a place like
  675. // Module.preRun (used by emcc to add file preloading).
  676. // Note that you can add dependencies in preRun, even though
  677. // it happens right before run - run will be postponed until
  678. // the dependencies are met.
  679. var runDependencies = 0;
  680. var runDependencyWatcher = null;
  681. var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
  682. var runDependencyTracking = {};
  683. function getUniqueRunDependency(id) {
  684. var orig = id;
  685. while (1) {
  686. if (!runDependencyTracking[id]) return id;
  687. id = orig + Math.random();
  688. }
  689. }
  690. function addRunDependency(id) {
  691. runDependencies++;
  692. if (Module['monitorRunDependencies']) {
  693. Module['monitorRunDependencies'](runDependencies);
  694. }
  695. if (id) {
  696. assert(!runDependencyTracking[id]);
  697. runDependencyTracking[id] = 1;
  698. if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
  699. // Check for missing dependencies every few seconds
  700. runDependencyWatcher = setInterval(function() {
  701. if (ABORT) {
  702. clearInterval(runDependencyWatcher);
  703. runDependencyWatcher = null;
  704. return;
  705. }
  706. var shown = false;
  707. for (var dep in runDependencyTracking) {
  708. if (!shown) {
  709. shown = true;
  710. err('still waiting on run dependencies:');
  711. }
  712. err('dependency: ' + dep);
  713. }
  714. if (shown) {
  715. err('(end of list)');
  716. }
  717. }, 10000);
  718. }
  719. } else {
  720. err('warning: run dependency added without ID');
  721. }
  722. }
  723. function removeRunDependency(id) {
  724. runDependencies--;
  725. if (Module['monitorRunDependencies']) {
  726. Module['monitorRunDependencies'](runDependencies);
  727. }
  728. if (id) {
  729. assert(runDependencyTracking[id]);
  730. delete runDependencyTracking[id];
  731. } else {
  732. err('warning: run dependency removed without ID');
  733. }
  734. if (runDependencies == 0) {
  735. if (runDependencyWatcher !== null) {
  736. clearInterval(runDependencyWatcher);
  737. runDependencyWatcher = null;
  738. }
  739. if (dependenciesFulfilled) {
  740. var callback = dependenciesFulfilled;
  741. dependenciesFulfilled = null;
  742. callback(); // can add another dependenciesFulfilled
  743. }
  744. }
  745. }
  746. /** @param {string|number=} what */
  747. function abort(what) {
  748. {
  749. if (Module['onAbort']) {
  750. Module['onAbort'](what);
  751. }
  752. }
  753. what = 'Aborted(' + what + ')';
  754. // TODO(sbc): Should we remove printing and leave it up to whoever
  755. // catches the exception?
  756. err(what);
  757. ABORT = true;
  758. EXITSTATUS = 1;
  759. // Use a wasm runtime error, because a JS error might be seen as a foreign
  760. // exception, which means we'd run destructors on it. We need the error to
  761. // simply make the program stop.
  762. // FIXME This approach does not work in Wasm EH because it currently does not assume
  763. // all RuntimeErrors are from traps; it decides whether a RuntimeError is from
  764. // a trap or not based on a hidden field within the object. So at the moment
  765. // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
  766. // allows this in the wasm spec.
  767. // Suppress closure compiler warning here. Closure compiler's builtin extern
  768. // defintion for WebAssembly.RuntimeError claims it takes no arguments even
  769. // though it can.
  770. // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
  771. /** @suppress {checkTypes} */
  772. var e = new WebAssembly.RuntimeError(what);
  773. // Throw the error whether or not MODULARIZE is set because abort is used
  774. // in code paths apart from instantiation where an exception is expected
  775. // to be thrown when abort is called.
  776. throw e;
  777. }
  778. // {{MEM_INITIALIZER}}
  779. // include: memoryprofiler.js
  780. // end include: memoryprofiler.js
  781. // show errors on likely calls to FS when it was not included
  782. var FS = {
  783. error: function() {
  784. 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');
  785. },
  786. init: function() { FS.error() },
  787. createDataFile: function() { FS.error() },
  788. createPreloadedFile: function() { FS.error() },
  789. createLazyFile: function() { FS.error() },
  790. open: function() { FS.error() },
  791. mkdev: function() { FS.error() },
  792. registerDevice: function() { FS.error() },
  793. analyzePath: function() { FS.error() },
  794. loadFilesFromDB: function() { FS.error() },
  795. ErrnoError: function ErrnoError() { FS.error() },
  796. };
  797. Module['FS_createDataFile'] = FS.createDataFile;
  798. Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
  799. // include: URIUtils.js
  800. // Prefix of data URIs emitted by SINGLE_FILE and related options.
  801. var dataURIPrefix = 'data:application/octet-stream;base64,';
  802. // Indicates whether filename is a base64 data URI.
  803. function isDataURI(filename) {
  804. // Prefix of data URIs emitted by SINGLE_FILE and related options.
  805. return filename.startsWith(dataURIPrefix);
  806. }
  807. // Indicates whether filename is delivered via file protocol (as opposed to http/https)
  808. function isFileURI(filename) {
  809. return filename.startsWith('file://');
  810. }
  811. // end include: URIUtils.js
  812. /** @param {boolean=} fixedasm */
  813. function createExportWrapper(name, fixedasm) {
  814. return function() {
  815. var displayName = name;
  816. var asm = fixedasm;
  817. if (!fixedasm) {
  818. asm = Module['asm'];
  819. }
  820. assert(runtimeInitialized, 'native function `' + displayName + '` called before runtime initialization');
  821. if (!asm[name]) {
  822. assert(asm[name], 'exported native function `' + displayName + '` not found');
  823. }
  824. return asm[name].apply(null, arguments);
  825. };
  826. }
  827. var wasmBinaryFile;
  828. wasmBinaryFile = 'stegano.wasm';
  829. if (!isDataURI(wasmBinaryFile)) {
  830. wasmBinaryFile = locateFile(wasmBinaryFile);
  831. }
  832. function getBinary(file) {
  833. try {
  834. if (file == wasmBinaryFile && wasmBinary) {
  835. return new Uint8Array(wasmBinary);
  836. }
  837. if (readBinary) {
  838. return readBinary(file);
  839. }
  840. throw "both async and sync fetching of the wasm failed";
  841. }
  842. catch (err) {
  843. abort(err);
  844. }
  845. }
  846. function getBinaryPromise() {
  847. // If we don't have the binary yet, try to to load it asynchronously.
  848. // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
  849. // See https://github.com/github/fetch/pull/92#issuecomment-140665932
  850. // Cordova or Electron apps are typically loaded from a file:// url.
  851. // So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
  852. if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
  853. if (typeof fetch == 'function'
  854. && !isFileURI(wasmBinaryFile)
  855. ) {
  856. return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
  857. if (!response['ok']) {
  858. throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
  859. }
  860. return response['arrayBuffer']();
  861. }).catch(function () {
  862. return getBinary(wasmBinaryFile);
  863. });
  864. }
  865. else {
  866. if (readAsync) {
  867. // fetch is not available or url is file => try XHR (readAsync uses XHR internally)
  868. return new Promise(function(resolve, reject) {
  869. readAsync(wasmBinaryFile, function(response) { resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))) }, reject)
  870. });
  871. }
  872. }
  873. }
  874. // Otherwise, getBinary should be able to get it synchronously
  875. return Promise.resolve().then(function() { return getBinary(wasmBinaryFile); });
  876. }
  877. // Create the wasm instance.
  878. // Receives the wasm imports, returns the exports.
  879. function createWasm() {
  880. // prepare imports
  881. var info = {
  882. 'env': asmLibraryArg,
  883. 'wasi_snapshot_preview1': asmLibraryArg,
  884. };
  885. // Load the wasm module and create an instance of using native support in the JS engine.
  886. // handle a generated wasm instance, receiving its exports and
  887. // performing other necessary setup
  888. /** @param {WebAssembly.Module=} module*/
  889. function receiveInstance(instance, module) {
  890. var exports = instance.exports;
  891. Module['asm'] = exports;
  892. wasmMemory = Module['asm']['memory'];
  893. assert(wasmMemory, "memory not found in wasm exports");
  894. // This assertion doesn't hold when emscripten is run in --post-link
  895. // mode.
  896. // TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode.
  897. //assert(wasmMemory.buffer.byteLength === 16777216);
  898. updateGlobalBufferAndViews(wasmMemory.buffer);
  899. wasmTable = Module['asm']['__indirect_function_table'];
  900. assert(wasmTable, "table not found in wasm exports");
  901. addOnInit(Module['asm']['__wasm_call_ctors']);
  902. removeRunDependency('wasm-instantiate');
  903. }
  904. // we can't run yet (except in a pthread, where we have a custom sync instantiator)
  905. addRunDependency('wasm-instantiate');
  906. // Prefer streaming instantiation if available.
  907. // Async compilation can be confusing when an error on the page overwrites Module
  908. // (for example, if the order of elements is wrong, and the one defining Module is
  909. // later), so we save Module and check it later.
  910. var trueModule = Module;
  911. function receiveInstantiationResult(result) {
  912. // 'result' is a ResultObject object which has both the module and instance.
  913. // receiveInstance() will swap in the exports (to Module.asm) so they can be called
  914. assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
  915. trueModule = null;
  916. // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
  917. // When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
  918. receiveInstance(result['instance']);
  919. }
  920. function instantiateArrayBuffer(receiver) {
  921. return getBinaryPromise().then(function(binary) {
  922. return WebAssembly.instantiate(binary, info);
  923. }).then(function (instance) {
  924. return instance;
  925. }).then(receiver, function(reason) {
  926. err('failed to asynchronously prepare wasm: ' + reason);
  927. // Warn on some common problems.
  928. if (isFileURI(wasmBinaryFile)) {
  929. err('warning: Loading from a file URI (' + wasmBinaryFile + ') is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing');
  930. }
  931. abort(reason);
  932. });
  933. }
  934. function instantiateAsync() {
  935. if (!wasmBinary &&
  936. typeof WebAssembly.instantiateStreaming == 'function' &&
  937. !isDataURI(wasmBinaryFile) &&
  938. // Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
  939. !isFileURI(wasmBinaryFile) &&
  940. // Avoid instantiateStreaming() on Node.js environment for now, as while
  941. // Node.js v18.1.0 implements it, it does not have a full fetch()
  942. // implementation yet.
  943. //
  944. // Reference:
  945. // https://github.com/emscripten-core/emscripten/pull/16917
  946. !ENVIRONMENT_IS_NODE &&
  947. typeof fetch == 'function') {
  948. return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
  949. // Suppress closure warning here since the upstream definition for
  950. // instantiateStreaming only allows Promise<Repsponse> rather than
  951. // an actual Response.
  952. // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure is fixed.
  953. /** @suppress {checkTypes} */
  954. var result = WebAssembly.instantiateStreaming(response, info);
  955. return result.then(
  956. receiveInstantiationResult,
  957. function(reason) {
  958. // We expect the most common failure cause to be a bad MIME type for the binary,
  959. // in which case falling back to ArrayBuffer instantiation should work.
  960. err('wasm streaming compile failed: ' + reason);
  961. err('falling back to ArrayBuffer instantiation');
  962. return instantiateArrayBuffer(receiveInstantiationResult);
  963. });
  964. });
  965. } else {
  966. return instantiateArrayBuffer(receiveInstantiationResult);
  967. }
  968. }
  969. // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
  970. // to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
  971. // to any other async startup actions they are performing.
  972. // Also pthreads and wasm workers initialize the wasm instance through this path.
  973. if (Module['instantiateWasm']) {
  974. try {
  975. var exports = Module['instantiateWasm'](info, receiveInstance);
  976. return exports;
  977. } catch(e) {
  978. err('Module.instantiateWasm callback failed with error: ' + e);
  979. return false;
  980. }
  981. }
  982. instantiateAsync();
  983. return {}; // no exports yet; we'll fill them in later
  984. }
  985. // Globals used by JS i64 conversions (see makeSetValue)
  986. var tempDouble;
  987. var tempI64;
  988. // === Body ===
  989. var ASM_CONSTS = {
  990. };
  991. /** @constructor */
  992. function ExitStatus(status) {
  993. this.name = 'ExitStatus';
  994. this.message = 'Program terminated with exit(' + status + ')';
  995. this.status = status;
  996. }
  997. function callRuntimeCallbacks(callbacks) {
  998. while (callbacks.length > 0) {
  999. // Pass the module as the first argument.
  1000. callbacks.shift()(Module);
  1001. }
  1002. }
  1003. function withStackSave(f) {
  1004. var stack = stackSave();
  1005. var ret = f();
  1006. stackRestore(stack);
  1007. return ret;
  1008. }
  1009. function demangle(func) {
  1010. warnOnce('warning: build with -sDEMANGLE_SUPPORT to link in libcxxabi demangling');
  1011. return func;
  1012. }
  1013. function demangleAll(text) {
  1014. var regex =
  1015. /\b_Z[\w\d_]+/g;
  1016. return text.replace(regex,
  1017. function(x) {
  1018. var y = demangle(x);
  1019. return x === y ? x : (y + ' [' + x + ']');
  1020. });
  1021. }
  1022. /**
  1023. * @param {number} ptr
  1024. * @param {string} type
  1025. */
  1026. function getValue(ptr, type = 'i8') {
  1027. if (type.endsWith('*')) type = '*';
  1028. switch (type) {
  1029. case 'i1': return HEAP8[((ptr)>>0)];
  1030. case 'i8': return HEAP8[((ptr)>>0)];
  1031. case 'i16': return HEAP16[((ptr)>>1)];
  1032. case 'i32': return HEAP32[((ptr)>>2)];
  1033. case 'i64': return HEAP32[((ptr)>>2)];
  1034. case 'float': return HEAPF32[((ptr)>>2)];
  1035. case 'double': return HEAPF64[((ptr)>>3)];
  1036. case '*': return HEAPU32[((ptr)>>2)];
  1037. default: abort('invalid type for getValue: ' + type);
  1038. }
  1039. return null;
  1040. }
  1041. function handleException(e) {
  1042. // Certain exception types we do not treat as errors since they are used for
  1043. // internal control flow.
  1044. // 1. ExitStatus, which is thrown by exit()
  1045. // 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others
  1046. // that wish to return to JS event loop.
  1047. if (e instanceof ExitStatus || e == 'unwind') {
  1048. return EXITSTATUS;
  1049. }
  1050. quit_(1, e);
  1051. }
  1052. function jsStackTrace() {
  1053. var error = new Error();
  1054. if (!error.stack) {
  1055. // IE10+ special cases: It does have callstack info, but it is only
  1056. // populated if an Error object is thrown, so try that as a special-case.
  1057. try {
  1058. throw new Error();
  1059. } catch(e) {
  1060. error = e;
  1061. }
  1062. if (!error.stack) {
  1063. return '(no stack trace available)';
  1064. }
  1065. }
  1066. return error.stack.toString();
  1067. }
  1068. /**
  1069. * @param {number} ptr
  1070. * @param {number} value
  1071. * @param {string} type
  1072. */
  1073. function setValue(ptr, value, type = 'i8') {
  1074. if (type.endsWith('*')) type = '*';
  1075. switch (type) {
  1076. case 'i1': HEAP8[((ptr)>>0)] = value; break;
  1077. case 'i8': HEAP8[((ptr)>>0)] = value; break;
  1078. case 'i16': HEAP16[((ptr)>>1)] = value; break;
  1079. case 'i32': HEAP32[((ptr)>>2)] = value; break;
  1080. case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math.min((+(Math.floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((ptr)>>2)] = tempI64[0],HEAP32[(((ptr)+(4))>>2)] = tempI64[1]); break;
  1081. case 'float': HEAPF32[((ptr)>>2)] = value; break;
  1082. case 'double': HEAPF64[((ptr)>>3)] = value; break;
  1083. case '*': HEAPU32[((ptr)>>2)] = value; break;
  1084. default: abort('invalid type for setValue: ' + type);
  1085. }
  1086. }
  1087. function stackTrace() {
  1088. var js = jsStackTrace();
  1089. if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
  1090. return demangleAll(js);
  1091. }
  1092. function warnOnce(text) {
  1093. if (!warnOnce.shown) warnOnce.shown = {};
  1094. if (!warnOnce.shown[text]) {
  1095. warnOnce.shown[text] = 1;
  1096. if (ENVIRONMENT_IS_NODE) text = 'warning: ' + text;
  1097. err(text);
  1098. }
  1099. }
  1100. function writeArrayToMemory(array, buffer) {
  1101. assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)')
  1102. HEAP8.set(array, buffer);
  1103. }
  1104. function ___assert_fail(condition, filename, line, func) {
  1105. abort('Assertion failed: ' + UTF8ToString(condition) + ', at: ' + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
  1106. }
  1107. function _emscripten_memcpy_big(dest, src, num) {
  1108. HEAPU8.copyWithin(dest, src, src + num);
  1109. }
  1110. function getHeapMax() {
  1111. // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
  1112. // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
  1113. // for any code that deals with heap sizes, which would require special
  1114. // casing all heap size related code to treat 0 specially.
  1115. return 2147483648;
  1116. }
  1117. function emscripten_realloc_buffer(size) {
  1118. try {
  1119. // round size grow request up to wasm page size (fixed 64KB per spec)
  1120. wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16); // .grow() takes a delta compared to the previous size
  1121. updateGlobalBufferAndViews(wasmMemory.buffer);
  1122. return 1 /*success*/;
  1123. } catch(e) {
  1124. err('emscripten_realloc_buffer: Attempted to grow heap from ' + buffer.byteLength + ' bytes to ' + size + ' bytes, but got error: ' + e);
  1125. }
  1126. // implicit 0 return to save code size (caller will cast "undefined" into 0
  1127. // anyhow)
  1128. }
  1129. function _emscripten_resize_heap(requestedSize) {
  1130. var oldSize = HEAPU8.length;
  1131. requestedSize = requestedSize >>> 0;
  1132. // With multithreaded builds, races can happen (another thread might increase the size
  1133. // in between), so return a failure, and let the caller retry.
  1134. assert(requestedSize > oldSize);
  1135. // Memory resize rules:
  1136. // 1. Always increase heap size to at least the requested size, rounded up
  1137. // to next page multiple.
  1138. // 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap
  1139. // geometrically: increase the heap size according to
  1140. // MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most
  1141. // overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB).
  1142. // 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap
  1143. // linearly: increase the heap size by at least
  1144. // MEMORY_GROWTH_LINEAR_STEP bytes.
  1145. // 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by
  1146. // MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest
  1147. // 4. If we were unable to allocate as much memory, it may be due to
  1148. // over-eager decision to excessively reserve due to (3) above.
  1149. // Hence if an allocation fails, cut down on the amount of excess
  1150. // growth, in an attempt to succeed to perform a smaller allocation.
  1151. // A limit is set for how much we can grow. We should not exceed that
  1152. // (the wasm binary specifies it, so if we tried, we'd fail anyhow).
  1153. var maxHeapSize = getHeapMax();
  1154. if (requestedSize > maxHeapSize) {
  1155. err('Cannot enlarge memory, asked to go up to ' + requestedSize + ' bytes, but the limit is ' + maxHeapSize + ' bytes!');
  1156. return false;
  1157. }
  1158. let alignUp = (x, multiple) => x + (multiple - x % multiple) % multiple;
  1159. // Loop through potential heap size increases. If we attempt a too eager
  1160. // reservation that fails, cut down on the attempted size and reserve a
  1161. // smaller bump instead. (max 3 times, chosen somewhat arbitrarily)
  1162. for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
  1163. var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); // ensure geometric growth
  1164. // but limit overreserving (default to capping at +96MB overgrowth at most)
  1165. overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296 );
  1166. var newSize = Math.min(maxHeapSize, alignUp(Math.max(requestedSize, overGrownHeapSize), 65536));
  1167. var replacement = emscripten_realloc_buffer(newSize);
  1168. if (replacement) {
  1169. return true;
  1170. }
  1171. }
  1172. err('Failed to grow the heap from ' + oldSize + ' bytes to ' + newSize + ' bytes, not enough memory!');
  1173. return false;
  1174. }
  1175. var SYSCALLS = {varargs:undefined,get:function() {
  1176. assert(SYSCALLS.varargs != undefined);
  1177. SYSCALLS.varargs += 4;
  1178. var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
  1179. return ret;
  1180. },getStr:function(ptr) {
  1181. var ret = UTF8ToString(ptr);
  1182. return ret;
  1183. }};
  1184. function _fd_close(fd) {
  1185. abort('fd_close called without SYSCALLS_REQUIRE_FILESYSTEM');
  1186. }
  1187. function convertI32PairToI53Checked(lo, hi) {
  1188. assert(lo == (lo >>> 0) || lo == (lo|0)); // lo should either be a i32 or a u32
  1189. assert(hi === (hi|0)); // hi should be a i32
  1190. return ((hi + 0x200000) >>> 0 < 0x400001 - !!lo) ? (lo >>> 0) + hi * 4294967296 : NaN;
  1191. }
  1192. function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {
  1193. return 70;
  1194. }
  1195. var printCharBuffers = [null,[],[]];
  1196. function printChar(stream, curr) {
  1197. var buffer = printCharBuffers[stream];
  1198. assert(buffer);
  1199. if (curr === 0 || curr === 10) {
  1200. (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
  1201. buffer.length = 0;
  1202. } else {
  1203. buffer.push(curr);
  1204. }
  1205. }
  1206. function flush_NO_FILESYSTEM() {
  1207. // flush anything remaining in the buffers during shutdown
  1208. _fflush(0);
  1209. if (printCharBuffers[1].length) printChar(1, 10);
  1210. if (printCharBuffers[2].length) printChar(2, 10);
  1211. }
  1212. function _fd_write(fd, iov, iovcnt, pnum) {
  1213. // hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
  1214. var num = 0;
  1215. for (var i = 0; i < iovcnt; i++) {
  1216. var ptr = HEAPU32[((iov)>>2)];
  1217. var len = HEAPU32[(((iov)+(4))>>2)];
  1218. iov += 8;
  1219. for (var j = 0; j < len; j++) {
  1220. printChar(fd, HEAPU8[ptr+j]);
  1221. }
  1222. num += len;
  1223. }
  1224. HEAPU32[((pnum)>>2)] = num;
  1225. return 0;
  1226. }
  1227. function uleb128Encode(n, target) {
  1228. assert(n < 16384);
  1229. if (n < 128) {
  1230. target.push(n);
  1231. } else {
  1232. target.push((n % 128) | 128, n >> 7);
  1233. }
  1234. }
  1235. function sigToWasmTypes(sig) {
  1236. var typeNames = {
  1237. 'i': 'i32',
  1238. 'j': 'i64',
  1239. 'f': 'f32',
  1240. 'd': 'f64',
  1241. 'p': 'i32',
  1242. };
  1243. var type = {
  1244. parameters: [],
  1245. results: sig[0] == 'v' ? [] : [typeNames[sig[0]]]
  1246. };
  1247. for (var i = 1; i < sig.length; ++i) {
  1248. assert(sig[i] in typeNames, 'invalid signature char: ' + sig[i]);
  1249. type.parameters.push(typeNames[sig[i]]);
  1250. }
  1251. return type;
  1252. }
  1253. function convertJsFunctionToWasm(func, sig) {
  1254. // If the type reflection proposal is available, use the new
  1255. // "WebAssembly.Function" constructor.
  1256. // Otherwise, construct a minimal wasm module importing the JS function and
  1257. // re-exporting it.
  1258. if (typeof WebAssembly.Function == "function") {
  1259. return new WebAssembly.Function(sigToWasmTypes(sig), func);
  1260. }
  1261. // The module is static, with the exception of the type section, which is
  1262. // generated based on the signature passed in.
  1263. var typeSectionBody = [
  1264. 0x01, // count: 1
  1265. 0x60, // form: func
  1266. ];
  1267. var sigRet = sig.slice(0, 1);
  1268. var sigParam = sig.slice(1);
  1269. var typeCodes = {
  1270. 'i': 0x7f, // i32
  1271. 'p': 0x7f, // i32
  1272. 'j': 0x7e, // i64
  1273. 'f': 0x7d, // f32
  1274. 'd': 0x7c, // f64
  1275. };
  1276. // Parameters, length + signatures
  1277. uleb128Encode(sigParam.length, typeSectionBody);
  1278. for (var i = 0; i < sigParam.length; ++i) {
  1279. assert(sigParam[i] in typeCodes, 'invalid signature char: ' + sigParam[i]);
  1280. typeSectionBody.push(typeCodes[sigParam[i]]);
  1281. }
  1282. // Return values, length + signatures
  1283. // With no multi-return in MVP, either 0 (void) or 1 (anything else)
  1284. if (sigRet == 'v') {
  1285. typeSectionBody.push(0x00);
  1286. } else {
  1287. typeSectionBody.push(0x01, typeCodes[sigRet]);
  1288. }
  1289. // Rest of the module is static
  1290. var bytes = [
  1291. 0x00, 0x61, 0x73, 0x6d, // magic ("\0asm")
  1292. 0x01, 0x00, 0x00, 0x00, // version: 1
  1293. 0x01, // Type section code
  1294. ];
  1295. // Write the overall length of the type section followed by the body
  1296. uleb128Encode(typeSectionBody.length, bytes);
  1297. bytes.push.apply(bytes, typeSectionBody);
  1298. // The rest of the module is static
  1299. bytes.push(
  1300. 0x02, 0x07, // import section
  1301. // (import "e" "f" (func 0 (type 0)))
  1302. 0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00,
  1303. 0x07, 0x05, // export section
  1304. // (export "f" (func 0 (type 0)))
  1305. 0x01, 0x01, 0x66, 0x00, 0x00,
  1306. );
  1307. // We can compile this wasm module synchronously because it is very small.
  1308. // This accepts an import (at "e.f"), that it reroutes to an export (at "f")
  1309. var module = new WebAssembly.Module(new Uint8Array(bytes));
  1310. var instance = new WebAssembly.Instance(module, { 'e': { 'f': func } });
  1311. var wrappedFunc = instance.exports['f'];
  1312. return wrappedFunc;
  1313. }
  1314. var wasmTableMirror = [];
  1315. function getWasmTableEntry(funcPtr) {
  1316. var func = wasmTableMirror[funcPtr];
  1317. if (!func) {
  1318. if (funcPtr >= wasmTableMirror.length) wasmTableMirror.length = funcPtr + 1;
  1319. wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr);
  1320. }
  1321. assert(wasmTable.get(funcPtr) == func, "JavaScript-side Wasm function table mirror is out of date!");
  1322. return func;
  1323. }
  1324. function updateTableMap(offset, count) {
  1325. if (functionsInTableMap) {
  1326. for (var i = offset; i < offset + count; i++) {
  1327. var item = getWasmTableEntry(i);
  1328. // Ignore null values.
  1329. if (item) {
  1330. functionsInTableMap.set(item, i);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. var functionsInTableMap = undefined;
  1336. var freeTableIndexes = [];
  1337. function getEmptyTableSlot() {
  1338. // Reuse a free index if there is one, otherwise grow.
  1339. if (freeTableIndexes.length) {
  1340. return freeTableIndexes.pop();
  1341. }
  1342. // Grow the table
  1343. try {
  1344. wasmTable.grow(1);
  1345. } catch (err) {
  1346. if (!(err instanceof RangeError)) {
  1347. throw err;
  1348. }
  1349. throw 'Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.';
  1350. }
  1351. return wasmTable.length - 1;
  1352. }
  1353. function setWasmTableEntry(idx, func) {
  1354. wasmTable.set(idx, func);
  1355. // With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overriden to return wrapped
  1356. // functions so we need to call it here to retrieve the potential wrapper correctly
  1357. // instead of just storing 'func' directly into wasmTableMirror
  1358. wasmTableMirror[idx] = wasmTable.get(idx);
  1359. }
  1360. /** @param {string=} sig */
  1361. function addFunction(func, sig) {
  1362. assert(typeof func != 'undefined');
  1363. // Check if the function is already in the table, to ensure each function
  1364. // gets a unique index. First, create the map if this is the first use.
  1365. if (!functionsInTableMap) {
  1366. functionsInTableMap = new WeakMap();
  1367. updateTableMap(0, wasmTable.length);
  1368. }
  1369. if (functionsInTableMap.has(func)) {
  1370. return functionsInTableMap.get(func);
  1371. }
  1372. // It's not in the table, add it now.
  1373. var ret = getEmptyTableSlot();
  1374. // Set the new value.
  1375. try {
  1376. // Attempting to call this with JS function will cause of table.set() to fail
  1377. setWasmTableEntry(ret, func);
  1378. } catch (err) {
  1379. if (!(err instanceof TypeError)) {
  1380. throw err;
  1381. }
  1382. assert(typeof sig != 'undefined', 'Missing signature argument to addFunction: ' + func);
  1383. var wrapped = convertJsFunctionToWasm(func, sig);
  1384. setWasmTableEntry(ret, wrapped);
  1385. }
  1386. functionsInTableMap.set(func, ret);
  1387. return ret;
  1388. }
  1389. function removeFunction(index) {
  1390. functionsInTableMap.delete(getWasmTableEntry(index));
  1391. freeTableIndexes.push(index);
  1392. }
  1393. var ALLOC_NORMAL = 0;
  1394. var ALLOC_STACK = 1;
  1395. function allocate(slab, allocator) {
  1396. var ret;
  1397. assert(typeof allocator == 'number', 'allocate no longer takes a type argument')
  1398. assert(typeof slab != 'number', 'allocate no longer takes a number as arg0')
  1399. if (allocator == ALLOC_STACK) {
  1400. ret = stackAlloc(slab.length);
  1401. } else {
  1402. ret = _malloc(slab.length);
  1403. }
  1404. if (!slab.subarray && !slab.slice) {
  1405. slab = new Uint8Array(slab);
  1406. }
  1407. HEAPU8.set(slab, ret);
  1408. return ret;
  1409. }
  1410. function AsciiToString(ptr) {
  1411. var str = '';
  1412. while (1) {
  1413. var ch = HEAPU8[((ptr++)>>0)];
  1414. if (!ch) return str;
  1415. str += String.fromCharCode(ch);
  1416. }
  1417. }
  1418. /** @param {boolean=} dontAddNull */
  1419. function writeAsciiToMemory(str, buffer, dontAddNull) {
  1420. for (var i = 0; i < str.length; ++i) {
  1421. assert(str.charCodeAt(i) === (str.charCodeAt(i) & 0xff));
  1422. HEAP8[((buffer++)>>0)] = str.charCodeAt(i);
  1423. }
  1424. // Null-terminate the pointer to the HEAP.
  1425. if (!dontAddNull) HEAP8[((buffer)>>0)] = 0;
  1426. }
  1427. function stringToAscii(str, outPtr) {
  1428. return writeAsciiToMemory(str, outPtr, false);
  1429. }
  1430. var UTF16Decoder = typeof TextDecoder != 'undefined' ? new TextDecoder('utf-16le') : undefined;;
  1431. function UTF16ToString(ptr, maxBytesToRead) {
  1432. assert(ptr % 2 == 0, 'Pointer passed to UTF16ToString must be aligned to two bytes!');
  1433. var endPtr = ptr;
  1434. // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
  1435. // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
  1436. var idx = endPtr >> 1;
  1437. var maxIdx = idx + maxBytesToRead / 2;
  1438. // If maxBytesToRead is not passed explicitly, it will be undefined, and this
  1439. // will always evaluate to true. This saves on code size.
  1440. while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx;
  1441. endPtr = idx << 1;
  1442. if (endPtr - ptr > 32 && UTF16Decoder) {
  1443. return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
  1444. } else {
  1445. var str = '';
  1446. // If maxBytesToRead is not passed explicitly, it will be undefined, and the for-loop's condition
  1447. // will always evaluate to true. The loop is then terminated on the first null char.
  1448. for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
  1449. var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
  1450. if (codeUnit == 0) break;
  1451. // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
  1452. str += String.fromCharCode(codeUnit);
  1453. }
  1454. return str;
  1455. }
  1456. }
  1457. function stringToUTF16(str, outPtr, maxBytesToWrite) {
  1458. assert(outPtr % 2 == 0, 'Pointer passed to stringToUTF16 must be aligned to two bytes!');
  1459. assert(typeof maxBytesToWrite == 'number', 'stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  1460. // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
  1461. if (maxBytesToWrite === undefined) {
  1462. maxBytesToWrite = 0x7FFFFFFF;
  1463. }
  1464. if (maxBytesToWrite < 2) return 0;
  1465. maxBytesToWrite -= 2; // Null terminator.
  1466. var startPtr = outPtr;
  1467. var numCharsToWrite = (maxBytesToWrite < str.length*2) ? (maxBytesToWrite / 2) : str.length;
  1468. for (var i = 0; i < numCharsToWrite; ++i) {
  1469. // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
  1470. var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
  1471. HEAP16[((outPtr)>>1)] = codeUnit;
  1472. outPtr += 2;
  1473. }
  1474. // Null-terminate the pointer to the HEAP.
  1475. HEAP16[((outPtr)>>1)] = 0;
  1476. return outPtr - startPtr;
  1477. }
  1478. function lengthBytesUTF16(str) {
  1479. return str.length*2;
  1480. }
  1481. function UTF32ToString(ptr, maxBytesToRead) {
  1482. assert(ptr % 4 == 0, 'Pointer passed to UTF32ToString must be aligned to four bytes!');
  1483. var i = 0;
  1484. var str = '';
  1485. // If maxBytesToRead is not passed explicitly, it will be undefined, and this
  1486. // will always evaluate to true. This saves on code size.
  1487. while (!(i >= maxBytesToRead / 4)) {
  1488. var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
  1489. if (utf32 == 0) break;
  1490. ++i;
  1491. // Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
  1492. // See http://unicode.org/faq/utf_bom.html#utf16-3
  1493. if (utf32 >= 0x10000) {
  1494. var ch = utf32 - 0x10000;
  1495. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  1496. } else {
  1497. str += String.fromCharCode(utf32);
  1498. }
  1499. }
  1500. return str;
  1501. }
  1502. function stringToUTF32(str, outPtr, maxBytesToWrite) {
  1503. assert(outPtr % 4 == 0, 'Pointer passed to stringToUTF32 must be aligned to four bytes!');
  1504. assert(typeof maxBytesToWrite == 'number', 'stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  1505. // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
  1506. if (maxBytesToWrite === undefined) {
  1507. maxBytesToWrite = 0x7FFFFFFF;
  1508. }
  1509. if (maxBytesToWrite < 4) return 0;
  1510. var startPtr = outPtr;
  1511. var endPtr = startPtr + maxBytesToWrite - 4;
  1512. for (var i = 0; i < str.length; ++i) {
  1513. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
  1514. // See http://unicode.org/faq/utf_bom.html#utf16-3
  1515. var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
  1516. if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
  1517. var trailSurrogate = str.charCodeAt(++i);
  1518. codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
  1519. }
  1520. HEAP32[((outPtr)>>2)] = codeUnit;
  1521. outPtr += 4;
  1522. if (outPtr + 4 > endPtr) break;
  1523. }
  1524. // Null-terminate the pointer to the HEAP.
  1525. HEAP32[((outPtr)>>2)] = 0;
  1526. return outPtr - startPtr;
  1527. }
  1528. function lengthBytesUTF32(str) {
  1529. var len = 0;
  1530. for (var i = 0; i < str.length; ++i) {
  1531. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
  1532. // See http://unicode.org/faq/utf_bom.html#utf16-3
  1533. var codeUnit = str.charCodeAt(i);
  1534. if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate.
  1535. len += 4;
  1536. }
  1537. return len;
  1538. }
  1539. function allocateUTF8(str) {
  1540. var size = lengthBytesUTF8(str) + 1;
  1541. var ret = _malloc(size);
  1542. if (ret) stringToUTF8Array(str, HEAP8, ret, size);
  1543. return ret;
  1544. }
  1545. function allocateUTF8OnStack(str) {
  1546. var size = lengthBytesUTF8(str) + 1;
  1547. var ret = stackAlloc(size);
  1548. stringToUTF8Array(str, HEAP8, ret, size);
  1549. return ret;
  1550. }
  1551. /** @deprecated @param {boolean=} dontAddNull */
  1552. function writeStringToMemory(string, buffer, dontAddNull) {
  1553. warnOnce('writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!');
  1554. var /** @type {number} */ lastChar, /** @type {number} */ end;
  1555. if (dontAddNull) {
  1556. // stringToUTF8Array always appends null. If we don't want to do that, remember the
  1557. // character that existed at the location where the null will be placed, and restore
  1558. // that after the write (below).
  1559. end = buffer + lengthBytesUTF8(string);
  1560. lastChar = HEAP8[end];
  1561. }
  1562. stringToUTF8(string, buffer, Infinity);
  1563. if (dontAddNull) HEAP8[end] = lastChar; // Restore the value under the null character.
  1564. }
  1565. /** @type {function(string, boolean=, number=)} */
  1566. function intArrayFromString(stringy, dontAddNull, length) {
  1567. var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
  1568. var u8array = new Array(len);
  1569. var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
  1570. if (dontAddNull) u8array.length = numBytesWritten;
  1571. return u8array;
  1572. }
  1573. function intArrayToString(array) {
  1574. var ret = [];
  1575. for (var i = 0; i < array.length; i++) {
  1576. var chr = array[i];
  1577. if (chr > 0xFF) {
  1578. if (ASSERTIONS) {
  1579. assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
  1580. }
  1581. chr &= 0xFF;
  1582. }
  1583. ret.push(String.fromCharCode(chr));
  1584. }
  1585. return ret.join('');
  1586. }
  1587. function getCFunc(ident) {
  1588. var func = Module['_' + ident]; // closure exported function
  1589. assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
  1590. return func;
  1591. }
  1592. /**
  1593. * @param {string|null=} returnType
  1594. * @param {Array=} argTypes
  1595. * @param {Arguments|Array=} args
  1596. * @param {Object=} opts
  1597. */
  1598. function ccall(ident, returnType, argTypes, args, opts) {
  1599. // For fast lookup of conversion functions
  1600. var toC = {
  1601. 'string': (str) => {
  1602. var ret = 0;
  1603. if (str !== null && str !== undefined && str !== 0) { // null string
  1604. // at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
  1605. var len = (str.length << 2) + 1;
  1606. ret = stackAlloc(len);
  1607. stringToUTF8(str, ret, len);
  1608. }
  1609. return ret;
  1610. },
  1611. 'array': (arr) => {
  1612. var ret = stackAlloc(arr.length);
  1613. writeArrayToMemory(arr, ret);
  1614. return ret;
  1615. }
  1616. };
  1617. function convertReturnValue(ret) {
  1618. if (returnType === 'string') {
  1619. return UTF8ToString(ret);
  1620. }
  1621. if (returnType === 'boolean') return Boolean(ret);
  1622. return ret;
  1623. }
  1624. var func = getCFunc(ident);
  1625. var cArgs = [];
  1626. var stack = 0;
  1627. assert(returnType !== 'array', 'Return type should not be "array".');
  1628. if (args) {
  1629. for (var i = 0; i < args.length; i++) {
  1630. var converter = toC[argTypes[i]];
  1631. if (converter) {
  1632. if (stack === 0) stack = stackSave();
  1633. cArgs[i] = converter(args[i]);
  1634. } else {
  1635. cArgs[i] = args[i];
  1636. }
  1637. }
  1638. }
  1639. var ret = func.apply(null, cArgs);
  1640. function onDone(ret) {
  1641. if (stack !== 0) stackRestore(stack);
  1642. return convertReturnValue(ret);
  1643. }
  1644. ret = onDone(ret);
  1645. return ret;
  1646. }
  1647. /**
  1648. * @param {string=} returnType
  1649. * @param {Array=} argTypes
  1650. * @param {Object=} opts
  1651. */
  1652. function cwrap(ident, returnType, argTypes, opts) {
  1653. return function() {
  1654. return ccall(ident, returnType, argTypes, arguments, opts);
  1655. }
  1656. }
  1657. var ASSERTIONS = true;
  1658. function checkIncomingModuleAPI() {
  1659. ignoredModuleProp('fetchSettings');
  1660. }
  1661. var asmLibraryArg = {
  1662. "__assert_fail": ___assert_fail,
  1663. "emscripten_memcpy_big": _emscripten_memcpy_big,
  1664. "emscripten_resize_heap": _emscripten_resize_heap,
  1665. "fd_close": _fd_close,
  1666. "fd_seek": _fd_seek,
  1667. "fd_write": _fd_write
  1668. };
  1669. var asm = createWasm();
  1670. /** @type {function(...*):?} */
  1671. var ___wasm_call_ctors = Module["___wasm_call_ctors"] = createExportWrapper("__wasm_call_ctors");
  1672. /** @type {function(...*):?} */
  1673. var _free = Module["_free"] = createExportWrapper("free");
  1674. /** @type {function(...*):?} */
  1675. var _malloc = Module["_malloc"] = createExportWrapper("malloc");
  1676. /** @type {function(...*):?} */
  1677. var _getcapacity = Module["_getcapacity"] = createExportWrapper("getcapacity");
  1678. /** @type {function(...*):?} */
  1679. var _decode = Module["_decode"] = createExportWrapper("decode");
  1680. /** @type {function(...*):?} */
  1681. var _encode = Module["_encode"] = createExportWrapper("encode");
  1682. /** @type {function(...*):?} */
  1683. var ___errno_location = Module["___errno_location"] = createExportWrapper("__errno_location");
  1684. /** @type {function(...*):?} */
  1685. var _fflush = Module["_fflush"] = createExportWrapper("fflush");
  1686. /** @type {function(...*):?} */
  1687. var _emscripten_stack_init = Module["_emscripten_stack_init"] = function() {
  1688. return (_emscripten_stack_init = Module["_emscripten_stack_init"] = Module["asm"]["emscripten_stack_init"]).apply(null, arguments);
  1689. };
  1690. /** @type {function(...*):?} */
  1691. var _emscripten_stack_get_free = Module["_emscripten_stack_get_free"] = function() {
  1692. return (_emscripten_stack_get_free = Module["_emscripten_stack_get_free"] = Module["asm"]["emscripten_stack_get_free"]).apply(null, arguments);
  1693. };
  1694. /** @type {function(...*):?} */
  1695. var _emscripten_stack_get_base = Module["_emscripten_stack_get_base"] = function() {
  1696. return (_emscripten_stack_get_base = Module["_emscripten_stack_get_base"] = Module["asm"]["emscripten_stack_get_base"]).apply(null, arguments);
  1697. };
  1698. /** @type {function(...*):?} */
  1699. var _emscripten_stack_get_end = Module["_emscripten_stack_get_end"] = function() {
  1700. return (_emscripten_stack_get_end = Module["_emscripten_stack_get_end"] = Module["asm"]["emscripten_stack_get_end"]).apply(null, arguments);
  1701. };
  1702. /** @type {function(...*):?} */
  1703. var stackSave = Module["stackSave"] = createExportWrapper("stackSave");
  1704. /** @type {function(...*):?} */
  1705. var stackRestore = Module["stackRestore"] = createExportWrapper("stackRestore");
  1706. /** @type {function(...*):?} */
  1707. var stackAlloc = Module["stackAlloc"] = createExportWrapper("stackAlloc");
  1708. /** @type {function(...*):?} */
  1709. var dynCall_jiiiii = Module["dynCall_jiiiii"] = createExportWrapper("dynCall_jiiiii");
  1710. /** @type {function(...*):?} */
  1711. var dynCall_jiji = Module["dynCall_jiji"] = createExportWrapper("dynCall_jiji");
  1712. // === Auto-generated postamble setup entry stuff ===
  1713. Module["ccall"] = ccall;
  1714. Module["cwrap"] = cwrap;
  1715. var unexportedRuntimeSymbols = [
  1716. 'run',
  1717. 'UTF8ArrayToString',
  1718. 'UTF8ToString',
  1719. 'stringToUTF8Array',
  1720. 'stringToUTF8',
  1721. 'lengthBytesUTF8',
  1722. 'addOnPreRun',
  1723. 'addOnInit',
  1724. 'addOnPreMain',
  1725. 'addOnExit',
  1726. 'addOnPostRun',
  1727. 'addRunDependency',
  1728. 'removeRunDependency',
  1729. 'FS_createFolder',
  1730. 'FS_createPath',
  1731. 'FS_createDataFile',
  1732. 'FS_createPreloadedFile',
  1733. 'FS_createLazyFile',
  1734. 'FS_createLink',
  1735. 'FS_createDevice',
  1736. 'FS_unlink',
  1737. 'getLEB',
  1738. 'getFunctionTables',
  1739. 'alignFunctionTables',
  1740. 'registerFunctions',
  1741. 'prettyPrint',
  1742. 'getCompilerSetting',
  1743. 'print',
  1744. 'printErr',
  1745. 'callMain',
  1746. 'abort',
  1747. 'keepRuntimeAlive',
  1748. 'wasmMemory',
  1749. 'stackAlloc',
  1750. 'stackSave',
  1751. 'stackRestore',
  1752. 'getTempRet0',
  1753. 'setTempRet0',
  1754. 'writeStackCookie',
  1755. 'checkStackCookie',
  1756. 'ptrToString',
  1757. 'zeroMemory',
  1758. 'stringToNewUTF8',
  1759. 'exitJS',
  1760. 'getHeapMax',
  1761. 'emscripten_realloc_buffer',
  1762. 'ENV',
  1763. 'ERRNO_CODES',
  1764. 'ERRNO_MESSAGES',
  1765. 'setErrNo',
  1766. 'inetPton4',
  1767. 'inetNtop4',
  1768. 'inetPton6',
  1769. 'inetNtop6',
  1770. 'readSockaddr',
  1771. 'writeSockaddr',
  1772. 'DNS',
  1773. 'getHostByName',
  1774. 'Protocols',
  1775. 'Sockets',
  1776. 'getRandomDevice',
  1777. 'warnOnce',
  1778. 'traverseStack',
  1779. 'UNWIND_CACHE',
  1780. 'convertPCtoSourceLocation',
  1781. 'readAsmConstArgsArray',
  1782. 'readAsmConstArgs',
  1783. 'mainThreadEM_ASM',
  1784. 'jstoi_q',
  1785. 'jstoi_s',
  1786. 'getExecutableName',
  1787. 'listenOnce',
  1788. 'autoResumeAudioContext',
  1789. 'dynCallLegacy',
  1790. 'getDynCaller',
  1791. 'dynCall',
  1792. 'handleException',
  1793. 'runtimeKeepalivePush',
  1794. 'runtimeKeepalivePop',
  1795. 'callUserCallback',
  1796. 'maybeExit',
  1797. 'safeSetTimeout',
  1798. 'asmjsMangle',
  1799. 'asyncLoad',
  1800. 'alignMemory',
  1801. 'mmapAlloc',
  1802. 'writeI53ToI64',
  1803. 'writeI53ToI64Clamped',
  1804. 'writeI53ToI64Signaling',
  1805. 'writeI53ToU64Clamped',
  1806. 'writeI53ToU64Signaling',
  1807. 'readI53FromI64',
  1808. 'readI53FromU64',
  1809. 'convertI32PairToI53',
  1810. 'convertI32PairToI53Checked',
  1811. 'convertU32PairToI53',
  1812. 'getCFunc',
  1813. 'uleb128Encode',
  1814. 'sigToWasmTypes',
  1815. 'convertJsFunctionToWasm',
  1816. 'freeTableIndexes',
  1817. 'functionsInTableMap',
  1818. 'getEmptyTableSlot',
  1819. 'updateTableMap',
  1820. 'addFunction',
  1821. 'removeFunction',
  1822. 'reallyNegative',
  1823. 'unSign',
  1824. 'strLen',
  1825. 'reSign',
  1826. 'formatString',
  1827. 'setValue',
  1828. 'getValue',
  1829. 'PATH',
  1830. 'PATH_FS',
  1831. 'intArrayFromString',
  1832. 'intArrayToString',
  1833. 'AsciiToString',
  1834. 'stringToAscii',
  1835. 'UTF16Decoder',
  1836. 'UTF16ToString',
  1837. 'stringToUTF16',
  1838. 'lengthBytesUTF16',
  1839. 'UTF32ToString',
  1840. 'stringToUTF32',
  1841. 'lengthBytesUTF32',
  1842. 'allocateUTF8',
  1843. 'allocateUTF8OnStack',
  1844. 'writeStringToMemory',
  1845. 'writeArrayToMemory',
  1846. 'writeAsciiToMemory',
  1847. 'SYSCALLS',
  1848. 'getSocketFromFD',
  1849. 'getSocketAddress',
  1850. 'JSEvents',
  1851. 'registerKeyEventCallback',
  1852. 'specialHTMLTargets',
  1853. 'maybeCStringToJsString',
  1854. 'findEventTarget',
  1855. 'findCanvasEventTarget',
  1856. 'getBoundingClientRect',
  1857. 'fillMouseEventData',
  1858. 'registerMouseEventCallback',
  1859. 'registerWheelEventCallback',
  1860. 'registerUiEventCallback',
  1861. 'registerFocusEventCallback',
  1862. 'fillDeviceOrientationEventData',
  1863. 'registerDeviceOrientationEventCallback',
  1864. 'fillDeviceMotionEventData',
  1865. 'registerDeviceMotionEventCallback',
  1866. 'screenOrientation',
  1867. 'fillOrientationChangeEventData',
  1868. 'registerOrientationChangeEventCallback',
  1869. 'fillFullscreenChangeEventData',
  1870. 'registerFullscreenChangeEventCallback',
  1871. 'JSEvents_requestFullscreen',
  1872. 'JSEvents_resizeCanvasForFullscreen',
  1873. 'registerRestoreOldStyle',
  1874. 'hideEverythingExceptGivenElement',
  1875. 'restoreHiddenElements',
  1876. 'setLetterbox',
  1877. 'currentFullscreenStrategy',
  1878. 'restoreOldWindowedStyle',
  1879. 'softFullscreenResizeWebGLRenderTarget',
  1880. 'doRequestFullscreen',
  1881. 'fillPointerlockChangeEventData',
  1882. 'registerPointerlockChangeEventCallback',
  1883. 'registerPointerlockErrorEventCallback',
  1884. 'requestPointerLock',
  1885. 'fillVisibilityChangeEventData',
  1886. 'registerVisibilityChangeEventCallback',
  1887. 'registerTouchEventCallback',
  1888. 'fillGamepadEventData',
  1889. 'registerGamepadEventCallback',
  1890. 'registerBeforeUnloadEventCallback',
  1891. 'fillBatteryEventData',
  1892. 'battery',
  1893. 'registerBatteryEventCallback',
  1894. 'setCanvasElementSize',
  1895. 'getCanvasElementSize',
  1896. 'demangle',
  1897. 'demangleAll',
  1898. 'jsStackTrace',
  1899. 'stackTrace',
  1900. 'ExitStatus',
  1901. 'getEnvStrings',
  1902. 'checkWasiClock',
  1903. 'flush_NO_FILESYSTEM',
  1904. 'dlopenMissingError',
  1905. 'setImmediateWrapped',
  1906. 'clearImmediateWrapped',
  1907. 'polyfillSetImmediate',
  1908. 'uncaughtExceptionCount',
  1909. 'exceptionLast',
  1910. 'exceptionCaught',
  1911. 'ExceptionInfo',
  1912. 'exception_addRef',
  1913. 'exception_decRef',
  1914. 'Browser',
  1915. 'setMainLoop',
  1916. 'wget',
  1917. 'FS',
  1918. 'MEMFS',
  1919. 'TTY',
  1920. 'PIPEFS',
  1921. 'SOCKFS',
  1922. '_setNetworkCallback',
  1923. 'tempFixedLengthArray',
  1924. 'miniTempWebGLFloatBuffers',
  1925. 'heapObjectForWebGLType',
  1926. 'heapAccessShiftForWebGLHeap',
  1927. 'GL',
  1928. 'emscriptenWebGLGet',
  1929. 'computeUnpackAlignedImageSize',
  1930. 'emscriptenWebGLGetTexPixelData',
  1931. 'emscriptenWebGLGetUniform',
  1932. 'webglGetUniformLocation',
  1933. 'webglPrepareUniformLocationsBeforeFirstUse',
  1934. 'webglGetLeftBracePos',
  1935. 'emscriptenWebGLGetVertexAttrib',
  1936. 'writeGLArray',
  1937. 'AL',
  1938. 'SDL_unicode',
  1939. 'SDL_ttfContext',
  1940. 'SDL_audio',
  1941. 'SDL',
  1942. 'SDL_gfx',
  1943. 'GLUT',
  1944. 'EGL',
  1945. 'GLFW_Window',
  1946. 'GLFW',
  1947. 'GLEW',
  1948. 'IDBStore',
  1949. 'runAndAbortIfError',
  1950. 'ALLOC_NORMAL',
  1951. 'ALLOC_STACK',
  1952. 'allocate',
  1953. ];
  1954. unexportedRuntimeSymbols.forEach(unexportedRuntimeSymbol);
  1955. var missingLibrarySymbols = [
  1956. 'ptrToString',
  1957. 'zeroMemory',
  1958. 'stringToNewUTF8',
  1959. 'exitJS',
  1960. 'setErrNo',
  1961. 'inetPton4',
  1962. 'inetNtop4',
  1963. 'inetPton6',
  1964. 'inetNtop6',
  1965. 'readSockaddr',
  1966. 'writeSockaddr',
  1967. 'getHostByName',
  1968. 'getRandomDevice',
  1969. 'traverseStack',
  1970. 'convertPCtoSourceLocation',
  1971. 'readAsmConstArgs',
  1972. 'mainThreadEM_ASM',
  1973. 'jstoi_q',
  1974. 'jstoi_s',
  1975. 'getExecutableName',
  1976. 'listenOnce',
  1977. 'autoResumeAudioContext',
  1978. 'dynCallLegacy',
  1979. 'getDynCaller',
  1980. 'dynCall',
  1981. 'runtimeKeepalivePush',
  1982. 'runtimeKeepalivePop',
  1983. 'callUserCallback',
  1984. 'maybeExit',
  1985. 'safeSetTimeout',
  1986. 'asmjsMangle',
  1987. 'asyncLoad',
  1988. 'alignMemory',
  1989. 'mmapAlloc',
  1990. 'writeI53ToI64',
  1991. 'writeI53ToI64Clamped',
  1992. 'writeI53ToI64Signaling',
  1993. 'writeI53ToU64Clamped',
  1994. 'writeI53ToU64Signaling',
  1995. 'readI53FromI64',
  1996. 'readI53FromU64',
  1997. 'convertI32PairToI53',
  1998. 'convertU32PairToI53',
  1999. 'reallyNegative',
  2000. 'unSign',
  2001. 'strLen',
  2002. 'reSign',
  2003. 'formatString',
  2004. 'getSocketFromFD',
  2005. 'getSocketAddress',
  2006. 'registerKeyEventCallback',
  2007. 'maybeCStringToJsString',
  2008. 'findEventTarget',
  2009. 'findCanvasEventTarget',
  2010. 'getBoundingClientRect',
  2011. 'fillMouseEventData',
  2012. 'registerMouseEventCallback',
  2013. 'registerWheelEventCallback',
  2014. 'registerUiEventCallback',
  2015. 'registerFocusEventCallback',
  2016. 'fillDeviceOrientationEventData',
  2017. 'registerDeviceOrientationEventCallback',
  2018. 'fillDeviceMotionEventData',
  2019. 'registerDeviceMotionEventCallback',
  2020. 'screenOrientation',
  2021. 'fillOrientationChangeEventData',
  2022. 'registerOrientationChangeEventCallback',
  2023. 'fillFullscreenChangeEventData',
  2024. 'registerFullscreenChangeEventCallback',
  2025. 'JSEvents_requestFullscreen',
  2026. 'JSEvents_resizeCanvasForFullscreen',
  2027. 'registerRestoreOldStyle',
  2028. 'hideEverythingExceptGivenElement',
  2029. 'restoreHiddenElements',
  2030. 'setLetterbox',
  2031. 'softFullscreenResizeWebGLRenderTarget',
  2032. 'doRequestFullscreen',
  2033. 'fillPointerlockChangeEventData',
  2034. 'registerPointerlockChangeEventCallback',
  2035. 'registerPointerlockErrorEventCallback',
  2036. 'requestPointerLock',
  2037. 'fillVisibilityChangeEventData',
  2038. 'registerVisibilityChangeEventCallback',
  2039. 'registerTouchEventCallback',
  2040. 'fillGamepadEventData',
  2041. 'registerGamepadEventCallback',
  2042. 'registerBeforeUnloadEventCallback',
  2043. 'fillBatteryEventData',
  2044. 'battery',
  2045. 'registerBatteryEventCallback',
  2046. 'setCanvasElementSize',
  2047. 'getCanvasElementSize',
  2048. 'getEnvStrings',
  2049. 'checkWasiClock',
  2050. 'setImmediateWrapped',
  2051. 'clearImmediateWrapped',
  2052. 'polyfillSetImmediate',
  2053. 'ExceptionInfo',
  2054. 'exception_addRef',
  2055. 'exception_decRef',
  2056. 'setMainLoop',
  2057. '_setNetworkCallback',
  2058. 'heapObjectForWebGLType',
  2059. 'heapAccessShiftForWebGLHeap',
  2060. 'emscriptenWebGLGet',
  2061. 'computeUnpackAlignedImageSize',
  2062. 'emscriptenWebGLGetTexPixelData',
  2063. 'emscriptenWebGLGetUniform',
  2064. 'webglGetUniformLocation',
  2065. 'webglPrepareUniformLocationsBeforeFirstUse',
  2066. 'webglGetLeftBracePos',
  2067. 'emscriptenWebGLGetVertexAttrib',
  2068. 'writeGLArray',
  2069. 'SDL_unicode',
  2070. 'SDL_ttfContext',
  2071. 'SDL_audio',
  2072. 'GLFW_Window',
  2073. 'runAndAbortIfError',
  2074. ];
  2075. missingLibrarySymbols.forEach(missingLibrarySymbol)
  2076. var calledRun;
  2077. dependenciesFulfilled = function runCaller() {
  2078. // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
  2079. if (!calledRun) run();
  2080. if (!calledRun) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
  2081. };
  2082. function stackCheckInit() {
  2083. // This is normally called automatically during __wasm_call_ctors but need to
  2084. // get these values before even running any of the ctors so we call it redundantly
  2085. // here.
  2086. _emscripten_stack_init();
  2087. // TODO(sbc): Move writeStackCookie to native to to avoid this.
  2088. writeStackCookie();
  2089. }
  2090. /** @type {function(Array=)} */
  2091. function run(args) {
  2092. args = args || arguments_;
  2093. if (runDependencies > 0) {
  2094. return;
  2095. }
  2096. stackCheckInit();
  2097. preRun();
  2098. // a preRun added a dependency, run will be called later
  2099. if (runDependencies > 0) {
  2100. return;
  2101. }
  2102. function doRun() {
  2103. // run may have just been called through dependencies being fulfilled just in this very frame,
  2104. // or while the async setStatus time below was happening
  2105. if (calledRun) return;
  2106. calledRun = true;
  2107. Module['calledRun'] = true;
  2108. if (ABORT) return;
  2109. initRuntime();
  2110. if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
  2111. assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
  2112. postRun();
  2113. }
  2114. if (Module['setStatus']) {
  2115. Module['setStatus']('Running...');
  2116. setTimeout(function() {
  2117. setTimeout(function() {
  2118. Module['setStatus']('');
  2119. }, 1);
  2120. doRun();
  2121. }, 1);
  2122. } else
  2123. {
  2124. doRun();
  2125. }
  2126. checkStackCookie();
  2127. }
  2128. function checkUnflushedContent() {
  2129. // Compiler settings do not allow exiting the runtime, so flushing
  2130. // the streams is not possible. but in ASSERTIONS mode we check
  2131. // if there was something to flush, and if so tell the user they
  2132. // should request that the runtime be exitable.
  2133. // Normally we would not even include flush() at all, but in ASSERTIONS
  2134. // builds we do so just for this check, and here we see if there is any
  2135. // content to flush, that is, we check if there would have been
  2136. // something a non-ASSERTIONS build would have not seen.
  2137. // How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0
  2138. // mode (which has its own special function for this; otherwise, all
  2139. // the code is inside libc)
  2140. var oldOut = out;
  2141. var oldErr = err;
  2142. var has = false;
  2143. out = err = (x) => {
  2144. has = true;
  2145. }
  2146. try { // it doesn't matter if it fails
  2147. flush_NO_FILESYSTEM();
  2148. } catch(e) {}
  2149. out = oldOut;
  2150. err = oldErr;
  2151. if (has) {
  2152. warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.');
  2153. warnOnce('(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)');
  2154. }
  2155. }
  2156. if (Module['preInit']) {
  2157. if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
  2158. while (Module['preInit'].length > 0) {
  2159. Module['preInit'].pop()();
  2160. }
  2161. }
  2162. run();