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

Side by Side Diff: src/parser.cc

Issue 1400973002: Throw when calling an undefined function Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « src/parser.h ('k') | src/v8natives.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/parser.h" 5 #include "src/parser.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 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 scope->set_end_position(scanner()->peek_location().beg_pos); 1064 scope->set_end_position(scanner()->peek_location().beg_pos);
1065 1065
1066 if (ok && is_strict(language_mode())) { 1066 if (ok && is_strict(language_mode())) {
1067 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 1067 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
1068 } 1068 }
1069 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) { 1069 if (ok && is_sloppy(language_mode()) && allow_harmony_sloppy_function()) {
1070 // TODO(littledan): Function bindings on the global object that modify 1070 // TODO(littledan): Function bindings on the global object that modify
1071 // pre-existing bindings should be made writable, enumerable and 1071 // pre-existing bindings should be made writable, enumerable and
1072 // nonconfigurable if possible, whereas this code will leave attributes 1072 // nonconfigurable if possible, whereas this code will leave attributes
1073 // unchanged if the property already exists. 1073 // unchanged if the property already exists.
1074 InsertSloppyBlockFunctionVarBindings(scope, &ok); 1074 InsertSloppyBlockFunctionVarBindings(scope, body, &ok);
1075 } 1075 }
1076 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy())) { 1076 if (ok && (is_strict(language_mode()) || allow_harmony_sloppy())) {
1077 CheckConflictingVarDeclarations(scope_, &ok); 1077 CheckConflictingVarDeclarations(scope_, &ok);
1078 } 1078 }
1079 1079
1080 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 1080 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
1081 if (body->length() != 1 || 1081 if (body->length() != 1 ||
1082 !body->at(0)->IsExpressionStatement() || 1082 !body->at(0)->IsExpressionStatement() ||
1083 !body->at(0)->AsExpressionStatement()-> 1083 !body->at(0)->AsExpressionStatement()->
1084 expression()->IsFunctionLiteral()) { 1084 expression()->IsFunctionLiteral()) {
(...skipping 3223 matching lines...) Expand 10 before | Expand all | Expand 10 after
4308 const bool allow_duplicate_parameters = 4308 const bool allow_duplicate_parameters =
4309 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); 4309 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind);
4310 ValidateFormalParameters(&formals_classifier, language_mode, 4310 ValidateFormalParameters(&formals_classifier, language_mode,
4311 allow_duplicate_parameters, CHECK_OK); 4311 allow_duplicate_parameters, CHECK_OK);
4312 4312
4313 if (is_strict(language_mode)) { 4313 if (is_strict(language_mode)) {
4314 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 4314 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
4315 CHECK_OK); 4315 CHECK_OK);
4316 } 4316 }
4317 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) { 4317 if (is_sloppy(language_mode) && allow_harmony_sloppy_function()) {
4318 InsertSloppyBlockFunctionVarBindings(scope, CHECK_OK); 4318 InsertSloppyBlockFunctionVarBindings(scope, body, CHECK_OK);
4319 } 4319 }
4320 if (is_strict(language_mode) || allow_harmony_sloppy()) { 4320 if (is_strict(language_mode) || allow_harmony_sloppy()) {
4321 CheckConflictingVarDeclarations(scope, CHECK_OK); 4321 CheckConflictingVarDeclarations(scope, CHECK_OK);
4322 } 4322 }
4323 } 4323 }
4324 4324
4325 bool has_duplicate_parameters = 4325 bool has_duplicate_parameters =
4326 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4326 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4327 FunctionLiteral::ParameterFlag duplicate_parameters = 4327 FunctionLiteral::ParameterFlag duplicate_parameters =
4328 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters 4328 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
4996 VariableProxy* from = factory()->NewVariableProxy(parameter); 4996 VariableProxy* from = factory()->NewVariableProxy(parameter);
4997 Expression* assignment = factory()->NewAssignment( 4997 Expression* assignment = factory()->NewAssignment(
4998 Token::ASSIGN, to, from, RelocInfo::kNoPosition); 4998 Token::ASSIGN, to, from, RelocInfo::kNoPosition);
4999 Statement* statement = factory()->NewExpressionStatement( 4999 Statement* statement = factory()->NewExpressionStatement(
5000 assignment, RelocInfo::kNoPosition); 5000 assignment, RelocInfo::kNoPosition);
5001 inner_block->statements()->InsertAt(0, statement, zone()); 5001 inner_block->statements()->InsertAt(0, statement, zone());
5002 } 5002 }
5003 } 5003 }
5004 5004
5005 5005
5006 void Parser::InsertSloppyBlockFunctionVarBindings(Scope* scope, bool* ok) { 5006 void Parser::InsertSloppyBlockFunctionVarBindings(Scope* scope, ZoneList<Stateme nt*>* body, bool* ok) {
5007 // For each variable which is used as a function declaration in a sloppy 5007 // For each variable which is used as a function declaration in a sloppy
5008 // block, 5008 // block,
5009 DCHECK(scope->is_declaration_scope()); 5009 DCHECK(scope->is_declaration_scope());
5010 SloppyBlockFunctionMap* map = scope->sloppy_block_function_map(); 5010 SloppyBlockFunctionMap* map = scope->sloppy_block_function_map();
5011 for (ZoneHashMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) { 5011 for (ZoneHashMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
5012 AstRawString* name = static_cast<AstRawString*>(p->key); 5012 AstRawString* name = static_cast<AstRawString*>(p->key);
5013 // If the variable wouldn't conflict with a lexical declaration, 5013 // If the variable wouldn't conflict with a lexical declaration,
5014 Variable* var = scope->LookupLocal(name); 5014 Variable* var = scope->LookupLocal(name);
5015 if (var == nullptr || !IsLexicalVariableMode(var->mode())) { 5015 if (var == nullptr || !IsLexicalVariableMode(var->mode())) {
5016 // Declare a var-style binding for the function in the outer scope 5016 // Declare a var-style binding for the function in the outer scope
5017 VariableProxy* proxy = scope->NewUnresolved(factory(), name); 5017 VariableProxy* proxy = scope->NewUnresolved(factory(), name);
5018 Declaration* declaration = factory()->NewVariableDeclaration( 5018 Declaration* declaration = factory()->NewVariableDeclaration(
5019 proxy, VAR, scope, RelocInfo::kNoPosition); 5019 proxy, VAR, scope, RelocInfo::kNoPosition);
5020 Declare(declaration, DeclarationDescriptor::NORMAL, true, ok, scope); 5020 Declare(declaration, DeclarationDescriptor::NORMAL, true, ok, scope);
5021 DCHECK(ok); // Based on the preceding check, this should not fail 5021 DCHECK(ok); // Based on the preceding check, this should not fail
5022 if (!ok) return; 5022 if (!ok) return;
5023 5023
5024 // For testing, insert an initializing assignment to the function
5025 // setting it to "throwLittleDan".
5026 VariableProxy* littledanVariable = scope_->NewUnresolved(
5027 factory(), ast_value_factory()->throwLittleDan_string(), Variable: :NORMAL,
5028 RelocInfo::kNoPosition, RelocInfo::kNoPosition);
5029 Assignment* littledanAssignment = factory()->NewAssignment(
5030 Token::ASSIGN, proxy, littledanVariable, RelocInfo::kNoPosition);
5031 Statement* littledanStatement = factory()->NewExpressionStatement(
5032 littledanAssignment, RelocInfo::kNoPosition);
5033 body->InsertAt(0, littledanStatement, zone());
5034
5024 // Write in assignments to var for each block-scoped function declaration 5035 // Write in assignments to var for each block-scoped function declaration
5025 auto delegates = static_cast<SloppyBlockFunctionMap::Vector*>(p->value); 5036 auto delegates = static_cast<SloppyBlockFunctionMap::Vector*>(p->value);
5026 for (SloppyBlockFunctionStatement* delegate : *delegates) { 5037 for (SloppyBlockFunctionStatement* delegate : *delegates) {
5027 // Read from the local lexical scope and write to the function scope 5038 // Read from the local lexical scope and write to the function scope
5028 VariableProxy* to = scope->NewUnresolved(factory(), name); 5039 VariableProxy* to = scope->NewUnresolved(factory(), name);
5029 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name); 5040 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name);
5030 Expression* assignment = factory()->NewAssignment( 5041 Expression* assignment = factory()->NewAssignment(
5031 Token::ASSIGN, to, from, RelocInfo::kNoPosition); 5042 Token::ASSIGN, to, from, RelocInfo::kNoPosition);
5032 Statement* statement = factory()->NewExpressionStatement( 5043 Statement* statement = factory()->NewExpressionStatement(
5033 assignment, RelocInfo::kNoPosition); 5044 assignment, RelocInfo::kNoPosition);
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
6342 6353
6343 Expression* Parser::SpreadCallNew(Expression* function, 6354 Expression* Parser::SpreadCallNew(Expression* function,
6344 ZoneList<v8::internal::Expression*>* args, 6355 ZoneList<v8::internal::Expression*>* args,
6345 int pos) { 6356 int pos) {
6346 args->InsertAt(0, function, zone()); 6357 args->InsertAt(0, function, zone());
6347 6358
6348 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6359 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6349 } 6360 }
6350 } // namespace internal 6361 } // namespace internal
6351 } // namespace v8 6362 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698