diff options
Diffstat (limited to 'src/library_browser.js')
-rw-r--r-- | src/library_browser.js | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 9283913f..75dfb9d0 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -142,24 +142,59 @@ mergeInto(LibraryManager.library, { 0; }, - asyncLoad: function(url, callback) { + xhrLoad: function(url, onload, onerror) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; xhr.onload = function() { - var arrayBuffer = xhr.response; - assert(arrayBuffer, 'Loading data file "' + url + '" failed (no arrayBuffer).'); - callback(new Uint8Array(arrayBuffer)); - removeRunDependency(); - }; - xhr.onerror = function(event) { - assert(arrayBuffer, 'Loading data file "' + url + '" failed.'); + if (xhr.status == 200) { + onload(xhr.response); + } else { + onerror(); + } }; + xhr.onerror = onerror; xhr.send(null); + }, + + asyncLoad: function(url, callback) { + Browser.xhrLoad(url, + function(arrayBuffer) { + assert(arrayBuffer, 'Loading data file "' + url + '" failed (no arrayBuffer).'); + callback(new Uint8Array(arrayBuffer)); + removeRunDependency(); + }, + function(event) { + assert(arrayBuffer, 'Loading data file "' + url + '" failed.'); + }); addRunDependency(); } }, + emscripten_async_wget: function(url, file, onload, onerror) { + url = Pointer_stringify(url); + + Browser.xhrLoad(url, + function (response) { + var absolute = Pointer_stringify(file); + var index = absolute.lastIndexOf('/'); + FS.createDataFile( + absolute.substr(0, index), + absolute.substr(index +1), + new Uint8Array(response), + true, true); + + if (onload) { + FUNCTION_TABLE[onload](file); + } + }, + function (event) { + if (onerror) { + FUNCTION_TABLE[onerror](file); + } + }); + }, + emscripten_async_run_script__deps: ['emscripten_run_script'], emscripten_async_run_script: function(script, millis) { Module['noExitRuntime'] = true; |