aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-07-18 17:21:27 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-07-18 17:21:27 -0700
commita8ffd30399bb7bdce72fbfe6f337f3c08278fcfa (patch)
tree4c5b58bc0cf55b62979e0d3d7414373999fffe18
parent188d8081144c7e655da77fbaabac8f57f13ccf35 (diff)
fix relative paths in preloading and add testing
-rw-r--r--src/library.js16
-rw-r--r--tests/emscripten_fs_api_browser.cpp2
2 files changed, 14 insertions, 4 deletions
diff --git a/src/library.js b/src/library.js
index 4b4c5781..a9a94299 100644
--- a/src/library.js
+++ b/src/library.js
@@ -52,6 +52,15 @@ LibraryManager.library = {
// This is set to false when the runtime is initialized, allowing you
// to modify the filesystem freely before run() is called.
ignorePermissions: true,
+ joinPath: function(parts, forceRelative) {
+ var ret = parts[0];
+ for (var i = 1; i < parts.length; i++) {
+ if (ret[ret.length-1] != '/') ret += '/';
+ ret += parts[i];
+ }
+ if (forceRelative && ret[0] == '/') ret = ret.substr(1);
+ return ret;
+ },
// Converts any path to an absolute path. Resolves embedded "." and ".."
// parts.
absolutePath: function(relative, base) {
@@ -286,6 +295,7 @@ LibraryManager.library = {
// result of an XHR that you did manually.
createPreloadedFile: function(parent, name, url, canRead, canWrite, onload, onerror) {
Browser.ensureObjects();
+ var fullname = FS.joinPath([parent, name], true);
function finish(byteArray) {
FS.createDataFile(parent, name, byteArray, canRead, canWrite);
if (Browser.isImageFile(name)) {
@@ -301,7 +311,7 @@ LibraryManager.library = {
canvas.height = img.height;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
- Module["preloadedImages"][name] = canvas;
+ Module["preloadedImages"][fullname] = canvas;
Browser.URLObject.revokeObjectURL(url);
Module['removeRunDependency']();
if (onload) onload();
@@ -319,7 +329,7 @@ LibraryManager.library = {
audio.removedDependency = false;
audio['oncanplaythrough'] = function() { // XXX string for closure
audio['oncanplaythrough'] = null;
- Module["preloadedAudios"][name] = audio;
+ Module["preloadedAudios"][fullname] = audio;
if (!audio.removedDependency) {
Module['removeRunDependency']();
audio.removedDependency = true;
@@ -335,7 +345,7 @@ LibraryManager.library = {
setTimeout(audio.onerror, 2000); // workaround for chromium bug 124926 (still no audio with this, but at least we don't hang)
audio.src = url;
} else {
- Module["preloadedAudios"]['%(filename)s'] = new Audio(); // empty shim
+ Module["preloadedAudios"][fullname] = new Audio(); // empty shim
Module['removeRunDependency']();
}
} else {
diff --git a/tests/emscripten_fs_api_browser.cpp b/tests/emscripten_fs_api_browser.cpp
index bfe33213..7757ef8a 100644
--- a/tests/emscripten_fs_api_browser.cpp
+++ b/tests/emscripten_fs_api_browser.cpp
@@ -12,7 +12,7 @@ int get_count = 0;
void wait_wgets() {
if (get_count == 3) {
- assert(IMG_Load("screen_shot.png"));
+ assert(IMG_Load("/tmp/screen_shot.png"));
emscripten_cancel_main_loop();
REPORT_RESULT();
}