aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-05-11 10:42:53 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-05-11 10:42:53 -0700
commitdcb1a7a14c03bf414dff5ed50d69523609c5f4e4 (patch)
treeac0605fc07d980a02030db8c34be02ec3fcd2703 /src
parent27379196d5710f73445eeb1e2d1dbaacdabd1c4c (diff)
FS.createPreloadedFile
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js3
-rw-r--r--src/library.js11
-rw-r--r--src/library_browser.js16
-rw-r--r--src/settings.js2
4 files changed, 31 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 77d67bec..89930918 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -73,6 +73,9 @@ function JSify(data, functionsOnly, givenFunctions) {
} else {
libFuncsToInclude = ['memcpy', 'memset', 'malloc', 'free'];
}
+ if (GENERATING_HTML) {
+ libFuncsToInclude.push('$Browser');
+ }
libFuncsToInclude.forEach(function(ident) {
data.functionStubs.push({
intertype: 'functionStub',
diff --git a/src/library.js b/src/library.js
index bac57b59..7e39bdca 100644
--- a/src/library.js
+++ b/src/library.js
@@ -257,11 +257,20 @@ LibraryManager.library = {
var properties = {isDevice: false, contents: data};
return FS.createFile(parent, name, properties, canRead, canWrite);
},
- // Creates a file record for lazy-loading from a URL.
+ // Creates a file record for lazy-loading from a URL. XXX This requires a synchronous
+ // XHR, which is not possible in browsers except in a web worker! Use preloading,
+ // either --preload-file in emcc or FS.createPreloadedFile
createLazyFile: function(parent, name, url, canRead, canWrite) {
var properties = {isDevice: false, url: url};
return FS.createFile(parent, name, properties, canRead, canWrite);
},
+ // Preloads a file asynchronously. You can call this before run, for example in
+ // preRun. run will be delayed until this file arrives and is set up.
+ createPreloadedFile: function(parent, name, url, canRead, canWrite) {
+ Browser.asyncLoad(url, function(data) {
+ FS.createDataFile(parent, name, data, canRead, canWrite);
+ });
+ },
// Creates a link to a sepcific local path.
createLink: function(parent, name, target, canRead, canWrite) {
var properties = {isDevice: false, link: target};
diff --git a/src/library_browser.js b/src/library_browser.js
index eb7f0293..6b2dfeff 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -138,6 +138,22 @@ mergeInto(LibraryManager.library, {
0; // delta;
},
+ asyncLoad: function(url, callback) {
+ 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.');
+ };
+ xhr.send(null);
+ addRunDependency();
+ }
},
emscripten_async_run_script__deps: ['emscripten_run_script'],
diff --git a/src/settings.js b/src/settings.js
index 452472d9..881f7b17 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -205,6 +205,8 @@ var LINKABLE = 0; // If set to 1, this file can be linked with others, either as
// LINKABLE of 0 is very useful in that we can reduce the size of the
// generated code very significantly, by removing everything not actually used.
+var GENERATING_HTML = 0; // Set to 1 when generating .html and not just .js
+
var RUNTIME_TYPE_INFO = 0; // Whether to expose type info to the script at run time. This
// increases the size of the generated script, but allows you
// to more easily perform operations from handwritten JS on