Module.preInit
This commit is contained in:
Родитель
b3389d30aa
Коммит
9998978f1b
|
@ -79,6 +79,13 @@ Module['run'] = run;
|
|||
|
||||
// {{PRE_RUN_ADDITIONS}}
|
||||
|
||||
if (Module['preInit']) {
|
||||
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
|
||||
while (Module['preInit'].length > 0) {
|
||||
Module['preInit'].pop()();
|
||||
}
|
||||
}
|
||||
|
||||
initRuntime();
|
||||
|
||||
#if INVOKE_RUN
|
||||
|
|
|
@ -7259,6 +7259,17 @@ f.close()
|
|||
open(os.path.join(self.get_dir(), 'a.out.js'), 'w').write(src)
|
||||
assert 'hello from main' in run_js(os.path.join(self.get_dir(), 'a.out.js')), 'main should print when called manually'
|
||||
|
||||
# Use postInit
|
||||
open(os.path.join(self.get_dir(), 'pre.js'), 'w').write('''
|
||||
var Module = {
|
||||
preRun: function() { Module.print('pre-run') },
|
||||
postRun: function() { Module.print('post-run') },
|
||||
preInit: function() { Module.print('pre-init') }
|
||||
};
|
||||
''')
|
||||
Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js']).communicate()
|
||||
self.assertContained('pre-init\npre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
|
||||
|
||||
def test_prepost2(self):
|
||||
open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write('''
|
||||
#include <stdio.h>
|
||||
|
|
Загрузка…
Ссылка в новой задаче