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

Side by Side Diff: src/scopes.h

Issue 1332873003: Implement sloppy-mode block-defined functions (Annex B 3.3) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Improve type clarity Created 5 years, 3 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/rewriter.cc ('k') | src/scopes.cc » ('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 #ifndef V8_SCOPES_H_ 5 #ifndef V8_SCOPES_H_
6 #define V8_SCOPES_H_ 6 #define V8_SCOPES_H_
7 7
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/pending-compilation-error-handler.h" 9 #include "src/pending-compilation-error-handler.h"
10 #include "src/zone.h" 10 #include "src/zone.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 int index = mode - DYNAMIC; 50 int index = mode - DYNAMIC;
51 DCHECK(index >= 0 && index < 3); 51 DCHECK(index >= 0 && index < 3);
52 return maps_[index]; 52 return maps_[index];
53 } 53 }
54 54
55 private: 55 private:
56 VariableMap *maps_[3]; 56 VariableMap *maps_[3];
57 }; 57 };
58 58
59 59
60 // Sloppy block-scoped function declarations to var-bind
61 class SloppyBlockFunctionMap : public ZoneHashMap {
62 public:
63 explicit SloppyBlockFunctionMap(Zone* zone);
64
65 virtual ~SloppyBlockFunctionMap();
66
67 void Declare(const AstRawString* name,
68 SloppyBlockFunctionStatement* statement);
69
70 typedef ZoneVector<SloppyBlockFunctionStatement*> Vector;
71
72 private:
73 Zone* zone_;
74 };
75
76
60 // Global invariants after AST construction: Each reference (i.e. identifier) 77 // Global invariants after AST construction: Each reference (i.e. identifier)
61 // to a JavaScript variable (including global properties) is represented by a 78 // to a JavaScript variable (including global properties) is represented by a
62 // VariableProxy node. Immediately after AST construction and before variable 79 // VariableProxy node. Immediately after AST construction and before variable
63 // allocation, most VariableProxy nodes are "unresolved", i.e. not bound to a 80 // allocation, most VariableProxy nodes are "unresolved", i.e. not bound to a
64 // corresponding variable (though some are bound during parse time). Variable 81 // corresponding variable (though some are bound during parse time). Variable
65 // allocation binds each unresolved VariableProxy to one Variable and assigns 82 // allocation binds each unresolved VariableProxy to one Variable and assigns
66 // a location. Note that many VariableProxy nodes may refer to the same Java- 83 // a location. Note that many VariableProxy nodes may refer to the same Java-
67 // Script variable. 84 // Script variable.
68 85
69 class Scope: public ZoneObject { 86 class Scope: public ZoneObject {
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 return variables_.Lookup(name) != NULL; 554 return variables_.Lookup(name) != NULL;
538 } 555 }
539 556
540 bool IsDeclaredParameter(const AstRawString* name) { 557 bool IsDeclaredParameter(const AstRawString* name) {
541 // If IsSimpleParameterList is false, duplicate parameters are not allowed, 558 // If IsSimpleParameterList is false, duplicate parameters are not allowed,
542 // however `arguments` may be allowed if function is not strict code. Thus, 559 // however `arguments` may be allowed if function is not strict code. Thus,
543 // the assumptions explained above do not hold. 560 // the assumptions explained above do not hold.
544 return params_.Contains(variables_.Lookup(name)); 561 return params_.Contains(variables_.Lookup(name));
545 } 562 }
546 563
564 SloppyBlockFunctionMap* sloppy_block_function_map() {
565 return &sloppy_block_function_map_;
566 }
567
547 // Error handling. 568 // Error handling.
548 void ReportMessage(int start_position, int end_position, 569 void ReportMessage(int start_position, int end_position,
549 MessageTemplate::Template message, 570 MessageTemplate::Template message,
550 const AstRawString* arg); 571 const AstRawString* arg);
551 572
552 // --------------------------------------------------------------------------- 573 // ---------------------------------------------------------------------------
553 // Debugging. 574 // Debugging.
554 575
555 #ifdef DEBUG 576 #ifdef DEBUG
556 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively 577 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 VariableDeclaration* function_; 616 VariableDeclaration* function_;
596 // new.target variable, function scopes only. 617 // new.target variable, function scopes only.
597 Variable* new_target_; 618 Variable* new_target_;
598 // Convenience variable; function scopes only. 619 // Convenience variable; function scopes only.
599 Variable* arguments_; 620 Variable* arguments_;
600 // Convenience variable; Subclass constructor only 621 // Convenience variable; Subclass constructor only
601 Variable* this_function_; 622 Variable* this_function_;
602 // Module descriptor; module scopes only. 623 // Module descriptor; module scopes only.
603 ModuleDescriptor* module_descriptor_; 624 ModuleDescriptor* module_descriptor_;
604 625
626 // Map of function names to lists of functions defined in sloppy blocks
627 SloppyBlockFunctionMap sloppy_block_function_map_;
628
605 // Illegal redeclaration. 629 // Illegal redeclaration.
606 Expression* illegal_redecl_; 630 Expression* illegal_redecl_;
607 631
608 // Scope-specific information computed during parsing. 632 // Scope-specific information computed during parsing.
609 // 633 //
610 // This scope is inside a 'with' of some outer scope. 634 // This scope is inside a 'with' of some outer scope.
611 bool scope_inside_with_; 635 bool scope_inside_with_;
612 // This scope contains a 'with' statement. 636 // This scope contains a 'with' statement.
613 bool scope_contains_with_; 637 bool scope_contains_with_;
614 // This scope or a nested catch scope or with scope contain an 'eval' call. At 638 // This scope or a nested catch scope or with scope contain an 'eval' call. At
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 PendingCompilationErrorHandler pending_error_handler_; 817 PendingCompilationErrorHandler pending_error_handler_;
794 818
795 // For tracking which classes are declared consecutively. Needed for strong 819 // For tracking which classes are declared consecutively. Needed for strong
796 // mode. 820 // mode.
797 int class_declaration_group_start_; 821 int class_declaration_group_start_;
798 }; 822 };
799 823
800 } } // namespace v8::internal 824 } } // namespace v8::internal
801 825
802 #endif // V8_SCOPES_H_ 826 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/rewriter.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698