Skip to content

Commit 7ac622e

Browse files
authored
Merge pull request #166 from Kukunin/wait_start
Start encoding after worker is ready
2 parents 24dda42 + fb080a0 commit 7ac622e

19 files changed

+16186
-15536
lines changed

dist-unminified/decoderWorker.js

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Copyright 2010 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
16
// The Module object: Our interface to the outside world. We import
27
// and export values on it. There are various ways Module can be used:
38
// 1. Not defined. We create it here
@@ -161,8 +166,8 @@ Module['quit'] = function(status, toThrow) {
161166
Module['preRun'] = [];
162167
Module['postRun'] = [];
163168

164-
// The environment setup code below is customized to use Module.
165-
// *** Environment setup code ***
169+
// Determine the runtime environment we are in. You can customize this by
170+
// setting the ENVIRONMENT setting at compile time (see settings.js).
166171

167172
var ENVIRONMENT_IS_WEB = false;
168173
var ENVIRONMENT_IS_WORKER = false;
@@ -234,9 +239,7 @@ if (ENVIRONMENT_IS_NODE) {
234239
});
235240
// Currently node will swallow unhandled rejections, but this behavior is
236241
// deprecated, and in the future it will exit with error status.
237-
process['on']('unhandledRejection', function(reason, p) {
238-
process['exit'](1);
239-
});
242+
process['on']('unhandledRejection', abort);
240243

241244
Module['quit'] = function(status) {
242245
process['exit'](status);
@@ -276,17 +279,17 @@ if (ENVIRONMENT_IS_SHELL) {
276279
}
277280
} else
278281
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
279-
if (ENVIRONMENT_IS_WEB) {
280-
if (document.currentScript) {
281-
scriptDirectory = document.currentScript.src;
282-
}
283-
} else { // worker
282+
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
284283
scriptDirectory = self.location.href;
284+
} else if (document.currentScript) { // web
285+
scriptDirectory = document.currentScript.src;
285286
}
286287
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
287288
// otherwise, slice off the final part of the url to find the script directory.
289+
// if scriptDirectory does not contain a slash, lastIndexOf will return -1,
290+
// and scriptDirectory will correctly be replaced with an empty string.
288291
if (scriptDirectory.indexOf('blob:') !== 0) {
289-
scriptDirectory = scriptDirectory.split('/').slice(0, -1).join('/') + '/';
292+
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1);
290293
} else {
291294
scriptDirectory = '';
292295
}
@@ -338,8 +341,6 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
338341
var out = Module['print'] || (typeof console !== 'undefined' ? console.log.bind(console) : (typeof print !== 'undefined' ? print : null));
339342
var err = Module['printErr'] || (typeof printErr !== 'undefined' ? printErr : ((typeof console !== 'undefined' && console.warn.bind(console)) || out));
340343

