Skip to content

Commit

Permalink
Transfer wasm file during cross-origin loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nmichaud committed Feb 12, 2018
1 parent 85af914 commit 881afe9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/perspective/src/js/perspective.parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ function worker() {
} else {
this._start_cross_origin();
}
this._detect_transferable();
}

worker.prototype._detect_transferable = function() {
Expand All @@ -204,6 +203,7 @@ worker.prototype._start_cross_origin = function() {
this._worker.postMessage = worker.postMessage.bind(worker);
this._worker.terminate = worker.terminate.bind(worker);
this._worker = worker;
this._detect_transferable();
this._worker.addEventListener('message', this._handle.bind(this));
if (typeof WebAssembly === 'undefined') {
this._start_cross_origin_asmjs();
Expand All @@ -224,13 +224,18 @@ worker.prototype._start_cross_origin_wasm = function() {
var wasmXHR = new XMLHttpRequest();
wasmXHR.open('GET', __SCRIPT_PATH__.path() + 'wasm_async/psp.wasm', true);
wasmXHR.responseType = 'arraybuffer';
wasmXHR.onload = function() {
this._worker.postMessage({
wasmXHR.onload = () => {
let msg = {
cmd: 'init',
data: wasmXHR.response,
path: __SCRIPT_PATH__.path()
});
}.bind(this);
};
if (this._worker.transferable) {
this._worker.postMessage(msg, [wasmXHR.response]);
} else {
this._worker.postMessage(msg);
}
};
wasmXHR.send(null);
}

Expand All @@ -248,6 +253,7 @@ worker.prototype._start_same_origin = function() {
this._worker = w;
this._worker.addEventListener('message', this._handle.bind(this));
this._worker.postMessage({cmd: 'init', path: __SCRIPT_PATH__.path()});
this._detect_transferable();
};

let _initialized = false;
Expand Down

0 comments on commit 881afe9

Please sign in to comment.