NeilFraser / JS-Interpreter

A sandboxed JavaScript interpreter in JavaScript.
Apache License 2.0
1.98k stars 353 forks source link

New bug in Function wrapper #217

Closed Webifi closed 2 years ago

Webifi commented 2 years ago

There is a bug in the "Function" wrapper since b820ad4:

Executing code like the following in the interpreter will result in a "parse_ is undefined" error:

var myFn = Function('return true')

In interpreter.js starting at line 539, .parse_ is referenced inside a function like:

      var ast = this.parse_('(function(' + argsStr + ') {' + code + '})',
          'function' + (this.functionCodeNumber_++)); 

This needs to be changed to:

      var ast = thisInterpreter.parse_('(function(' + argsStr + ') {' + code + '})',
          'function' + (thisInterpreter.functionCodeNumber_++)); 
NeilFraser commented 2 years ago

Thanks for the bug report. Your solution was correct. Fixed.

But leaving this bug open since the Closure Compiler is currently throwing errors. Have filed a bug with Google to get this fixed. Then I can push the compressed version of JS-Interpreter and close this bug.

NeilFraser commented 2 years ago

Recompiled.