Bug 701887

Summary: arguments -object not reachable from inside the code of an eval() invocation unless it has been referenced before eval()
Product: MuJS Reporter: Arto Pekkanen <isoa>
Component: generalAssignee: Tor Andersson <tor.andersson>
Status: RESOLVED FIXED    
Severity: major    
Priority: P4    
Version: 1.0.6   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---

Description Arto Pekkanen 2019-11-08 16:10:52 UTC
function foo() {
    eval("var a = arguments");
}
foo();

Run the forementioned code and you get an exception:
Uncaught exception - ReferenceError: 'arguments' is not defined

However, if I modify the function foo like this:
function foo() {
    arguments;
    eval("var a = arguments");
}

then the code runs just fine.

This means that the arguments -object (which should be accessible for every function), is not accessible from within eval()'ed code unless it is referenced before the eval().

This is very confusing behaviour, which can lead to really arcane bugs. Unless this behaviour is required for ES5 conformance I suggest to make arguments available inside eval() without prior referencing as one would expect.
Comment 1 Tor Andersson 2019-11-19 15:22:13 UTC
commit 3d3f473c399186d229bc0313d3f4efaef0cc5bdb
Author: Tor Andersson <tor.andersson@artifex.com>
Date:   Mon Nov 11 11:02:54 2019 +0100

    Bug 701887: Create arguments if eval is present.
    
    We can't know at compile time that the 'arguments' object will not be used
    from the eval statement, so err on the side of caution and always create
    the arguments object if eval can be called.