New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 744216 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Jul 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

creating variables using eval does not work in a class context

Reported by mwhitfie...@gmail.com, Jul 17 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36

Steps to reproduce the problem:
1. eval('var a = 123;'); console.log('a');
2. paste above code outside class context, runs fine
3. paste code inside class context (static), throws error

What is the expected behavior?
eval
Should allow new variables to be set in class context.

What went wrong?
"[Variable] is not defined." error thrown.

Did this work before? No 

Chrome version: 59.0.3071.115  Channel: stable
OS Version: 10.0
Flash Version: 

/**
 * Bug report: eval has difficulty binding inside a class context.  This 
 * occurs for static and non-static methods.  This may or may not indicate
 * further work required for completely implementing ES6 classes in the browser.
 * @foundby Mike Whitfield (http://mikewhitfield.org | github.com/mgwhitfield)
 */

fn = function() {
	eval('var b = 234;');
	console.log(b);
}

arrowFn = () => {
	eval('var c = 345;');
	console.log(c);
}

class err {
	constructor() {
		try {
		    eval('var a = 123;');
			console.log(a);
        } catch(e) {
			console.log('test1 fails', e);
		}
		try {
			fn();
        } catch(e) {
			console.log('test2 fails', e);
        }
		try {
			arrowFn();
        } catch(e) {
			console.log('test3 fails', e);
        }
        try {
            err.fn();
        } catch(e) {
            console.log('test4 fails', e);
        }
        var e = 567;
		try {
		    eval('e = 678;');
			console.assert(e == 678);
        } catch(e) {
			console.log('test5 fails', e);
		}
		try {
		    eval('this.f = 789;');
			console.log(this.f);
        } catch(e) {
			console.log('test6 fails', e);
		}
		try {
		    eval('let g = 890;');
			console.log(g);
        } catch(e) {
			console.log('test7 fails', e);
		}
		try {
		    eval('const h = 901;');
			console.log(h);
        } catch(e) {
			console.log('test8 fails', e);
		}
    }

    static fn() {
        eval('var d = 456');
        console.log(d);
    }
}
 
this is working as intended, classes are strict by default

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Strict_mode

    (new class {
        constructor () {
            var eval = 1;
        }
    });
    
    // Uncaught SyntaxError: Unexpected eval or arguments in strict mode
@mwhitfield347: Thanks for the report.

Could you please provide us a sample test file to check the issue from our end?

Thanks!!
Labels: Needs-Feedback
Components: -Blink Blink>JavaScript
Assigning to Blink>Javascript but I expect this can be closed as per comment #1.
Project Member

Comment 6 by sheriffbot@chromium.org, Jul 19 2017

Cc: sandeepkumars@chromium.org
Labels: -Needs-Feedback
Thank you for providing more feedback. Adding requester "sandeepkumars@chromium.org" to the cc list and removing "Needs-Feedback" label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Components: -Blink>JavaScript Blink>JavaScript>Language
Status: WontFix (was: Unconfirmed)

Sign in to add a comment