Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b33e5f3

Browse files
committed
Make infinite loop protection work in web worker
Fixes codesandbox#3761
1 parent c59f559 commit b33e5f3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/app/src/sandbox/eval/transpilers/babel/worker/plugins/babel-plugin-transform-prevent-infinite-loops.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ module.exports = ({ types: t, template }) => {
1515
// We set a global so that we can later fail the test
1616
// even if the error ends up being caught by the code.
1717
const buildGuard = template(`
18+
var csb_global = typeof window === 'undefined' ? self : window;
1819
if (ITERATOR++ > MAX_ITERATIONS) {
19-
global.infiniteLoopError = new RangeError(
20+
csb_global.infiniteLoopError = new RangeError(
2021
'Potential infinite loop: exceeded ' +
2122
MAX_ITERATIONS +
2223
' iterations. You can disable this check by creating a sandbox.config.json file.'
2324
);
24-
throw global.infiniteLoopError;
25+
throw csb_global.infiniteLoopError;
2526
}
2627
`);
2728

0 commit comments

Comments
 (0)