Skip to content

xieranmaya/infinite-loop-detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Infinite Loop Detector

A mini library to detect infinite loop in Javascript

Usage

var code = `
for (;;) {
  console.log(1)
}`

code = infiniteLoopDetector.wrap(code)
// Can only wrap plain code string, no function or other things, or it will throw
// There is also an `unwrap` method to restore the code to the previous shape

try {
  eval(code)
} catch(e) {
  if (e.type === 'InfiniteLoopError') {
    console.log('infinite loop detected')
  }
}

Related blog post

https://zhuanlan.zhihu.com/p/23954773

About

A mini library to detect infinite loop in Javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published