341-
// *** Environment setup code ***
342-
343344
// Merge back in the overrides
344345
for (key in moduleOverrides) {
345346
if (moduleOverrides.hasOwnProperty(key)) {
@@ -352,6 +353,11 @@ moduleOverrides = undefined;
352353

353354

354355

356+
// Copyright 2017 The Emscripten Authors. All rights reserved.
357+
// Emscripten is available under two separate licenses, the MIT license and the
358+
// University of Illinois/NCSA Open Source License. Both these licenses can be
359+
// found in the LICENSE file.
360+
355361
// {{PREAMBLE_ADDITIONS}}
356362

357363
var STACK_ALIGN = 16;
@@ -517,7 +523,13 @@ var GLOBAL_BASE = 1024;
517523
// Runtime essentials
518524
//========================================
519525

520-
var ABORT = 0; // whether we are quitting the application. no code should run after this. set in exit() and abort()
526+
// whether we are quitting the application. no code should run after this.
527+
// set in exit() and abort()
528+
var ABORT = false;
529+
530+
// set by exit() and abort(). Passed to 'onExit' handler.
531+
// NOTE: This is also used as the process return code code in shell environments
532+
// but only when noExitRuntime is false.
521533
var EXITSTATUS = 0;
522534

523535
/** @type {function(*, string=)} */
@@ -808,7 +820,10 @@ function UTF8ArrayToString(u8Array, idx) {
808820

809821
var str = '';
810822
while (1) {
811-
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
823+
// For UTF8 byte structure, see:
824+
// http://en.wikipedia.org/wiki/UTF-8#Description
825+
// https://www.ietf.org/rfc/rfc2279.txt
826+
// https://tools.ietf.org/html/rfc3629
812827
u0 = u8Array[idx++];
813828
if (!u0) return str;
814829
if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
@@ -1114,7 +1129,7 @@ function demangleAll(text) {
11141129
return text.replace(regex,
11151130
function(x) {
11161131
var y = demangle(x);
1117-
return x === y ? x : (x + ' [' + y + ']');
1132+
return x === y ? x : (y + ' [' + x + ']');
11181133
});
11191134
}
11201135

@@ -1407,7 +1422,7 @@ var Math_trunc = Math.trunc;
14071422
// A counter of dependencies for calling run(). If we need to
14081423
// do asynchronous work before running, increment this and
14091424
// decrement it. Incrementing must happen in a place like
1410-
// PRE_RUN_ADDITIONS (used by emcc to add file preloading).
1425+
// Module.preRun (used by emcc to add file preloading).
14111426
// Note that you can add dependencies in preRun, even though
14121427
// it happens right before run - run will be postponed until
14131428
// the dependencies are met.
@@ -1456,6 +1471,11 @@ var memoryInitializer = null;
14561471

14571472

14581473

1474+
// Copyright 2017 The Emscripten Authors. All rights reserved.
1475+
// Emscripten is available under two separate licenses, the MIT license and the
1476+
// University of Illinois/NCSA Open Source License. Both these licenses can be
1477+
// found in the LICENSE file.
1478+
14591479
// Prefix of data URIs emitted by SINGLE_FILE and related options.
14601480
var dataURIPrefix = 'data:application/octet-stream;base64,';
14611481

@@ -1622,7 +1642,7 @@ function integrateWasmJS() {
16221642
function instantiateArrayBuffer(receiver) {
16231643
getBinaryPromise().then(function(binary) {
16241644
return WebAssembly.instantiate(binary, info);
1625-
}).then(receiver).catch(function(reason) {
1645+
}).then(receiver, function(reason) {
16261646
err('failed to asynchronously prepare wasm: ' + reason);
16271647
abort(reason);
16281648
});
@@ -1633,8 +1653,7 @@ function integrateWasmJS() {
16331653
!isDataURI(wasmBinaryFile) &&
16341654
typeof fetch === 'function') {
16351655
WebAssembly.instantiateStreaming(fetch(wasmBinaryFile, { credentials: 'same-origin' }), info)
1636-
.then(receiveInstantiatedSource)
1637-
.catch(function(reason) {
1656+
.then(receiveInstantiatedSource, function(reason) {
16381657
// We expect the most common failure cause to be a bad MIME type for the binary,
16391658
// in which case falling back to ArrayBuffer instantiation should work.
16401659
err('wasm streaming compile failed: ' + reason);
@@ -1860,6 +1879,11 @@ staticSealed = true; // seal the static portion of memory
18601879

18611880
var ASSERTIONS = false;
18621881

1882+
// Copyright 2017 The Emscripten Authors. All rights reserved.
1883+
// Emscripten is available under two separate licenses, the MIT license and the
1884+
// University of Illinois/NCSA Open Source License. Both these licenses can be
1885+
// found in the LICENSE file.
1886+
18631887
/** @type {function(string, boolean=, number=)} */
18641888
function intArrayFromString(stringy, dontAddNull, length) {
18651889
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
@@ -1903,7 +1927,7 @@ function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
19031927

19041928
Module.asmGlobalArg = {};
19051929

1906-
Module.asmLibraryArg = { "abort": abort, "assert": assert, "enlargeMemory": enlargeMemory, "getTotalMemory": getTotalMemory, "abortOnCannotGrowMemory": abortOnCannotGrowMemory, "invoke_iiiiiii": invoke_iiiiiii, "___setErrNo": ___setErrNo, "_abort": _abort, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_llvm_cos_f64": _llvm_cos_f64, "_llvm_exp_f64": _llvm_exp_f64, "_llvm_fabs_f32": _llvm_fabs_f32, "_llvm_floor_f32": _llvm_floor_f32, "_llvm_sin_f64": _llvm_sin_f64, "_llvm_sqrt_f32": _llvm_sqrt_f32, "_llvm_sqrt_f64": _llvm_sqrt_f64, "_llvm_stackrestore": _llvm_stackrestore, "_llvm_stacksave": _llvm_stacksave, "DYNAMICTOP_PTR": DYNAMICTOP_PTR, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX };
1930+
Module.asmLibraryArg = { "abort": abort, "assert": assert, "enlargeMemory": enlargeMemory, "getTotalMemory": getTotalMemory, "abortOnCannotGrowMemory": abortOnCannotGrowMemory, "invoke_iiiiiii": invoke_iiiiiii, "___setErrNo": ___setErrNo, "_abort": _abort, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_llvm_cos_f64": _llvm_cos_f64, "_llvm_exp_f64": _llvm_exp_f64, "_llvm_fabs_f32": _llvm_fabs_f32, "_llvm_floor_f32": _llvm_floor_f32, "_llvm_sin_f64": _llvm_sin_f64, "_llvm_sqrt_f32": _llvm_sqrt_f32, "_llvm_sqrt_f64": _llvm_sqrt_f64, "_llvm_stackrestore": _llvm_stackrestore, "_llvm_stacksave": _llvm_stacksave, "DYNAMICTOP_PTR": DYNAMICTOP_PTR, "tempDoublePtr": tempDoublePtr, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX };
19071931
// EMSCRIPTEN_START_ASM
19081932
var asm =Module["asm"]// EMSCRIPTEN_END_ASM
19091933
(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
@@ -2131,8 +2155,6 @@ function abort(what) {
21312155
}
21322156
Module['abort'] = abort;
21332157

2134-
// {{PRE_RUN_ADDITIONS}}
2135-
21362158
if (Module['preInit']) {
21372159
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
21382160
while (Module['preInit'].length > 0) {
@@ -2145,8 +2167,6 @@ Module["noExitRuntime"] = true;
21452167

21462168
run();
21472169

2148-
// {{POST_RUN_ADDITIONS}}
2149-
21502170

21512171

21522172

dist-unminified/decoderWorker.wasm

349 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)