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
11 changes: 11 additions & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ function addRunDependency(id) {
#endif

#if ASSERTIONS
#if RUNTIME_DEBUG
dbg('addRunDependency', id);
#endif
assert(id, 'addRunDependency requires an ID')
assert(!runDependencyTracking[id]);
runDependencyTracking[id] = 1;
Expand All @@ -274,6 +277,11 @@ function addRunDependency(id) {
err('(end of list)');
}
}, 10000);
#if ENVIRONMENT_MAY_BE_NODE
// Prevent this timer from keeping the runtime alive if nothing
// else is.
runDependencyWatcher.unref?.()
#endif
}
#endif
}
Expand All @@ -286,6 +294,9 @@ function removeRunDependency(id) {
#endif

#if ASSERTIONS
#if RUNTIME_DEBUG
dbg('removeRunDependency', id);
#endif
assert(id, 'removeRunDependency requires an ID');
assert(runDependencyTracking[id]);
delete runDependencyTracking[id];
Expand Down
8 changes: 4 additions & 4 deletions test/code_size/test_codesize_hello_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22449,
"a.out.js.gz": 8326,
"a.out.js": 22462,
"a.out.js.gz": 8336,
"a.out.nodebug.wasm": 15143,
"a.out.nodebug.wasm.gz": 7452,
"total": 37592,
"total_gz": 15778,
"total": 37605,
"total_gz": 15788,
"sent": [
"fd_write"
],
Expand Down
8 changes: 4 additions & 4 deletions test/code_size/test_codesize_minimal_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 17710,
"a.out.js.gz": 6612,
"a.out.js": 17723,
"a.out.js.gz": 6621,
"a.out.nodebug.wasm": 1136,
"a.out.nodebug.wasm.gz": 659,
"total": 18846,
"total_gz": 7271,
"total": 18859,
"total_gz": 7280,
"sent": [],
"imports": [],
"exports": [
Expand Down
12 changes: 6 additions & 6 deletions test/code_size/test_unoptimized_code_size.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"hello_world.js": 53804,
"hello_world.js.gz": 17065,
"hello_world.js": 53923,
"hello_world.js.gz": 17123,
"hello_world.wasm": 15143,
"hello_world.wasm.gz": 7452,
"no_asserts.js": 26714,
"no_asserts.js.gz": 8952,
"no_asserts.wasm": 12227,
"no_asserts.wasm.gz": 6008,
"strict.js": 51854,
"strict.js.gz": 16403,
"strict.js": 51973,
"strict.js.gz": 16455,
"strict.wasm": 15143,
"strict.wasm.gz": 7438,
"total": 174885,
"total_gz": 63318
"total": 175123,
"total_gz": 63428
}
3 changes: 3 additions & 0 deletions test/other/codesize/test_codesize_minimal_O0.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ function addRunDependency(id) {
err('(end of list)');
}
}, 10000);
// Prevent this timer from keeping the runtime alive if nothing
// else is.
runDependencyWatcher.unref?.()
}
}

Expand Down
25 changes: 11 additions & 14 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2850,21 +2850,19 @@ def test_get_proc_address_error_message(self):
})
def test_prepost(self, no_initial_run, run_dep):
create_file('pre.js', '''
var Module = {
preRun: () => out('pre-run'),
postRun: () => out('post-run')
Module = {
"preRun": () => out('pre-run'),
"postRun": () => out('post-run')
};
''')

self.run_process([EMCC, test_file('hello_world.c'), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
self.assertContained('pre-run\nhello, world!\npost-run\n', self.run_js('a.out.js'))
self.do_runf('hello_world.c', 'pre-run\nhello, world!\npost-run\n', cflags=['--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])

# addRunDependency during preRun should prevent main, and post-run from
# running.
with open('pre.js', 'a') as f:
f.write('Module.preRun = () => { out("add-dep"); addRunDependency(); }\n')
self.run_process([EMCC, test_file('hello_world.c'), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
output = self.run_js('a.out.js')
f.write('Module["preRun"] = () => { out("add-dep"); addRunDependency("dep"); }\n')
output = self.do_runf('hello_world.c', cflags=['--pre-js', 'pre.js', '-sRUNTIME_DEBUG', '-sWASM_ASYNC_COMPILATION=0', '-O2', '--closure=1'])
self.assertContained('add-dep\n', output)
self.assertNotContained('hello, world!\n', output)
self.assertNotContained('post-run\n', output)
Expand All @@ -2874,21 +2872,20 @@ def test_prepost(self, no_initial_run, run_dep):
if no_initial_run:
args += ['-sINVOKE_RUN=0']
if run_dep:
create_file('pre.js', 'Module.preRun = () => addRunDependency("test");')
create_file('pre.js', 'Module["preRun"] = () => addRunDependency("test");')
create_file('post.js', 'removeRunDependency("test");')
args += ['--pre-js', 'pre.js', '--post-js', 'post.js']

self.run_process([EMCC, test_file('hello_world.c')] + args)
output = self.run_js('a.out.js')
output = self.do_runf('hello_world.c', cflags=args)
self.assertContainedIf('hello, world!', output, not no_initial_run)

if no_initial_run:
# Calling main later should still work, filesystem etc. must be set up.
print('call main later')
src = read_file('a.out.js')
src = read_file('hello_world.js')
src += '\nout("callMain -> " + Module.callMain());\n'
create_file('a.out.js', src)
self.assertContained('hello, world!\ncallMain -> 0\n', self.run_js('a.out.js'))
create_file('hello_world.js', src)
self.assertContained('hello, world!\ncallMain -> 0\n', self.run_js('hello_world.js'))

def test_prepost2(self):
create_file('pre.js', 'Module.preRun = () => out("pre-run");')
Expand Down