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 /src | |
parent | fd08013827a5fec461b374b9e0605b4ebabf7fe1 (diff) |
improve EM_ASM to tolerate quotes when safe, and error when not; fixes #2032
Diffstat (limited to 'src')
-rw-r--r-- | src/runtime.js | 12 |
1 files changed, 11 insertions, 1 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) { |