aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index 938a3c92..26358bd6 100644
--- a/src/library.js
+++ b/src/library.js
@@ -359,7 +359,25 @@ LibraryManager.library = {
var success = true;
if (typeof XMLHttpRequest !== 'undefined') {
// Browser.
- throw 'Cannot do synchronous binary XHRs in modern browsers. Use --embed-file or --preload-file in emcc';
+ if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
+
+ // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', obj.url, false);
+
+ // Some hints to the browser that we want binary data.
+ if (typeof Uint8Array != 'undefined') xhr.responseType = 'arraybuffer';
+ if (xhr.overrideMimeType) {
+ xhr.overrideMimeType('text/plain; charset=x-user-defined');
+ }
+
+ xhr.send(null);
+ if (xhr.status != 200 && xhr.status != 0) success = false;
+ if (xhr.response !== undefined) {
+ obj.contents = new Uint8Array(xhr.response || []);
+ } else {
+ obj.contents = intArrayFromString(xhr.responseText || '', true);
+ }
} else if (Module['read']) {
// Command-line.
try {