From 3df65c30cdd4325cb264b1cf69079feadf1a6f35 Mon Sep 17 00:00:00 2001 From: Kristofer Koishigawa Date: Sat, 23 Dec 2017 04:51:21 +0900 Subject: [PATCH] fix(common): Fix for loopProtect undefined error (#16263) Edited the file so that the loopProtect code, which is in the head of the iframe on www.freecodecamp.org, is in the same script tag as the base challenge content that get's rendered to the page. While the loopProtect code is not rendered to the page like the rest of the challenge code, it's within the same scope and seems to function normally. BREAKING CHANGE: None that I know of, but will keep checking. Closes #16260 --- .../routes/Challenges/rechallenge/builders.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/common/app/routes/Challenges/rechallenge/builders.js b/common/app/routes/Challenges/rechallenge/builders.js index e076440383..3984c83e0d 100644 --- a/common/app/routes/Challenges/rechallenge/builders.js +++ b/common/app/routes/Challenges/rechallenge/builders.js @@ -19,6 +19,20 @@ import { const htmlCatch = '\n\n'; const jsCatch = '\n;/*fcc*/\n'; +const loopProtector = ` + window.loopProtect = parent.loopProtect; + window.__err = null; + window.loopProtect.hit = function(line) { + window.__err = new Error( + 'Potential infinite loop at line ' + + line + + '. To disable loop protection, write:' + + ' // noprotect as the first' + + ' line. Beware that if you do have an infinite loop in your code' + + ' this will crash your browser.' + ); + }; +`; const defaultTemplate = ({ source }) => ` @@ -28,7 +42,7 @@ const defaultTemplate = ({ source }) => ` `; const wrapInScript = partial(transformContents, (content) => ( - `${htmlCatch}` + `${htmlCatch}` )); const wrapInStyle = partial(transformContents, (content) => ( `${htmlCatch}`