Bug 701887 - arguments -object not reachable from inside the code of an eval() invocation unless it has been referenced before eval()
Summary: arguments -object not reachable from inside the code of an eval() invocation ...
Status: RESOLVED FIXED
Alias: None
Product: MuJS
Classification: Unclassified
Component: general (show other bugs)
Version: 1.0.6
Hardware: PC Linux
: P4 major
Assignee: Tor Andersson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-08 16:10 UTC by Arto Pekkanen
Modified: 2019-11-19 15:22 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.