diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-18 18:26:19 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-18 18:26:19 -0800 |
commit | fa70d238fca62dc3f7b1aefa8f0bf8c6dc337eea (patch) | |
tree | 831265df8ac384e2a10617878fe792f8e7409886 | |
parent | fd08013827a5fec461b374b9e0605b4ebabf7fe1 (diff) |
improve EM_ASM to tolerate quotes when safe, and error when not; fixes #2032
-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);); } |