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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 : (is_strict(language_mode()) || allow_harmony_sloppy()) && 2210 : (is_strict(language_mode()) || allow_harmony_sloppy()) &&
2211 !(scope_->is_script_scope() || scope_->is_eval_scope() || 2211 !(scope_->is_script_scope() || scope_->is_eval_scope() ||
2212 scope_->is_function_scope()) 2212 scope_->is_function_scope())
2213 ? LET 2213 ? LET
2214 : VAR; 2214 : VAR;
2215 VariableProxy* proxy = NewUnresolved(name, mode); 2215 VariableProxy* proxy = NewUnresolved(name, mode);
2216 Declaration* declaration = 2216 Declaration* declaration =
2217 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos); 2217 factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
2218 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2218 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2219 if (names) names->Add(name, zone()); 2219 if (names) names->Add(name, zone());
2220
2221 // For sloppy function in block we also add a var binding that gets assigned
2222 // to at the location of the FunctionDeclaration -- but only if introducing
2223 // this var binding does not lead to an early error.
2224 if (is_sloppy(language_mode()) && scope_->is_block_scope() &&
2225 allow_harmony_sloppy()) {
2226 VariableProxy* var_proxy = NewUnresolved(name, VAR);
2227 Declaration* declaration =
2228 factory()->NewVariableDeclaration(var_proxy, VAR, scope_, pos);
2229 bool var_ok = true;
2230 Declare(declaration, DeclarationDescriptor::NORMAL, true, &var_ok);
2231 if (!var_ok) {
2232 scope_->RemoveUnresolved(var_proxy);
2233 } else {
2234 // At the location of the FunctionDeclaration we assign to the var
2235 // binding.
2236 Assignment* assignment = factory()->NewAssignment(
2237 Token::ASSIGN, var_proxy, NewUnresolved(name, mode), pos);
2238 return factory()->NewExpressionStatement(assignment,
2239 RelocInfo::kNoPosition);
2240 }
2241 }
2220 return factory()->NewEmptyStatement(RelocInfo::kNoPosition); 2242 return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
2221 } 2243 }
2222 2244
2223 2245
2224 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, 2246 Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
2225 bool* ok) { 2247 bool* ok) {
2226 // ClassDeclaration :: 2248 // ClassDeclaration ::
2227 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' 2249 // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'
2228 // 2250 //
2229 // A ClassDeclaration 2251 // A ClassDeclaration
(...skipping 3714 matching lines...) Expand 10 before | Expand all | Expand 10 after
5944 Expression* Parser::SpreadCallNew(Expression* function, 5966 Expression* Parser::SpreadCallNew(Expression* function,
5945 ZoneList<v8::internal::Expression*>* args, 5967 ZoneList<v8::internal::Expression*>* args,
5946 int pos) { 5968 int pos) {
5947 args->InsertAt(0, function, zone()); 5969 args->InsertAt(0, function, zone());
5948 5970
5949 return factory()->NewCallRuntime( 5971 return factory()->NewCallRuntime(
5950 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5972 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5951 } 5973 }
5952 } // namespace internal 5974 } // namespace internal
5953 } // namespace v8 5975 } // namespace v8
OLDNEW
« 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