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

Side by Side Diff: src/ast/ast.h

Issue 1712833002: Don't reflect ES2015 Function name inference in Function.prototype.toString (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | src/ast/ast.cc » ('j') | src/objects-printer.cc » ('J')
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 #ifndef V8_AST_AST_H_ 5 #ifndef V8_AST_AST_H_
6 #define V8_AST_AST_H_ 6 #define V8_AST_AST_H_
7 7
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/ast/ast-value-factory.h" 9 #include "src/ast/ast-value-factory.h"
10 #include "src/ast/modules.h" 10 #include "src/ast/modules.h"
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); 1422 DCHECK_LT(offset, static_cast<int>(arraysize(slots_)));
1423 return slots_[offset]; 1423 return slots_[offset];
1424 } 1424 }
1425 void SetSlot(FeedbackVectorSlot slot, int offset = 0) { 1425 void SetSlot(FeedbackVectorSlot slot, int offset = 0) {
1426 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); 1426 DCHECK_LT(offset, static_cast<int>(arraysize(slots_)));
1427 slots_[offset] = slot; 1427 slots_[offset] = slot;
1428 } 1428 }
1429 1429
1430 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } 1430 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; }
1431 1431
1432 bool NeedsSetFunctionName() const { 1432 bool NeedsSetFunctionName() const;
1433 return is_computed_name_ && value_->IsAnonymousFunctionDefinition();
1434 }
1435 1433
1436 protected: 1434 protected:
1437 friend class AstNodeFactory; 1435 friend class AstNodeFactory;
1438 1436
1439 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, 1437 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
1440 bool is_static, bool is_computed_name); 1438 bool is_static, bool is_computed_name);
1441 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, 1439 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
1442 Expression* value, bool is_static, 1440 Expression* value, bool is_static,
1443 bool is_computed_name); 1441 bool is_computed_name);
1444 1442
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 Expression* exception_; 2566 Expression* exception_;
2569 }; 2567 };
2570 2568
2571 2569
2572 class FunctionLiteral final : public Expression { 2570 class FunctionLiteral final : public Expression {
2573 public: 2571 public:
2574 enum FunctionType { 2572 enum FunctionType {
2575 kAnonymousExpression, 2573 kAnonymousExpression,
2576 kNamedExpression, 2574 kNamedExpression,
2577 kDeclaration, 2575 kDeclaration,
2578 kGlobalOrEval 2576 kGetter,
2577 kSetter,
2578 kMethod
2579 }; 2579 };
2580 2580
2581 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters }; 2581 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters };
2582 2582
2583 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; 2583 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
2584 2584
2585 enum ArityRestriction { kNormalArity, kGetterArity, kSetterArity };
2586
2587 DECLARE_NODE_TYPE(FunctionLiteral) 2585 DECLARE_NODE_TYPE(FunctionLiteral)
2588 2586
2589 Handle<String> name() const { return raw_name_->string(); } 2587 Handle<String> name() const { return raw_name_->string(); }
2590 const AstString* raw_name() const { return raw_name_; } 2588 const AstString* raw_name() const { return raw_name_; }
2591 void set_raw_name(const AstString* name) { raw_name_ = name; } 2589 void set_raw_name(const AstString* name) { raw_name_ = name; }
2592 Scope* scope() const { return scope_; } 2590 Scope* scope() const { return scope_; }
2593 ZoneList<Statement*>* body() const { return body_; } 2591 ZoneList<Statement*>* body() const { return body_; }
2594 void set_function_token_position(int pos) { function_token_position_ = pos; } 2592 void set_function_token_position(int pos) { function_token_position_ = pos; }
2595 int function_token_position() const { return function_token_position_; } 2593 int function_token_position() const { return function_token_position_; }
2596 int start_position() const; 2594 int start_position() const;
2597 int end_position() const; 2595 int end_position() const;
2598 int SourceSize() const { return end_position() - start_position(); } 2596 int SourceSize() const { return end_position() - start_position(); }
2599 bool is_expression() const { return IsExpression::decode(bitfield_); } 2597 bool is_declaration() const { return IsDeclaration::decode(bitfield_); }
2600 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); } 2598 bool is_named_expression() const {
2599 return IsNamedExpression::decode(bitfield_);
2600 }
2601 bool is_anonymous_expression() const {
2602 return IsAnonymousExpression::decode(bitfield_);
2603 }
2601 LanguageMode language_mode() const; 2604 LanguageMode language_mode() const;
2602 2605
2603 static bool NeedsHomeObject(Expression* expr); 2606 static bool NeedsHomeObject(Expression* expr);
2604 2607
2605 int materialized_literal_count() { return materialized_literal_count_; } 2608 int materialized_literal_count() { return materialized_literal_count_; }
2606 int expected_property_count() { return expected_property_count_; } 2609 int expected_property_count() { return expected_property_count_; }
2607 int parameter_count() { return parameter_count_; } 2610 int parameter_count() { return parameter_count_; }
2608 2611
2609 bool AllowsLazyCompilation(); 2612 bool AllowsLazyCompilation();
2610 bool AllowsLazyCompilationWithoutContext(); 2613 bool AllowsLazyCompilationWithoutContext();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 const FeedbackVectorSpec* feedback_vector_spec() const { 2686 const FeedbackVectorSpec* feedback_vector_spec() const {
2684 return ast_properties_.get_spec(); 2687 return ast_properties_.get_spec();
2685 } 2688 }
2686 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } 2689 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2687 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } 2690 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2688 void set_dont_optimize_reason(BailoutReason reason) { 2691 void set_dont_optimize_reason(BailoutReason reason) {
2689 dont_optimize_reason_ = reason; 2692 dont_optimize_reason_ = reason;
2690 } 2693 }
2691 2694
2692 bool IsAnonymousFunctionDefinition() const final { 2695 bool IsAnonymousFunctionDefinition() const final {
2693 // TODO(adamk): This isn't quite accurate, as many non-expressions 2696 return is_anonymous_expression();
2694 // (such as concise methods) are marked as anonymous, but it's
2695 // sufficient for the current callers.
2696 return is_anonymous();
2697 } 2697 }
2698 2698
2699 protected: 2699 protected:
2700 FunctionLiteral(Zone* zone, const AstString* name, 2700 FunctionLiteral(Zone* zone, const AstString* name,
2701 AstValueFactory* ast_value_factory, Scope* scope, 2701 AstValueFactory* ast_value_factory, Scope* scope,
2702 ZoneList<Statement*>* body, int materialized_literal_count, 2702 ZoneList<Statement*>* body, int materialized_literal_count,
2703 int expected_property_count, int parameter_count, 2703 int expected_property_count, int parameter_count,
2704 FunctionType function_type, 2704 FunctionType function_type,
2705 ParameterFlag has_duplicate_parameters, 2705 ParameterFlag has_duplicate_parameters,
2706 EagerCompileHint eager_compile_hint, FunctionKind kind, 2706 EagerCompileHint eager_compile_hint, FunctionKind kind,
2707 int position) 2707 int position, bool is_function)
2708 : Expression(zone, position), 2708 : Expression(zone, position),
2709 raw_name_(name), 2709 raw_name_(name),
2710 scope_(scope), 2710 scope_(scope),
2711 body_(body), 2711 body_(body),
2712 raw_inferred_name_(ast_value_factory->empty_string()), 2712 raw_inferred_name_(ast_value_factory->empty_string()),
2713 ast_properties_(zone), 2713 ast_properties_(zone),
2714 dont_optimize_reason_(kNoReason), 2714 dont_optimize_reason_(kNoReason),
2715 materialized_literal_count_(materialized_literal_count), 2715 materialized_literal_count_(materialized_literal_count),
2716 expected_property_count_(expected_property_count), 2716 expected_property_count_(expected_property_count),
2717 parameter_count_(parameter_count), 2717 parameter_count_(parameter_count),
2718 function_token_position_(RelocInfo::kNoPosition) { 2718 function_token_position_(RelocInfo::kNoPosition) {
2719 bitfield_ = 2719 bitfield_ =
2720 IsExpression::encode(function_type != kDeclaration) | 2720 IsDeclaration::encode(function_type == kDeclaration) |
2721 IsAnonymous::encode(function_type == kAnonymousExpression) | 2721 IsNamedExpression::encode(function_type == kNamedExpression) |
2722 IsAnonymousExpression::encode(function_type == kAnonymousExpression) |
2722 Pretenure::encode(false) | 2723 Pretenure::encode(false) |
2723 HasDuplicateParameters::encode(has_duplicate_parameters == 2724 HasDuplicateParameters::encode(has_duplicate_parameters ==
2724 kHasDuplicateParameters) | 2725 kHasDuplicateParameters) |
2725 IsFunction::encode(function_type != kGlobalOrEval) | 2726 IsFunction::encode(is_function) |
2726 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | 2727 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) |
2727 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false); 2728 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false);
2728 DCHECK(IsValidFunctionKind(kind)); 2729 DCHECK(IsValidFunctionKind(kind));
2729 } 2730 }
2730 2731
2731 private: 2732 private:
2732 class IsExpression : public BitField16<bool, 0, 1> {}; 2733 class IsDeclaration : public BitField16<bool, 0, 1> {};
2733 class IsAnonymous : public BitField16<bool, 1, 1> {}; 2734 class IsNamedExpression : public BitField16<bool, 1, 1> {};
2734 class Pretenure : public BitField16<bool, 2, 1> {}; 2735 class IsAnonymousExpression : public BitField16<bool, 2, 1> {};
2735 class HasDuplicateParameters : public BitField16<bool, 3, 1> {}; 2736 class Pretenure : public BitField16<bool, 3, 1> {};
2736 class IsFunction : public BitField16<bool, 4, 1> {}; 2737 class HasDuplicateParameters : public BitField16<bool, 4, 1> {};
2737 class ShouldEagerCompile : public BitField16<bool, 5, 1> {}; 2738 class IsFunction : public BitField16<bool, 5, 1> {};
2738 class FunctionKindBits : public BitField16<FunctionKind, 6, 8> {}; 2739 class ShouldEagerCompile : public BitField16<bool, 6, 1> {};
2739 class ShouldBeUsedOnceHint : public BitField16<bool, 15, 1> {}; 2740 class ShouldBeUsedOnceHint : public BitField16<bool, 7, 1> {};
2741 class FunctionKindBits : public BitField16<FunctionKind, 8, 7> {};
2740 2742
2741 // Start with 16-bit field, which should get packed together 2743 // Start with 16-bit field, which should get packed together
2742 // with Expression's trailing 16-bit field. 2744 // with Expression's trailing 16-bit field.
2743 uint16_t bitfield_; 2745 uint16_t bitfield_;
2744 2746
2745 const AstString* raw_name_; 2747 const AstString* raw_name_;
2746 Scope* scope_; 2748 Scope* scope_;
2747 ZoneList<Statement*>* body_; 2749 ZoneList<Statement*>* body_;
2748 const AstString* raw_inferred_name_; 2750 const AstString* raw_inferred_name_;
2749 Handle<String> inferred_name_; 2751 Handle<String> inferred_name_;
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
3406 int materialized_literal_count, int expected_property_count, 3408 int materialized_literal_count, int expected_property_count,
3407 int parameter_count, 3409 int parameter_count,
3408 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3410 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3409 FunctionLiteral::FunctionType function_type, 3411 FunctionLiteral::FunctionType function_type,
3410 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, 3412 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
3411 int position) { 3413 int position) {
3412 return new (parser_zone_) FunctionLiteral( 3414 return new (parser_zone_) FunctionLiteral(
3413 parser_zone_, name, ast_value_factory_, scope, body, 3415 parser_zone_, name, ast_value_factory_, scope, body,
3414 materialized_literal_count, expected_property_count, parameter_count, 3416 materialized_literal_count, expected_property_count, parameter_count,
3415 function_type, has_duplicate_parameters, eager_compile_hint, kind, 3417 function_type, has_duplicate_parameters, eager_compile_hint, kind,
3416 position); 3418 position, true);
3419 }
3420
3421 FunctionLiteral* NewGlobalOrEvalFunctionLiteral(
Dan Ehrenberg 2016/02/19 00:10:41 GlobalOrEval is a pretty confusing name. What if w
adamk 2016/02/19 01:09:15 Hmm, but this is also used for Function-constructo
adamk 2016/02/19 02:02:19 Renamed a bit and added a comment.
3422 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3423 int expected_property_count) {
3424 return new (parser_zone_) FunctionLiteral(
3425 parser_zone_, ast_value_factory_->empty_string(), ast_value_factory_,
3426 scope, body, materialized_literal_count, expected_property_count, 0,
3427 FunctionLiteral::kAnonymousExpression,
3428 FunctionLiteral::kNoDuplicateParameters,
3429 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0,
3430 false);
3417 } 3431 }
3418 3432
3419 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy, 3433 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy,
3420 Expression* extends, 3434 Expression* extends,
3421 FunctionLiteral* constructor, 3435 FunctionLiteral* constructor,
3422 ZoneList<ObjectLiteral::Property*>* properties, 3436 ZoneList<ObjectLiteral::Property*>* properties,
3423 int start_position, int end_position) { 3437 int start_position, int end_position) {
3424 return new (parser_zone_) 3438 return new (parser_zone_)
3425 ClassLiteral(parser_zone_, scope, proxy, extends, constructor, 3439 ClassLiteral(parser_zone_, scope, proxy, extends, constructor,
3426 properties, start_position, end_position); 3440 properties, start_position, end_position);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3490 // the parser-level zone. 3504 // the parser-level zone.
3491 Zone* parser_zone_; 3505 Zone* parser_zone_;
3492 AstValueFactory* ast_value_factory_; 3506 AstValueFactory* ast_value_factory_;
3493 }; 3507 };
3494 3508
3495 3509
3496 } // namespace internal 3510 } // namespace internal
3497 } // namespace v8 3511 } // namespace v8
3498 3512
3499 #endif // V8_AST_AST_H_ 3513 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | src/objects-printer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698