Skip to content

Commit 10a4a9e

Browse files
authored
Require id in addRunDependency/removeRunDependency (#24890)
Since the dawn of time we've been emitting warnings when these are called without an ID. It seem pretty reasonable to require one at this point. One of my motivations here it to update/replace this interface with a more modern one based on promises. Making this API consistently use IDs simplifies things. Also, even though this could be breaking change I think its highly unlikely there are any users who are not specifying IDs, since we have had warnings in debug builds since 2012: f67ad60.
1 parent eb9b5a2 commit 10a4a9e

File tree

7 files changed

+70
-78
lines changed

7 files changed

+70
-78
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.13 (in development)
2222
-----------------------
23+
- The `addRunDependency`/`removeRunDependency` now assert in debug builds if
24+
they are not passed an `id` parameter. We have been issuing warnings in
25+
this case since 2012 (f67ad60), so it seems highly unlikely anyone is not
26+
passing IDs here. (#24890).
2327
- The `-sMODULARIZE` setting generates a factory function that must be called
2428
before the program is instantiated that run. However, emscripten previously
2529
had very special case where this instantiation would happen automatically

src/preamble.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -251,32 +251,29 @@ function addRunDependency(id) {
251251
#endif
252252

253253
#if ASSERTIONS
254-
if (id) {
255-
assert(!runDependencyTracking[id]);
256-
runDependencyTracking[id] = 1;
257-
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
258-
// Check for missing dependencies every few seconds
259-
runDependencyWatcher = setInterval(() => {
260-
if (ABORT) {
261-
clearInterval(runDependencyWatcher);
262-
runDependencyWatcher = null;
263-
return;
264-
}
265-
var shown = false;
266-
for (var dep in runDependencyTracking) {
267-
if (!shown) {
268-
shown = true;
269-
err('still waiting on run dependencies:');
270-
}
271-
err(`dependency: ${dep}`);
272-
}
273-
if (shown) {
274-
err('(end of list)');
254+
assert(id, 'addRunDependency requires an ID')
255+
assert(!runDependencyTracking[id]);
256+
runDependencyTracking[id] = 1;
257+
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
258+
// Check for missing dependencies every few seconds
259+
runDependencyWatcher = setInterval(() => {
260+
if (ABORT) {
261+
clearInterval(runDependencyWatcher);
262+
runDependencyWatcher = null;
263+
return;
264+
}
265+
var shown = false;
266+
for (var dep in runDependencyTracking) {
267+
if (!shown) {
268+
shown = true;
269+
err('still waiting on run dependencies:');
275270
}
276-
}, 10000);
277-
}
278-
} else {
279-
err('warning: run dependency added without ID');
271+
err(`dependency: ${dep}`);
272+
}
273+
if (shown) {
274+
err('(end of list)');
275+
}
276+
}, 10000);
280277
}
281278
#endif
282279
}
@@ -289,12 +286,9 @@ function removeRunDependency(id) {
289286
#endif
290287

291288
#if ASSERTIONS
292-
if (id) {
293-
assert(runDependencyTracking[id]);
294-
delete runDependencyTracking[id];
295-
} else {
296-
err('warning: run dependency removed without ID');
297-
}
289+
assert(id, 'removeRunDependency requires an ID');
290+
assert(runDependencyTracking[id]);
291+
delete runDependencyTracking[id];
298292
#endif
299293
if (runDependencies == 0) {
300294
#if ASSERTIONS

test/code_size/test_codesize_hello_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 22324,
3-
"a.out.js.gz": 8300,
2+
"a.out.js": 22449,
3+
"a.out.js.gz": 8326,
44
"a.out.nodebug.wasm": 15143,
55
"a.out.nodebug.wasm.gz": 7452,
6-
"total": 37467,
7-
"total_gz": 15752,
6+
"total": 37592,
7+
"total_gz": 15778,
88
"sent": [
99
"fd_write"
1010
],

test/code_size/test_codesize_minimal_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 17587,
3-
"a.out.js.gz": 6587,
2+
"a.out.js": 17710,
3+
"a.out.js.gz": 6612,
44
"a.out.nodebug.wasm": 1136,
55
"a.out.nodebug.wasm.gz": 659,
6-
"total": 18723,
7-
"total_gz": 7246,
6+
"total": 18846,
7+
"total_gz": 7271,
88
"sent": [],
99
"imports": [],
1010
"exports": [
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 53916,
3-
"hello_world.js.gz": 17076,
2+
"hello_world.js": 53804,
3+
"hello_world.js.gz": 17065,
44
"hello_world.wasm": 15143,
55
"hello_world.wasm.gz": 7452,
66
"no_asserts.js": 26714,
77
"no_asserts.js.gz": 8952,
88
"no_asserts.wasm": 12227,
99
"no_asserts.wasm.gz": 6008,
10-
"strict.js": 51966,
11-
"strict.js.gz": 16409,
10+
"strict.js": 51854,
11+
"strict.js.gz": 16403,
1212
"strict.wasm": 15143,
1313
"strict.wasm.gz": 7438,
14-
"total": 175109,
15-
"total_gz": 63335
14+
"total": 174885,
15+
"total_gz": 63318
1616
}

test/other/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -508,44 +508,38 @@ var runDependencyWatcher = null;
508508
function addRunDependency(id) {
509509
runDependencies++;
510510

511-
if (id) {
512-
assert(!runDependencyTracking[id]);
513-
runDependencyTracking[id] = 1;
514-
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
515-
// Check for missing dependencies every few seconds
516-
runDependencyWatcher = setInterval(() => {
517-
if (ABORT) {
518-
clearInterval(runDependencyWatcher);
519-
runDependencyWatcher = null;
520-
return;
521-
}
522-
var shown = false;
523-
for (var dep in runDependencyTracking) {
524-
if (!shown) {
525-
shown = true;
526-
err('still waiting on run dependencies:');
527-
}
528-
err(`dependency: ${dep}`);
529-
}
530-
if (shown) {
531-
err('(end of list)');
511+
assert(id, 'addRunDependency requires an ID')
512+
assert(!runDependencyTracking[id]);
513+
runDependencyTracking[id] = 1;
514+
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
515+
// Check for missing dependencies every few seconds
516+
runDependencyWatcher = setInterval(() => {
517+
if (ABORT) {
518+
clearInterval(runDependencyWatcher);
519+
runDependencyWatcher = null;
520+
return;
521+
}
522+
var shown = false;
523+
for (var dep in runDependencyTracking) {
524+
if (!shown) {
525+
shown = true;
526+
err('still waiting on run dependencies:');
532527
}
533-
}, 10000);
534-
}
535-
} else {
536-
err('warning: run dependency added without ID');
528+
err(`dependency: ${dep}`);
529+
}
530+
if (shown) {
531+
err('(end of list)');
532+
}
533+
}, 10000);
537534
}
538535
}
539536

540537
function removeRunDependency(id) {
541538
runDependencies--;
542539

543-
if (id) {
544-
assert(runDependencyTracking[id]);
545-
delete runDependencyTracking[id];
546-
} else {
547-
err('warning: run dependency removed without ID');
548-
}
540+
assert(id, 'removeRunDependency requires an ID');
541+
assert(runDependencyTracking[id]);
542+
delete runDependencyTracking[id];
549543
if (runDependencies == 0) {
550544
if (runDependencyWatcher !== null) {
551545
clearInterval(runDependencyWatcher);

test/test_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,11 +2379,11 @@ def test_pre_run_deps(self):
23792379
# Adding a dependency in preRun will delay run
23802380
create_file('pre.js', '''
23812381
Module.preRun = () => {
2382-
addRunDependency();
2382+
addRunDependency('foo');
23832383
out('preRun called, added a dependency...');
23842384
setTimeout(function() {
23852385
Module.okk = 10;
2386-
removeRunDependency()
2386+
removeRunDependency('foo')
23872387
}, 2000);
23882388
};
23892389
''')

0 commit comments

Comments
 (0)