diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-24 11:14:04 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-24 11:14:04 -0700 |
commit | 97b99d6e689d0740b85be1ad7279df7a1ca74f7f (patch) | |
tree | 8fd5715165fc35aeeae7fcb581e455f369368195 | |
parent | e309c2077097725c71e2cd0f20d3ada3b5f79bf6 (diff) |
fix caching of asm const strings; fixes #2253
-rw-r--r-- | src/runtime.js | 12 | ||||
-rw-r--r-- | tests/core/test_inlinejs3.in | 5 | ||||
-rw-r--r-- | tests/core/test_inlinejs3.out | 2 |
3 files changed, 13 insertions, 6 deletions
diff --git a/src/runtime.js b/src/runtime.js index 2ae68279..edcbf637 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -399,17 +399,17 @@ var Runtime = { for (var i = 0; i < numArgs; i++) { args.push(String.fromCharCode(36) + i); // $0, $1 etc } - code = Pointer_stringify(code); - if (code[0] === '"') { + var source = Pointer_stringify(code); + if (source[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); + if (source.indexOf('"', 1) === source.length-1) { + source = source.substr(1, source.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)'); + abort('invalid EM_ASM input |' + source + '|. 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 + return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + source + ' })'); // 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 da720a3d..b45abe95 100644 --- a/tests/core/test_inlinejs3.in +++ b/tests/core/test_inlinejs3.in @@ -1,6 +1,10 @@ #include <stdio.h> #include <emscripten.h> +void loop_iter() { + EM_ASM(Module.print('loop iter!')); +} + int main(int argc, char **argv) { EM_ASM(Module.print('hello dere1')); EM_ASM("Module.print('hello dere2');"); @@ -21,5 +25,6 @@ int main(int argc, char **argv) { sum = 0; sum = EM_ASM_INT_V({ return globalVar }); // no inputs, just output printf("sum: %d\n", sum); + for (int i = 0; i < argc*2; i++) loop_iter(); return 0; } diff --git a/tests/core/test_inlinejs3.out b/tests/core/test_inlinejs3.out index 1f64a89a..5d185adc 100644 --- a/tests/core/test_inlinejs3.out +++ b/tests/core/test_inlinejs3.out @@ -11,3 +11,5 @@ i: 0,0.00 i: 1,0.08 i: 2,0.17 sum: 6 +loop iter! +loop iter! |