1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-17 20:11:12 +02:00

add setting to change infinite loop detection timeout. fixes #188;

This commit is contained in:
Kushagra Gour
2018-05-05 23:08:03 +05:30
parent 7b255ceca8
commit dd4a11d059
3 changed files with 28 additions and 8 deletions

View File

@@ -87,13 +87,12 @@
* Contributed by Ariya Hidayat!
* @param code {string} Code to be protected from infinite loops.
*/
function addInfiniteLoopProtection(code) {
function addInfiniteLoopProtection(code, { timeout }) {
var loopId = 1;
var patches = [];
var varPrefix = '_wmloopvar';
var varStr = 'var %d = Date.now();\n';
var checkStr =
'\nif (Date.now() - %d > 1000) { window.top.previewException(new Error("Infinite loop")); break;}\n';
var checkStr = `\nif (Date.now() - %d > ${timeout}) { window.top.previewException(new Error("Infinite loop")); break;}\n`;
esprima.parse(code, { tolerant: true, range: true, jsx: true }, function(
node