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
3 changes: 3 additions & 0 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ if (ENVIRONMENT_IS_NODE) {

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

// MODULARIZE == 1 will export the module in the proper place outside, we don't need to export here
#if MODULARIZE == 0
if (typeof module !== 'undefined') {
module['exports'] = Module;
}
#endif

#if NODEJS_CATCH_EXIT
process['on']('uncaughtException', function(ex) {
Expand Down
4 changes: 4 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5438,6 +5438,10 @@ 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

# We call require() twice to ensure it returns wrapper function each time
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