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

Side by Side Diff: src/preparser.h

Issue 8306024: Make native syntax an early error in the preparser. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 }; 103 };
104 104
105 105
106 class PreParser { 106 class PreParser {
107 public: 107 public:
108 enum PreParseResult { 108 enum PreParseResult {
109 kPreParseStackOverflow, 109 kPreParseStackOverflow,
110 kPreParseSuccess 110 kPreParseSuccess
111 }; 111 };
112 112
113 enum Flags {
114 kNoFlags = 0,
115 kAllowLazy = 1,
116 kAllowNativesSyntax = 2
117 };
118
113 ~PreParser() {} 119 ~PreParser() {}
114 120
115 // Pre-parse the program from the character stream; returns true on 121 // Pre-parse the program from the character stream; returns true on
116 // success (even if parsing failed, the pre-parse data successfully 122 // success (even if parsing failed, the pre-parse data successfully
117 // captured the syntax error), and false if a stack-overflow happened 123 // captured the syntax error), and false if a stack-overflow happened
118 // during parsing. 124 // during parsing.
119 static PreParseResult PreParseProgram(i::JavaScriptScanner* scanner, 125 static PreParseResult PreParseProgram(i::JavaScriptScanner* scanner,
120 i::ParserRecorder* log, 126 i::ParserRecorder* log,
121 bool allow_lazy, 127 int flags,
122 uintptr_t stack_limit) { 128 uintptr_t stack_limit) {
123 return PreParser(scanner, log, stack_limit, allow_lazy).PreParse(); 129 bool allow_lazy = (flags & kAllowLazy) != 0;
130 bool allow_natives_syntax = (flags & kAllowNativesSyntax) != 0;
131 return PreParser(scanner, log, stack_limit,
132 allow_lazy, allow_natives_syntax).PreParse();
124 } 133 }
125 134
126 private: 135 private:
127 // Used to detect duplicates in object literals. Each of the values 136 // Used to detect duplicates in object literals. Each of the values
128 // kGetterProperty, kSetterProperty and kValueProperty represents 137 // kGetterProperty, kSetterProperty and kValueProperty represents
129 // a type of object literal property. When parsing a property, its 138 // a type of object literal property. When parsing a property, its
130 // type value is stored in the DuplicateFinder for the property name. 139 // type value is stored in the DuplicateFinder for the property name.
131 // Values are chosen so that having intersection bits means the there is 140 // Values are chosen so that having intersection bits means the there is
132 // an incompatibility. 141 // an incompatibility.
133 // I.e., you can add a getter to a property that already has a setter, since 142 // I.e., you can add a getter to a property that already has a setter, since
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 int materialized_literal_count_; 439 int materialized_literal_count_;
431 int expected_properties_; 440 int expected_properties_;
432 int with_nesting_count_; 441 int with_nesting_count_;
433 bool strict_; 442 bool strict_;
434 }; 443 };
435 444
436 // Private constructor only used in PreParseProgram. 445 // Private constructor only used in PreParseProgram.
437 PreParser(i::JavaScriptScanner* scanner, 446 PreParser(i::JavaScriptScanner* scanner,
438 i::ParserRecorder* log, 447 i::ParserRecorder* log,
439 uintptr_t stack_limit, 448 uintptr_t stack_limit,
440 bool allow_lazy) 449 bool allow_lazy,
450 bool allow_natives_syntax)
441 : scanner_(scanner), 451 : scanner_(scanner),
442 log_(log), 452 log_(log),
443 scope_(NULL), 453 scope_(NULL),
444 stack_limit_(stack_limit), 454 stack_limit_(stack_limit),
445 strict_mode_violation_location_(i::Scanner::Location::invalid()), 455 strict_mode_violation_location_(i::Scanner::Location::invalid()),
446 strict_mode_violation_type_(NULL), 456 strict_mode_violation_type_(NULL),
447 stack_overflow_(false), 457 stack_overflow_(false),
448 allow_lazy_(true), 458 allow_lazy_(allow_lazy),
459 allow_natives_syntax_(allow_natives_syntax),
449 parenthesized_function_(false), 460 parenthesized_function_(false),
450 harmony_scoping_(scanner->HarmonyScoping()) { } 461 harmony_scoping_(scanner->HarmonyScoping()) { }
451 462
452 // Preparse the program. Only called in PreParseProgram after creating 463 // Preparse the program. Only called in PreParseProgram after creating
453 // the instance. 464 // the instance.
454 PreParseResult PreParse() { 465 PreParseResult PreParse() {
455 Scope top_scope(&scope_, kTopLevelScope); 466 Scope top_scope(&scope_, kTopLevelScope);
456 bool ok = true; 467 bool ok = true;
457 int start_position = scanner_->peek_location().beg_pos; 468 int start_position = scanner_->peek_location().beg_pos;
458 ParseSourceElements(i::Token::EOS, &ok); 469 ParseSourceElements(i::Token::EOS, &ok);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 bool* ok); 611 bool* ok);
601 612
602 i::JavaScriptScanner* scanner_; 613 i::JavaScriptScanner* scanner_;
603 i::ParserRecorder* log_; 614 i::ParserRecorder* log_;
604 Scope* scope_; 615 Scope* scope_;
605 uintptr_t stack_limit_; 616 uintptr_t stack_limit_;
606 i::Scanner::Location strict_mode_violation_location_; 617 i::Scanner::Location strict_mode_violation_location_;
607 const char* strict_mode_violation_type_; 618 const char* strict_mode_violation_type_;
608 bool stack_overflow_; 619 bool stack_overflow_;
609 bool allow_lazy_; 620 bool allow_lazy_;
621 bool allow_natives_syntax_;
610 bool parenthesized_function_; 622 bool parenthesized_function_;
611 bool harmony_scoping_; 623 bool harmony_scoping_;
612 }; 624 };
613 } } // v8::preparser 625 } } // v8::preparser
614 626
615 #endif // V8_PREPARSER_H 627 #endif // V8_PREPARSER_H
OLDNEW
« src/parser.h ('K') | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698