Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var STDOUT = java.lang.System.out;
STDOUT.println("starting test");
var body =
"// this is a common js module\n" +
"\n" +
"module.exports = function() {\n" +
" var num = 234;\n" +
" num.substr(1, 1);\n" +
"}"
STDOUT.println("module source is:\n" + body);
var args = ['module'];
var func = new Function(args, body);
var module = {};
func.apply(module, [module]);
var f = module.exports;
try {
f();
} catch (ex) {
if (ex instanceof TypeError) {
STDOUT.println("message is:" + ex.message);
STDOUT.println("line no is:" + ex.lineNumber);
STDOUT.println("filename is:" + ex.fileName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.