Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1023)

Unified Diff: src/parser.cc

Issue 1234433002: [es6] Sloppy functions in block (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add more tests and discover we do report wrong error Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 753391193bf03667a685a24161b83e53ca3ecbda..65b4d7ee896026a780e4342588d00f5335db7549 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2217,6 +2217,28 @@ Statement* Parser::ParseFunctionDeclaration(
factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
if (names) names->Add(name, zone());
+
+ // For sloppy function in block we also add a var binding that gets assigned
+ // to at the location of the FunctionDeclaration -- but only if introducing
+ // this var binding does not lead to an early error.
+ if (is_sloppy(language_mode()) && scope_->is_block_scope() &&
+ allow_harmony_sloppy()) {
+ VariableProxy* var_proxy = NewUnresolved(name, VAR);
+ Declaration* declaration =
+ factory()->NewVariableDeclaration(var_proxy, VAR, scope_, pos);
+ bool var_ok = true;
+ Declare(declaration, DeclarationDescriptor::NORMAL, true, &var_ok);
+ if (!var_ok) {
+ scope_->RemoveUnresolved(var_proxy);
+ } else {
+ // At the location of the FunctionDeclaration we assign to the var
+ // binding.
+ Assignment* assignment = factory()->NewAssignment(
+ Token::ASSIGN, var_proxy, NewUnresolved(name, mode), pos);
+ return factory()->NewExpressionStatement(assignment,
+ RelocInfo::kNoPosition);
+ }
+ }
return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
}
« no previous file with comments | « no previous file | test/mjsunit/harmony/block-function-sloppy.js » ('j') | test/mjsunit/harmony/block-function-sloppy.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698