mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-12 17:46:26 +02:00
add setting to change infinite loop detection timeout. fixes #188;
This commit is contained in:
@ -535,6 +535,16 @@
|
||||
<input type="checkbox" d-change="updateSetting" data-setting="isCodeBlastOn"> Code blast!
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3>Advanced</h3>
|
||||
<p>
|
||||
<label class="line" title="This timeout is used to indentify a possible infinite loop and prevent it.">
|
||||
Maximum time allowed in a loop iteration
|
||||
<input type="number" data-setting="infiniteLoopTimeout" d-change="updateSetting"> ms
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -40,7 +40,8 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn, askTo
|
||||
autoComplete: true,
|
||||
preserveConsoleLogs: true,
|
||||
lightVersion: false,
|
||||
lineWrap: true
|
||||
lineWrap: true,
|
||||
infiniteLoopTimeout: 1000
|
||||
};
|
||||
var HtmlModes = {
|
||||
HTML: 'html',
|
||||
@ -914,7 +915,9 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn, askTo
|
||||
]);
|
||||
} finally {
|
||||
if (shouldPreventInfiniteLoops !== false) {
|
||||
code = utils.addInfiniteLoopProtection(code);
|
||||
code = utils.addInfiniteLoopProtection(code, {
|
||||
timeout: prefs.infiniteLoopTimeout
|
||||
});
|
||||
}
|
||||
d.resolve(code);
|
||||
}
|
||||
@ -931,7 +934,9 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn, askTo
|
||||
]);
|
||||
} finally {
|
||||
if (shouldPreventInfiniteLoops !== false) {
|
||||
code = utils.addInfiniteLoopProtection(code);
|
||||
code = utils.addInfiniteLoopProtection(code, {
|
||||
timeout: prefs.infiniteLoopTimeout
|
||||
});
|
||||
}
|
||||
d.resolve(code);
|
||||
}
|
||||
@ -954,7 +959,9 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn, askTo
|
||||
presets: ['latest', 'stage-2', 'react']
|
||||
}).code;
|
||||
if (shouldPreventInfiniteLoops !== false) {
|
||||
code = utils.addInfiniteLoopProtection(code);
|
||||
code = utils.addInfiniteLoopProtection(code, {
|
||||
timeout: prefs.infiniteLoopTimeout
|
||||
});
|
||||
}
|
||||
d.resolve(code);
|
||||
}
|
||||
@ -983,7 +990,9 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn, askTo
|
||||
};
|
||||
}
|
||||
if (shouldPreventInfiniteLoops !== false) {
|
||||
code = utils.addInfiniteLoopProtection(code.outputText);
|
||||
code = utils.addInfiniteLoopProtection(code.outputText, {
|
||||
timeout: prefs.infiniteLoopTimeout
|
||||
});
|
||||
}
|
||||
d.resolve(code);
|
||||
} catch (e) {
|
||||
@ -1753,6 +1762,8 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn, askTo
|
||||
$('[data-setting=preserveConsoleLogs]').checked = prefs.preserveConsoleLogs;
|
||||
$('[data-setting=lightVersion]').checked = prefs.lightVersion;
|
||||
$('[data-setting=lineWrap]').checked = prefs.lineWrap;
|
||||
$('[data-setting=infiniteLoopTimeout]').value =
|
||||
prefs.infiniteLoopTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user