diff --git a/src/postamble.js b/src/postamble.js index 4898e1052445d..64e55bdc02e86 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -43,6 +43,9 @@ if (memoryInitializer) { memoryInitializer = Module['locateFile'](memoryInitializer); } else if (Module['memoryInitializerPrefixURL']) { memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer; + } else if (ENVIRONMENT_IS_NODE) { + // Look for .mem file in the same folder as script by default + memoryInitializer = __dirname + '/' + memoryInitializer; } if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) { var data = Module['readBinary'](memoryInitializer); diff --git a/tests/test_other.py b/tests/test_other.py index 1020ea5850d48..accbe8d6341c5 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -1240,6 +1240,18 @@ def _test(): output_filename='a.out.js') _test() + def test_memory_file_not_in_cwd(self): + # Test that even if JS is executed in different working directory, then it should still find .js.mem file in the same folder as script itself + filename = path_from_root('a.out.js') + Building.emcc(path_from_root('tests', 'hello_world.c'), ['--memory-init-file', '1'], output_filename=filename) + cwd = path_from_root('tests') + print + print 'Filename: %s' % filename + print 'Working dir: %s' % cwd + for engine in JS_ENGINES: + print engine + run_js(filename, cwd=cwd) + def test_ungetc_fscanf(self): open('main.cpp', 'w').write(r''' #include