File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 3
3
"name" : " loop-protect" ,
4
4
"description" : " Prevent infinite loops in dynamically eval'd JavaScript." ,
5
5
"main" : " lib/" ,
6
- "version" : " 2.0.0-beta.2 " ,
6
+ "version" : " 2.0.0" ,
7
7
"homepage" : " https://github.com/jsbin/loop-protect" ,
8
8
"repository" : {
9
9
"type" : " git" ,
Original file line number Diff line number Diff line change @@ -73,6 +73,40 @@ describe('loop', function() {
73
73
spy = sinon . spy ( run ) ;
74
74
} ) ;
75
75
76
+ // https://github.com/jsbin/loop-protect/issues/16
77
+ it ( 'should handle nested for' , ( ) => {
78
+ const code = `for (var i = 0; i < 10; i = i + 1) {
79
+ for (var j = 0; j < 10; i = i + 1) {
80
+ }
81
+ }
82
+ return true` ;
83
+
84
+ const compiled = loopProtect ( code ) ;
85
+ assert ( run ( compiled ) === true ) ;
86
+ } ) ;
87
+
88
+ // https://github.com/jsbin/loop-protect/issues/5
89
+ it ( 'blank line' , ( ) => {
90
+ const code = `const log = () => {};while (1)
91
+
92
+ log('Hello')
93
+ return true` ;
94
+
95
+ const compiled = loopProtect ( code ) ;
96
+ assert ( run ( compiled ) === true ) ;
97
+ } ) ;
98
+
99
+ it ( 'with if' , ( ) => {
100
+ const code = `if (false) for (var i = 1; i--;) {
101
+ throw Error;
102
+ }
103
+
104
+ return true;` ;
105
+
106
+ const compiled = loopProtect ( code ) ;
107
+ assert ( run ( compiled ) === true ) ;
108
+ } ) ;
109
+
76
110
it ( 'should ignore comments' , function ( ) {
77
111
var c = code . ignorecomments ;
78
112
var compiled = loopProtect ( c ) ;
You can’t perform that action at this time.
0 commit comments