[es6] Remaining cases of parameter scopes for sloppy eval

R=littledan@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1303013007

Cr-Commit-Position: refs/heads/master@{#30363}
This commit is contained in:
rossberg 2015-08-25 15:24:17 -07:00 committed by Commit bot
parent 233d62f8e3
commit 089592ad33
3 changed files with 74 additions and 15 deletions

View File

@ -4399,7 +4399,7 @@ Block* Parser::BuildParameterInitializationBlock(
Scope* param_scope = scope_;
Block* param_block = init_block;
if (parameter.initializer != nullptr && scope_->calls_sloppy_eval()) {
if (!parameter.is_simple() && scope_->calls_sloppy_eval()) {
param_scope = NewScope(scope_, BLOCK_SCOPE);
param_scope->set_is_declaration_scope();
param_scope->set_start_position(parameter.pattern->position());
@ -4418,7 +4418,7 @@ Block* Parser::BuildParameterInitializationBlock(
&decl, nullptr, CHECK_OK);
}
if (parameter.initializer != nullptr && scope_->calls_sloppy_eval()) {
if (!parameter.is_simple() && scope_->calls_sloppy_eval()) {
param_scope = param_scope->FinalizeBlockScope();
if (param_scope != nullptr) {
CheckConflictingVarDeclarations(param_scope, CHECK_OK);

View File

@ -546,6 +546,9 @@ struct ParserFormalParameters : FormalParametersBase {
Expression* pattern;
Expression* initializer;
bool is_rest;
bool is_simple() const {
return pattern->IsVariableProxy() && initializer == nullptr && !is_rest;
}
};
explicit ParserFormalParameters(Scope* scope)

View File

@ -172,19 +172,18 @@
function f3(y = eval("var x = 2"), z = eval("x")) { return z; }
assertEquals(1, f3());
assertEquals(1, f3(0));
// TODO(rossberg): eval inside patterns is not recognized yet.
// function f41({[eval("var x = 2; 'a'")]: w}, z = x)) { return z; }
// assertEquals(1, f41({}));
// assertEquals(1, f41({a: 0}));
// function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; }
// assertEquals(1, f42({}));
// assertEquals(1, f42({a: 0}));
// function f43({a: w = eval("var x = 2")}, z = x) { return z; }
// assertEquals(1, f43({}));
// assertEquals(1, f43({a: 0}));
// function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; }
// assertEquals(1, f44({}));
// assertEquals(1, f44({a: 0}));
function f41({[eval("var x = 2; 'a'")]: w}, z = x) { return z; }
assertEquals(1, f41({}));
assertEquals(1, f41({a: 0}));
function f42({[eval("var x = 2; 'a'")]: w}, z = eval("x")) { return z; }
assertEquals(1, f42({}));
assertEquals(1, f42({a: 0}));
function f43({a: w = eval("var x = 2")}, z = x) { return z; }
assertEquals(1, f43({}));
assertEquals(1, f43({a: 0}));
function f44({a: w = eval("var x = 2")}, z = eval("x")) { return z; }
assertEquals(1, f44({}));
assertEquals(1, f44({a: 0}));
function f5({a = eval("var x = 2"), b = x}) { return b; }
assertEquals(2, f5({}));
@ -221,6 +220,63 @@
function f22(f = () => eval("x")) { eval("var x = 2"); return f() }
assertEquals(1, f22());
assertEquals(3, f22(() => 3));
var g1 = (y = eval("var x = 2")) => { with ({}) { return x; } };
assertEquals(1, g1());
var g2 = (y = eval("var x = 2"), z = x) => { return z; };
assertEquals(1, g2());
assertEquals(1, g2(0));
var g3 = (y = eval("var x = 2"), z = eval("x")) => { return z; };
assertEquals(1, g3());
assertEquals(1, g3(0));
var g41 = ({[eval("var x = 2; 'a'")]: w}, z = x) => { return z; };
assertEquals(1, g41({}));
assertEquals(1, g41({a: 0}));
var g42 = ({[eval("var x = 2; 'a'")]: w}, z = eval("x")) => { return z; };
assertEquals(1, g42({}));
assertEquals(1, g42({a: 0}));
var g43 = ({a: w = eval("var x = 2")}, z = x) => { return z; };
assertEquals(1, g43({}));
assertEquals(1, g43({a: 0}));
var g44 = ({a: w = eval("var x = 2")}, z = eval("x")) => { return z; };
assertEquals(1, g44({}));
assertEquals(1, g44({a: 0}));
var g5 = ({a = eval("var x = 2"), b = x}) => { return b; };
assertEquals(2, g5({}));
assertEquals(1, g5({a: 0}));
var g6 = ({a = eval("var x = 2"), b = eval("x")}) => { return b; };
assertEquals(2, g6({}));
assertEquals(1, g6({a: 0}));
var g71 = ({[eval("var x = 2; 'a'")]: w, b = x}) => { return b; };
assertEquals(2, g71({}));
assertEquals(2, g71({a: 0}));
var g72 = ({[eval("var x = 2; 'a'")]: w, b = eval("x")}) => { return b; };
assertEquals(2, g72({}));
assertEquals(2, g72({a: 0}));
var g73 = ({a: w = eval("var x = 2"), b = x}) => { return b; };
assertEquals(2, g73({}));
assertEquals(1, g73({a: 0}));
var g74 = ({a: w = eval("var x = 2"), b = eval("x")}) => { return b; };
assertEquals(2, g74({}));
assertEquals(1, g74({a: 0}));
var g8 = (y = (eval("var x = 2"), x)) => { return y; };
assertEquals(2, g8());
assertEquals(0, g8(0));
var g11 = (z = eval("var y = 2")) => { return y; };
assertThrows(g11, ReferenceError);
var g12 = (z = eval("var y = 2"), b = y) => {};
assertThrows(g12, ReferenceError);
var g13 = (z = eval("var y = 2"), b = eval("y")) => {};
assertThrows(g13, ReferenceError);
var g21 = (f = () => x) => { eval("var x = 2"); return f() };
assertEquals(1, g21());
assertEquals(3, g21(() => 3));
var g22 = (f = () => eval("x")) => { eval("var x = 2"); return f() };
assertEquals(1, g22());
assertEquals(3, g22(() => 3));
})();