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
This commit is contained in:
Kristofer Koishigawa
2017-12-23 04:51:21 +09:00
committed by Ethan Arrowood
parent b7e89e698f
commit 3df65c30cd

View File

@ -19,6 +19,20 @@ import {
const htmlCatch = '\n<!--fcc-->\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 }) => `
<body style='margin:8px;'>
<!-- fcc-start-source -->
@ -28,7 +42,7 @@ const defaultTemplate = ({ source }) => `
`;
const wrapInScript = partial(transformContents, (content) => (
`${htmlCatch}<script>${content}${jsCatch}</script>`
`${htmlCatch}<script>${loopProtector}${content}${jsCatch}</script>`
));
const wrapInStyle = partial(transformContents, (content) => (
`${htmlCatch}<style>${content}</style>`