Add loop protection on keyup update

This commit is contained in:
Berkeley Martinez
2015-12-02 14:56:06 -08:00
parent a6a32d94cd
commit 096fba0de7
3 changed files with 35 additions and 10 deletions

View File

@@ -10,12 +10,6 @@ window.$(document).ready(function() {
var tests = parent.tests;
var common = parent.common;
window.loopProtect.hit = function(line) {
window.__err = new Error(
'Potential infinite loop at line ' + line
);
};
common.getJsOutput = function evalJs(code = '') {
let output;
try {
@@ -40,11 +34,13 @@ window.$(document).ready(function() {
return Rx.Observable.throw(window.__err);
}
// Iterate throught the test one at a time
// on new stacks
return Rx.Observable.from(tests, null, null, Rx.Scheduler.default)
// add delay here for firefox to catch up
.delay(100)
.map(test => {
const userTest = {};
common.appendToOutputDisplay('');
try {
/* eslint-disable no-eval */
eval(test);
@@ -65,10 +61,19 @@ window.$(document).ready(function() {
}
return userTest;
})
// gather tests back into an array
.toArray()
.map(tests => ({ ...rest, tests, originalCode }));
};
// used when updating preview without running tests
common.checkPreview$ = function checkPreview$(args) {
if (window.__err) {
return Rx.Observable.throw(window.__err);
}
return Rx.Observable.just(args);
};
// now that the runPreviewTest$ is defined
// we set the subject to true
// this will let the updatePreview