Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/libbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ var LibraryBrowser = {
},

// TODO: currently not callable from a pthread, but immediately calls onerror() if not on main thread.
emscripten_async_load_script__deps: ['$UTF8ToString'],
emscripten_async_load_script__deps: ['$UTF8ToString', '$runDependencies', '$dependenciesFulfilled'],
emscripten_async_load_script: async (url, onload, onerror) => {
url = UTF8ToString(url);
#if PTHREADS
Expand Down
8 changes: 7 additions & 1 deletion src/lib/libfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

var LibraryFetch = {
$Fetch__postset: 'Fetch.init();',
$Fetch__deps: ['$HandleAllocator'],
$Fetch__deps: [
'$HandleAllocator',
#if FETCH_SUPPORT_INDEXEDDB
'$addRunDependency',
'$removeRunDependency',
#endif
],
$Fetch: Fetch,
_emscripten_fetch_get_response_headers_length__deps: ['$lengthBytesUTF8'],
_emscripten_fetch_get_response_headers_length: fetchGetResponseHeadersLength,
Expand Down
38 changes: 19 additions & 19 deletions test/codesize/test_codesize_file_preload.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,25 +517,6 @@ var onPreRuns = [];

var addOnPreRun = cb => onPreRuns.push(cb);

var runDependencies = 0;

var dependenciesFulfilled = null;

var removeRunDependency = id => {
runDependencies--;
if (runDependencies == 0) {
if (dependenciesFulfilled) {
var callback = dependenciesFulfilled;
dependenciesFulfilled = null;
callback();
}
}
};

var addRunDependency = id => {
runDependencies++;
};

/** @param {number=} offset */ var doWritev = (stream, iov, iovcnt, offset) => {
var ret = 0;
for (var i = 0; i < iovcnt; i++) {
Expand Down Expand Up @@ -1323,6 +1304,25 @@ var FS_createDataFile = (...args) => FS.createDataFile(...args);

var getUniqueRunDependency = id => id;

var runDependencies = 0;

var dependenciesFulfilled = null;

var removeRunDependency = id => {
runDependencies--;
if (runDependencies == 0) {
if (dependenciesFulfilled) {
var callback = dependenciesFulfilled;
dependenciesFulfilled = null;
callback();
}
}
};

var addRunDependency = id => {
runDependencies++;
};

var preloadPlugins = [];

var FS_handledByPreloadPlugin = async (byteArray, fullname) => {
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_file_preload.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22109,
"a.out.js.gz": 9180,
"a.out.js": 22108,
"a.out.js.gz": 9183,
"a.out.nodebug.wasm": 1666,
"a.out.nodebug.wasm.gz": 945,
"total": 23775,
"total_gz": 10125,
"total": 23774,
"total_gz": 10128,
"sent": [
"a (fd_write)"
],
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 23358,
"a.out.js.gz": 8434,
"a.out.js": 23248,
"a.out.js.gz": 8396,
"a.out.nodebug.wasm": 15115,
"a.out.nodebug.wasm.gz": 7464,
"total": 38473,
"total_gz": 15898,
"total": 38363,
"total_gz": 15860,
"sent": [
"fd_write"
],
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"a.out.js": 26398,
"a.out.js": 26397,
"a.out.js.gz": 11245,
"a.out.nodebug.wasm": 17861,
"a.out.nodebug.wasm.gz": 9019,
"total": 44259,
"total": 44258,
"total_gz": 20264,
"sent": [
"__syscall_stat64",
Expand Down
77 changes: 2 additions & 75 deletions test/codesize/test_codesize_minimal_O0.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,67 +736,6 @@ async function createWasm() {
/** @type {!Uint8Array} */
var HEAPU8;

var runDependencies = 0;


var dependenciesFulfilled = null;

var runDependencyTracking = {
};

var runDependencyWatcher = null;
var removeRunDependency = (id) => {
runDependencies--;

assert(id, 'removeRunDependency requires an ID');
assert(runDependencyTracking[id]);
delete runDependencyTracking[id];
if (runDependencies == 0) {
if (runDependencyWatcher !== null) {
clearInterval(runDependencyWatcher);
runDependencyWatcher = null;
}
if (dependenciesFulfilled) {
var callback = dependenciesFulfilled;
dependenciesFulfilled = null;
callback(); // can add another dependenciesFulfilled
}
}
};


var addRunDependency = (id) => {
runDependencies++;

assert(id, 'addRunDependency requires an ID')
assert(!runDependencyTracking[id]);
runDependencyTracking[id] = 1;
if (runDependencyWatcher === null && globalThis.setInterval) {
// Check for missing dependencies every few seconds
runDependencyWatcher = setInterval(() => {
if (ABORT) {
clearInterval(runDependencyWatcher);
runDependencyWatcher = null;
return;
}
var shown = false;
for (var dep in runDependencyTracking) {
if (!shown) {
shown = true;
err('still waiting on run dependencies:');
}
err(`dependency: ${dep}`);
}
if (shown) {
err('(end of list)');
}
}, 10000);
// Prevent this timer from keeping the runtime alive if nothing
// else is.
runDependencyWatcher.unref?.()
}
};

var callRuntimeCallbacks = (callbacks) => {
while (callbacks.length > 0) {
// Pass the module as the first argument.
Expand Down Expand Up @@ -831,7 +770,6 @@ async function createWasm() {
return '0x' + ptr.toString(16).padStart(8, '0');
}



/**
* @param {number} ptr
Expand Down Expand Up @@ -953,6 +891,8 @@ Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
'mmapAlloc',
'HandleAllocator',
'getUniqueRunDependency',
'addRunDependency',
'removeRunDependency',
'addOnPreRun',
'addOnInit',
'addOnPostCtor',
Expand Down Expand Up @@ -1103,8 +1043,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
'wasmTable',
'wasmMemory',
'noExitRuntime',
'addRunDependency',
'removeRunDependency',
'freeTableIndexes',
'functionsInTableMap',
'setValue',
Expand Down Expand Up @@ -1380,21 +1318,10 @@ function stackCheckInit() {

function run() {

if (runDependencies > 0) {
dependenciesFulfilled = run;
return;
}

stackCheckInit();

preRun();

// a preRun added a dependency, run will be called later
if (runDependencies > 0) {
dependenciesFulfilled = run;
return;
}

function doRun() {
// run may have just been called through dependencies being fulfilled just in this very frame,
// or while the async setStatus time below was happening
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_minimal_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18596,
"a.out.js.gz": 6720,
"a.out.js.gz": 6718,
"a.out.nodebug.wasm": 1015,
"a.out.nodebug.wasm.gz": 602,
"total": 19611,
"total_gz": 7322,
"total_gz": 7320,
"sent": [],
"imports": [],
"exports": [
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_minimal_pthreads.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 6975,
"a.out.js.gz": 3442,
"a.out.js": 6949,
"a.out.js.gz": 3427,
"a.out.nodebug.wasm": 19063,
"a.out.nodebug.wasm.gz": 8803,
"total": 26038,
"total_gz": 12245,
"total": 26012,
"total_gz": 12230,
"sent": [
"a (memory)",
"b (exit)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_minimal_pthreads_memgrowth.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7383,
"a.out.js.gz": 3643,
"a.out.js": 7357,
"a.out.js.gz": 3627,
"a.out.nodebug.wasm": 19064,
"a.out.nodebug.wasm.gz": 8804,
"total": 26447,
"total_gz": 12447,
"total": 26421,
"total_gz": 12431,
"sent": [
"a (memory)",
"b (exit)",
Expand Down
13 changes: 0 additions & 13 deletions test/codesize/test_small_js_flags.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,6 @@ class ExitStatus {

/** @type {!Uint8Array} */ var HEAPU8;

var runDependencies = 0;

var dependenciesFulfilled = null;

var printCharBuffers = [ null, [], [] ];

var UTF8Decoder = globalThis.TextDecoder && new TextDecoder;
Expand Down Expand Up @@ -444,16 +440,7 @@ function callMain() {
}

function run() {
if (runDependencies > 0) {
dependenciesFulfilled = run;
return;
}
preRun();
// a preRun added a dependency, run will be called later
if (runDependencies > 0) {
dependenciesFulfilled = run;
return;
}
function doRun() {
// run may have just been called through dependencies being fulfilled just in this very frame,
// or while the async setStatus time below was happening
Expand Down
16 changes: 8 additions & 8 deletions test/codesize/test_unoptimized_code_size.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"hello_world.js": 57125,
"hello_world.js.gz": 17796,
"hello_world.js": 54902,
"hello_world.js.gz": 17283,
"hello_world.wasm": 15115,
"hello_world.wasm.gz": 7464,
"no_asserts.js": 26698,
"no_asserts.js.gz": 8934,
"no_asserts.js": 25903,
"no_asserts.js.gz": 8768,
"no_asserts.wasm": 12229,
"no_asserts.wasm.gz": 6004,
"strict.js": 54758,
"strict.js.gz": 17042,
"strict.js": 52659,
"strict.js.gz": 16513,
"strict.wasm": 15115,
"strict.wasm.gz": 7461,
"total": 181040,
"total_gz": 64701
"total": 175923,
"total_gz": 63493
}
6 changes: 3 additions & 3 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,8 @@ def limit_incoming_module_api():

settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$ExitStatus']

# Certain configurations require the removeRunDependency/addRunDependency system.
if settings.LOAD_SOURCE_MAP or (settings.WASM_ASYNC_COMPILATION and not settings.MODULARIZE):
if settings.LOAD_SOURCE_MAP:
# Loading the source map uses the addRunDependency/removeRunDependency system.
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$addRunDependency', '$removeRunDependency']

if settings.ABORT_ON_WASM_EXCEPTIONS or settings.SPLIT_MODULE:
Expand Down Expand Up @@ -1953,7 +1953,7 @@ def run_embind_gen(options, wasm_target, js_syms, extra_settings):
settings.MIN_NODE_VERSION = feature_matrix.OLDEST_SUPPORTED_NODE
settings.MINIMAL_RUNTIME = 0
# Required function to trigger TS generation.
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$callRuntimeCallbacks', '$addRunDependency', '$removeRunDependency']
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$callRuntimeCallbacks']
settings.EXPORT_ES6 = False
# Disable proxying and thread pooling so a worker is not automatically created.
settings.PROXY_TO_PTHREAD = False
Expand Down
Loading