aboutsummaryrefslogtreecommitdiff
path: root/src/library_browser.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-22 16:26:30 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-22 16:26:30 -0700
commit97f9f26f4bebc8db98608df6e7bcf45322ee189b (patch)
tree2ff62b9b5e3e4c4d97a97caa17ba5ccc77eec294 /src/library_browser.js
parentc11c08094b855e8d6d00d84cbea0f4bf2b18ff72 (diff)
handle no-data worker api calls, and more tests
Diffstat (limited to 'src/library_browser.js')
-rw-r--r--src/library_browser.js22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index b671e6f9..7c1d4320 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -585,14 +585,18 @@ mergeInto(LibraryManager.library, {
if (!callbackInfo) return; // no callback or callback removed meanwhile
info.callbacks[callbackId] = null; // TODO: reuse callbackIds, compress this
var data = msg.data['data'];
- if (!data.byteLength) data = new Uint8Array(data);
- if (!info.buffer || info.bufferSize < data.length) {
- if (info.buffer) _free(info.buffer);
- info.bufferSize = data.length;
- info.buffer = _malloc(data.length);
+ if (data) {
+ if (!data.byteLength) data = new Uint8Array(data);
+ if (!info.buffer || info.bufferSize < data.length) {
+ if (info.buffer) _free(info.buffer);
+ info.bufferSize = data.length;
+ info.buffer = _malloc(data.length);
+ }
+ HEAPU8.set(data, info.buffer);
+ callbackInfo.func(info.buffer, data.length, callbackInfo.arg);
+ } else {
+ callbackInfo.func(0, 0, callbackInfo.arg);
}
- HEAPU8.set(data, info.buffer);
- callbackInfo.func(info.buffer, data.length, callbackInfo.arg);
};
Browser.workers.push(info);
return id;
@@ -619,7 +623,7 @@ mergeInto(LibraryManager.library, {
info.worker.postMessage({
'funcName': funcName,
'callbackId': callbackId,
- 'data': {{{ makeHEAPView('U8', 'data', 'data + size') }}}
+ 'data': data ? {{{ makeHEAPView('U8', 'data', 'data + size') }}} : 0
});
},
@@ -629,7 +633,7 @@ mergeInto(LibraryManager.library, {
workerResponded = true;
postMessage({
'callbackId': workerCallbackId,
- 'data': {{{ makeHEAPView('U8', 'data', 'data + size') }}}
+ 'data': data ? {{{ makeHEAPView('U8', 'data', 'data + size') }}} : 0
});
}
});