| OLD | NEW | 
|---|
| 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/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" | 
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" | 
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 711       pending_error_arg_(NULL), | 711       pending_error_arg_(NULL), | 
| 712       pending_error_char_arg_(NULL) { | 712       pending_error_char_arg_(NULL) { | 
| 713   ASSERT(!script_.is_null()); | 713   ASSERT(!script_.is_null()); | 
| 714   isolate_->set_ast_node_id(0); | 714   isolate_->set_ast_node_id(0); | 
| 715   set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 715   set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 
| 716   set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 716   set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 
| 717   set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 717   set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 
| 718   set_allow_lazy(false);  // Must be explicitly enabled. | 718   set_allow_lazy(false);  // Must be explicitly enabled. | 
| 719   set_allow_generators(FLAG_harmony_generators); | 719   set_allow_generators(FLAG_harmony_generators); | 
| 720   set_allow_for_of(FLAG_harmony_iteration); | 720   set_allow_for_of(FLAG_harmony_iteration); | 
|  | 721   set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 
| 721   set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 722   set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 
| 722   for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 723   for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 
| 723        ++feature) { | 724        ++feature) { | 
| 724     use_counts_[feature] = 0; | 725     use_counts_[feature] = 0; | 
| 725   } | 726   } | 
| 726 } | 727 } | 
| 727 | 728 | 
| 728 | 729 | 
| 729 FunctionLiteral* Parser::ParseProgram() { | 730 FunctionLiteral* Parser::ParseProgram() { | 
| 730   // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 731   // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 
| (...skipping 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3264   Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3265   Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 
| 3265   return static_cast<LiteralType>(literal_type->value()); | 3266   return static_cast<LiteralType>(literal_type->value()); | 
| 3266 } | 3267 } | 
| 3267 | 3268 | 
| 3268 | 3269 | 
| 3269 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3270 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 
| 3270   return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3271   return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 
| 3271 } | 3272 } | 
| 3272 | 3273 | 
| 3273 | 3274 | 
|  | 3275 bool CheckAndDeclareArrowParameter(ParserTraits* traits, Expression* expression, | 
|  | 3276                                    Scope* scope, int* num_params, | 
|  | 3277                                    Scanner::Location* dupe_loc) { | 
|  | 3278   // Case for empty parameter lists: | 
|  | 3279   //   () => ... | 
|  | 3280   if (expression == NULL) return true; | 
|  | 3281 | 
|  | 3282   // Too many parentheses around expression: | 
|  | 3283   //   (( ... )) => ... | 
|  | 3284   if (expression->parenthesization_level() > 1) return false; | 
|  | 3285 | 
|  | 3286   // Case for a single parameter: | 
|  | 3287   //   (foo) => ... | 
|  | 3288   //   foo => ... | 
|  | 3289   if (expression->IsVariableProxy()) { | 
|  | 3290     if (expression->AsVariableProxy()->is_this()) return false; | 
|  | 3291 | 
|  | 3292     const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); | 
|  | 3293     if (traits->IsEvalOrArguments(raw_name) || | 
|  | 3294         traits->IsFutureStrictReserved(raw_name)) | 
|  | 3295       return false; | 
|  | 3296 | 
|  | 3297     if (scope->IsDeclared(raw_name)) { | 
|  | 3298       *dupe_loc = Scanner::Location( | 
|  | 3299           expression->position(), expression->position() + raw_name->length()); | 
|  | 3300       return false; | 
|  | 3301     } | 
|  | 3302 | 
|  | 3303     scope->DeclareParameter(raw_name, VAR); | 
|  | 3304     ++(*num_params); | 
|  | 3305     return true; | 
|  | 3306   } | 
|  | 3307 | 
|  | 3308   // Case for more than one parameter: | 
|  | 3309   //   (foo, bar [, ...]) => ... | 
|  | 3310   if (expression->IsBinaryOperation()) { | 
|  | 3311     BinaryOperation* binop = expression->AsBinaryOperation(); | 
|  | 3312     if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() || | 
|  | 3313         binop->right()->is_parenthesized()) | 
|  | 3314       return false; | 
|  | 3315 | 
|  | 3316     return CheckAndDeclareArrowParameter(traits, binop->left(), scope, | 
|  | 3317                                          num_params, dupe_loc) && | 
|  | 3318            CheckAndDeclareArrowParameter(traits, binop->right(), scope, | 
|  | 3319                                          num_params, dupe_loc); | 
|  | 3320   } | 
|  | 3321 | 
|  | 3322   // Any other kind of expression is not a valid parameter list. | 
|  | 3323   return false; | 
|  | 3324 } | 
|  | 3325 | 
|  | 3326 | 
|  | 3327 int ParserTraits::DeclareArrowParametersFromExpression( | 
|  | 3328     Expression* expression, Scope* scope, Scanner::Location* dupe_loc, | 
|  | 3329     bool* ok) { | 
|  | 3330   int num_params = 0; | 
|  | 3331   *ok = CheckAndDeclareArrowParameter(this, expression, scope, &num_params, | 
|  | 3332                                       dupe_loc); | 
|  | 3333   return num_params; | 
|  | 3334 } | 
|  | 3335 | 
|  | 3336 | 
| 3274 FunctionLiteral* Parser::ParseFunctionLiteral( | 3337 FunctionLiteral* Parser::ParseFunctionLiteral( | 
| 3275     const AstRawString* function_name, | 3338     const AstRawString* function_name, | 
| 3276     Scanner::Location function_name_location, | 3339     Scanner::Location function_name_location, | 
| 3277     bool name_is_strict_reserved, | 3340     bool name_is_strict_reserved, | 
| 3278     bool is_generator, | 3341     bool is_generator, | 
| 3279     int function_token_pos, | 3342     int function_token_pos, | 
| 3280     FunctionLiteral::FunctionType function_type, | 3343     FunctionLiteral::FunctionType function_type, | 
| 3281     FunctionLiteral::ArityRestriction arity_restriction, | 3344     FunctionLiteral::ArityRestriction arity_restriction, | 
| 3282     bool* ok) { | 3345     bool* ok) { | 
| 3283   // Function :: | 3346   // Function :: | 
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3673 | 3736 | 
| 3674   if (reusable_preparser_ == NULL) { | 3737   if (reusable_preparser_ == NULL) { | 
| 3675     intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3738     intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 
| 3676     reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3739     reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 
| 3677     reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3740     reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 
| 3678     reusable_preparser_->set_allow_modules(allow_modules()); | 3741     reusable_preparser_->set_allow_modules(allow_modules()); | 
| 3679     reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3742     reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 
| 3680     reusable_preparser_->set_allow_lazy(true); | 3743     reusable_preparser_->set_allow_lazy(true); | 
| 3681     reusable_preparser_->set_allow_generators(allow_generators()); | 3744     reusable_preparser_->set_allow_generators(allow_generators()); | 
| 3682     reusable_preparser_->set_allow_for_of(allow_for_of()); | 3745     reusable_preparser_->set_allow_for_of(allow_for_of()); | 
|  | 3746     reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | 
| 3683     reusable_preparser_->set_allow_harmony_numeric_literals( | 3747     reusable_preparser_->set_allow_harmony_numeric_literals( | 
| 3684         allow_harmony_numeric_literals()); | 3748         allow_harmony_numeric_literals()); | 
| 3685   } | 3749   } | 
| 3686   PreParser::PreParseResult result = | 3750   PreParser::PreParseResult result = | 
| 3687       reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3751       reusable_preparser_->PreParseLazyFunction(strict_mode(), | 
| 3688                                                 is_generator(), | 3752                                                 is_generator(), | 
| 3689                                                 logger); | 3753                                                 logger); | 
| 3690   return result; | 3754   return result; | 
| 3691 } | 3755 } | 
| 3692 | 3756 | 
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4742     info()->SetAstValueFactory(ast_value_factory_); | 4806     info()->SetAstValueFactory(ast_value_factory_); | 
| 4743   } | 4807   } | 
| 4744   ast_value_factory_ = NULL; | 4808   ast_value_factory_ = NULL; | 
| 4745 | 4809 | 
| 4746   InternalizeUseCounts(); | 4810   InternalizeUseCounts(); | 
| 4747 | 4811 | 
| 4748   return (result != NULL); | 4812   return (result != NULL); | 
| 4749 } | 4813 } | 
| 4750 | 4814 | 
| 4751 } }  // namespace v8::internal | 4815 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|