OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 static void TearDownFunctionState(FunctionState* function_state) { | 441 static void TearDownFunctionState(FunctionState* function_state) { |
442 if (function_state->outer_function_state_ != NULL) { | 442 if (function_state->outer_function_state_ != NULL) { |
443 function_state->isolate_->set_ast_node_id( | 443 function_state->isolate_->set_ast_node_id( |
444 function_state->saved_ast_node_id_); | 444 function_state->saved_ast_node_id_); |
445 } | 445 } |
446 } | 446 } |
447 | 447 |
448 // Helper functions for recursive descent. | 448 // Helper functions for recursive descent. |
449 bool IsEvalOrArguments(Handle<String> identifier) const; | 449 bool IsEvalOrArguments(Handle<String> identifier) const; |
450 | 450 |
451 // Returns true if the expression is of type "this.foo". | |
452 static bool IsThisProperty(Expression* expression); | |
453 | |
451 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { | 454 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { |
452 return ObjectLiteral::IsBoilerplateProperty(property); | 455 return ObjectLiteral::IsBoilerplateProperty(property); |
453 } | 456 } |
454 | 457 |
455 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { | 458 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { |
456 return !string.is_null() && string->AsArrayIndex(index); | 459 return !string.is_null() && string->AsArrayIndex(index); |
457 } | 460 } |
458 | 461 |
462 // Functions for encapsulating the differences between parsing and preparsing; | |
463 // operations interleaved with the recursive descent. | |
459 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) { | 464 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) { |
460 fni->PushLiteralName(id); | 465 fni->PushLiteralName(id); |
461 } | 466 } |
462 | 467 |
463 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 468 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
464 Scope* scope, Expression* value, bool* has_function) { | 469 Scope* scope, Expression* value, bool* has_function) { |
465 if (scope->DeclarationScope()->is_global_scope() && | 470 if (scope->DeclarationScope()->is_global_scope() && |
466 value->AsFunctionLiteral() != NULL) { | 471 value->AsFunctionLiteral() != NULL) { |
467 *has_function = true; | 472 *has_function = true; |
468 value->AsFunctionLiteral()->set_pretenure(); | 473 value->AsFunctionLiteral()->set_pretenure(); |
469 } | 474 } |
470 } | 475 } |
471 | 476 |
477 // If we assign a function literal to a property we pretenure the | |
478 // literal so it can be added as a constant function property. | |
479 static void CheckAssigningFunctionLiteralToProperty(Expression* left, | |
480 Expression* right); | |
481 | |
482 // Signal a reference error if the expression is an invalid left-hand side | |
483 // expression. We could report this as a syntax error but for compatibility | |
484 // with JSC we choose to report the error at runtime. | |
rossberg
2014/03/13 09:25:34
Do we have plans to fix this eventually? It's clea
marja
2014/03/13 15:54:49
Wasn't on my radar (yet), but I'll put it on my TO
| |
485 Expression* ValidateAssignmentLeftHandSide(Expression* expression) const; | |
486 | |
487 // Determine if the expression is a variable proxy and mark it as being used | |
488 // in an assignment or with a increment/decrement operator. This is currently | |
489 // used on for the statically checking assignments to harmony const bindings. | |
490 static Expression* MarkExpressionAsLValue(Expression* expression); | |
491 | |
492 // Checks LHS expression for assignment and prefix/postfix increment/decrement | |
493 // in strict mode. | |
494 void CheckStrictModeLValue(Expression*expression, bool* ok); | |
495 | |
472 // Reporting errors. | 496 // Reporting errors. |
473 void ReportMessageAt(Scanner::Location source_location, | 497 void ReportMessageAt(Scanner::Location source_location, |
474 const char* message, | 498 const char* message, |
475 Vector<const char*> args); | 499 Vector<const char*> args); |
476 void ReportMessage(const char* message, Vector<Handle<String> > args); | 500 void ReportMessage(const char* message, Vector<Handle<String> > args); |
477 void ReportMessageAt(Scanner::Location source_location, | 501 void ReportMessageAt(Scanner::Location source_location, |
478 const char* message, | 502 const char* message, |
479 Vector<Handle<String> > args); | 503 Vector<Handle<String> > args); |
480 | 504 |
481 // "null" return type creators. | 505 // "null" return type creators. |
(...skipping 30 matching lines...) Expand all Loading... | |
512 int pos, Scanner* scanner, | 536 int pos, Scanner* scanner, |
513 AstNodeFactory<AstConstructionVisitor>* factory); | 537 AstNodeFactory<AstConstructionVisitor>* factory); |
514 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 538 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
515 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 539 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
516 } | 540 } |
517 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 541 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
518 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 542 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
519 } | 543 } |
520 | 544 |
521 // Temporary glue; these functions will move to ParserBase. | 545 // Temporary glue; these functions will move to ParserBase. |
522 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); | |
523 Expression* ParseV8Intrinsic(bool* ok); | 546 Expression* ParseV8Intrinsic(bool* ok); |
524 FunctionLiteral* ParseFunctionLiteral( | 547 FunctionLiteral* ParseFunctionLiteral( |
525 Handle<String> name, | 548 Handle<String> name, |
526 Scanner::Location function_name_location, | 549 Scanner::Location function_name_location, |
527 bool name_is_strict_reserved, | 550 bool name_is_strict_reserved, |
528 bool is_generator, | 551 bool is_generator, |
529 int function_token_position, | 552 int function_token_position, |
530 FunctionLiteral::FunctionType type, | 553 FunctionLiteral::FunctionType type, |
531 bool* ok); | 554 bool* ok); |
555 Expression* ParseYieldExpression(bool* ok); | |
556 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); | |
532 | 557 |
533 private: | 558 private: |
534 Parser* parser_; | 559 Parser* parser_; |
535 }; | 560 }; |
536 | 561 |
537 | 562 |
538 class Parser : public ParserBase<ParserTraits> { | 563 class Parser : public ParserBase<ParserTraits> { |
539 public: | 564 public: |
540 explicit Parser(CompilationInfo* info); | 565 explicit Parser(CompilationInfo* info); |
541 ~Parser() { | 566 ~Parser() { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 689 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
665 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 690 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
666 Statement* ParseThrowStatement(bool* ok); | 691 Statement* ParseThrowStatement(bool* ok); |
667 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 692 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
668 TryStatement* ParseTryStatement(bool* ok); | 693 TryStatement* ParseTryStatement(bool* ok); |
669 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 694 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
670 | 695 |
671 // Support for hamony block scoped bindings. | 696 // Support for hamony block scoped bindings. |
672 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); | 697 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); |
673 | 698 |
674 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); | |
675 Expression* ParseYieldExpression(bool* ok); | 699 Expression* ParseYieldExpression(bool* ok); |
676 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); | 700 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); |
677 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 701 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
678 Expression* ParseUnaryExpression(bool* ok); | 702 Expression* ParseUnaryExpression(bool* ok); |
679 Expression* ParsePostfixExpression(bool* ok); | 703 Expression* ParsePostfixExpression(bool* ok); |
680 Expression* ParseLeftHandSideExpression(bool* ok); | 704 Expression* ParseLeftHandSideExpression(bool* ok); |
681 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); | 705 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); |
682 Expression* ParseMemberExpression(bool* ok); | 706 Expression* ParseMemberExpression(bool* ok); |
683 Expression* ParseMemberExpressionContinuation(Expression* expression, | 707 Expression* ParseMemberExpressionContinuation(Expression* expression, |
684 bool* ok); | 708 bool* ok); |
(...skipping 15 matching lines...) Expand all Loading... | |
700 bool* ok); | 724 bool* ok); |
701 | 725 |
702 // Magical syntax support. | 726 // Magical syntax support. |
703 Expression* ParseV8Intrinsic(bool* ok); | 727 Expression* ParseV8Intrinsic(bool* ok); |
704 | 728 |
705 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); | 729 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); |
706 | 730 |
707 // Get odd-ball literals. | 731 // Get odd-ball literals. |
708 Literal* GetLiteralUndefined(int position); | 732 Literal* GetLiteralUndefined(int position); |
709 | 733 |
710 // Determine if the expression is a variable proxy and mark it as being used | |
711 // in an assignment or with a increment/decrement operator. This is currently | |
712 // used on for the statically checking assignments to harmony const bindings. | |
713 void MarkAsLValue(Expression* expression); | |
714 | |
715 // Strict mode validation of LValue expressions | |
716 void CheckStrictModeLValue(Expression* expression, | |
717 bool* ok); | |
718 | |
719 // For harmony block scoping mode: Check if the scope has conflicting var/let | 734 // For harmony block scoping mode: Check if the scope has conflicting var/let |
720 // declarations from different scopes. It covers for example | 735 // declarations from different scopes. It covers for example |
721 // | 736 // |
722 // function f() { { { var x; } let x; } } | 737 // function f() { { { var x; } let x; } } |
723 // function g() { { var x; let x; } } | 738 // function g() { { var x; let x; } } |
724 // | 739 // |
725 // The var declarations are hoisted to the function scope, but originate from | 740 // The var declarations are hoisted to the function scope, but originate from |
726 // a scope where the name has also been let bound or the var declaration is | 741 // a scope where the name has also been let bound or the var declaration is |
727 // hoisted over such a scope. | 742 // hoisted over such a scope. |
728 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); | 743 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 private: | 824 private: |
810 static const int kLiteralTypeSlot = 0; | 825 static const int kLiteralTypeSlot = 0; |
811 static const int kElementsSlot = 1; | 826 static const int kElementsSlot = 1; |
812 | 827 |
813 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 828 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
814 }; | 829 }; |
815 | 830 |
816 } } // namespace v8::internal | 831 } } // namespace v8::internal |
817 | 832 |
818 #endif // V8_PARSER_H_ | 833 #endif // V8_PARSER_H_ |
OLD | NEW |