Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix for repeated require() when MODULARIZE=1 is used
  • Loading branch information
nazar-pc committed Sep 11, 2017
commit 85dfda320d2396821b3e47221aa7e408e9f9ea49
2 changes: 2 additions & 0 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ if (ENVIRONMENT_IS_NODE) {

Module['arguments'] = process['argv'].slice(2);

#if MODULARIZE == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment saying why this is not needed in that mode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added

if (typeof module !== 'undefined') {
module['exports'] = Module;
}
#endif

#if NODEJS_CATCH_EXIT
process['on']('uncaughtException', function(ex) {
Expand Down
3 changes: 3 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5438,6 +5438,9 @@ def test_require_modularize(self):
assert "module['exports'] = NotModule;" in src
output = Popen(NODE_JS + ['-e', 'var m = require("./a.out.js"); m();'], stdout=PIPE, stderr=PIPE).communicate()
assert output == ('hello, world!\n', ''), 'expected output, got\n===\nSTDOUT\n%s\n===\nSTDERR\n%s\n===\n' % output
Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'MODULARIZE=1', '-s', 'NO_EXIT_RUNTIME=1']).communicate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment saying this tests two calls to require

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added

output = Popen(NODE_JS + ['-e', 'require("./a.out.js")();var m = require("./a.out.js"); m();'], stdout=PIPE, stderr=PIPE).communicate()
assert output[0] == 'hello, world!\nhello, world!\n', 'expected output, got\n===\nSTDOUT\n%s\n===\nSTDERR\n%s\n===\n' % output

def test_native_optimizer(self):
def test(args, expected):
Expand Down