(moduleConfig)
| 13 | var initSqlJsPromise = undefined; |
| 14 | |
| 15 | var initSqlJs = function (moduleConfig) { |
| 16 | if (initSqlJsPromise) { |
| 17 | return initSqlJsPromise; |
| 18 | } |
| 19 | // If we're here, we've never called this function before |
| 20 | initSqlJsPromise = new Promise(function (resolveModule, reject) { |
| 21 | // We are modularizing this manually because the current modularize setting in Emscripten has some issues: |
| 22 | // https://github.com/kripken/emscripten/issues/5820 |
| 23 | |
| 24 | // The way to affect the loading of emcc compiled modules is to create a variable called `Module` and add |
| 25 | // properties to it, like `preRun`, `postRun`, etc |
| 26 | // We are using that to get notified when the WASM has finished loading. |
| 27 | // Only then will we return our promise |
| 28 | |
| 29 | // If they passed in a moduleConfig object, use that |
| 30 | // Otherwise, initialize Module to the empty object |
| 31 | var Module = typeof moduleConfig !== "undefined" ? moduleConfig : {}; |
| 32 | |
| 33 | // EMCC only allows for a single onAbort function (not an array of functions) |
| 34 | // So if the user defined their own onAbort function, we remember it and call it |
| 35 | var originalOnAbortFunction = Module["onAbort"]; |
| 36 | Module["onAbort"] = function (errorThatCausedAbort) { |
| 37 | reject(new Error(errorThatCausedAbort)); |
| 38 | if (originalOnAbortFunction) { |
| 39 | originalOnAbortFunction(errorThatCausedAbort); |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | Module["postRun"] = Module["postRun"] || []; |
| 44 | Module["postRun"].push(function () { |
| 45 | // When Emscripted calls postRun, this promise resolves with the built Module |
| 46 | resolveModule(Module); |
| 47 | }); |
| 48 | |
| 49 | // There is a section of code in the emcc-generated code below that looks like this: |
| 50 | // (Note that this is lowercase `module`) |
| 51 | // if (typeof module !== 'undefined') { |
| 52 | // module['exports'] = Module; |
| 53 | // } |
| 54 | // When that runs, it's going to overwrite our own modularization export efforts in shell-post.js! |
| 55 | // The only way to tell emcc not to emit it is to pass the MODULARIZE=1 or MODULARIZE_INSTANCE=1 flags, |
| 56 | // but that carries with it additional unnecessary baggage/bugs we don't want either. |
| 57 | // So, we have three options: |
| 58 | // 1) We undefine `module` |
| 59 | // 2) We remember what `module['exports']` was at the beginning of this function and we restore it later |
| 60 | // 3) We write a script to remove those lines of code as part of the Make process. |
| 61 | // |
| 62 | // Since those are the only lines of code that care about module, we will undefine it. It's the most straightforward |
| 63 | // of the options, and has the side effect of reducing emcc's efforts to modify the module if its output were to change in the future. |
| 64 | // That's a nice side effect since we're handling the modularization efforts ourselves |
| 65 | module = undefined; |
| 66 | |
| 67 | // The emcc-generated code and shell-post.js code goes below, |
| 68 | // meaning that all of it runs inside of this promise. If anything throws an exception, our promise will abort |
| 69 | |
| 70 | var e; |
| 71 | e || (e = typeof Module !== "undefined" ? Module : {}); |
| 72 | null; |
nothing calls this directly
no test coverage detected
searching dependent graphs…