Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new Function(...) returns undefined in Chrome 58 when in debug mode

I came across some odd behavior of new Function(...) in Chrome 58. When executing new Function(...) in the developer console when paused at a debug point, undefined is returned instead of a newly created function.

jsbin example: http://jsbin.com/raluwu/edit?html,output

<!DOCTYPE html>
<html>
<body>
  <script>
    // open the developer console in Chrome 58, 
    // and run this code until the debug point
    debugger;
    //eval('debugger');
    // when at the debug point, enter the following in the console:
    //
    //     var f = new Function ('a', 'return a + a');
    //     // f should be a function but is undefined when in debug mode
    // 
    //     console.log(f(2));   
    //     // should return 4, but throws "Uncaught TypeError: f is not a function"

    // without debug point, everything runs fine:
    var f = new Function ('a', 'return a + a');
    console.log(f(2)); // 4
  </script>
</body>
</html>

Is this a bug in Chrome?

like image 519
Jos de Jong Avatar asked Jun 13 '26 21:06

Jos de Jong


1 Answers

I've done some more digging and found a bug report on this issue:

https://bugs.chromium.org/p/chromium/issues/detail?id=705149

So, it's indeed a bug in Chrome

like image 138
Jos de Jong Avatar answered Jun 15 '26 16:06

Jos de Jong