diff options
-rw-r--r-- | src/runtime.js | 12 | ||||
-rw-r--r-- | tests/core/test_inlinejs3.in | 2 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/runtime.js b/src/runtime.js index 1fc9e026..4fcca56b 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -393,7 +393,17 @@ var Runtime = { for (var i = 0; i < numArgs; i++) { args.push(String.fromCharCode(36) + i); // $0, $1 etc } - return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + Pointer_stringify(code) + ' })'); // new Function does not allow upvars in node + code = Pointer_stringify(code); + if (code[0] === '"') { + // tolerate EM_ASM("..code..") even though EM_ASM(..code..) is correct + if (code.indexOf('"', 1) === code.length-1) { + code = code.substr(1, code.length-2); + } else { + // something invalid happened, e.g. EM_ASM("..code($0)..", input) + abort('invalid EM_ASM input |' + code + '|. Please use EM_ASM(..code..) (no quotes) or EM_ASM({ ..code($0).. }, input) (to input values)'); + } + } + return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + code + ' })'); // new Function does not allow upvars in node }, warnOnce: function(text) { diff --git a/tests/core/test_inlinejs3.in b/tests/core/test_inlinejs3.in index 3e1913ff..e21ed041 100644 --- a/tests/core/test_inlinejs3.in +++ b/tests/core/test_inlinejs3.in @@ -3,7 +3,7 @@ int main(int argc, char **argv) { EM_ASM(Module.print('hello dere1')); - EM_ASM(Module.print('hello dere2');); + EM_ASM("Module.print('hello dere2');"); for (int i = 0; i < 3; i++) { EM_ASM(Module.print('hello dere3'); Module.print('hello dere' + 4);); } |