OLD | NEW |
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 Token::Value JavaScriptScanner::SkipSingleLineComment() { | 140 Token::Value JavaScriptScanner::SkipSingleLineComment() { |
141 Advance(); | 141 Advance(); |
142 | 142 |
143 // The line terminator at the end of the line is not considered | 143 // The line terminator at the end of the line is not considered |
144 // to be part of the single-line comment; it is recognized | 144 // to be part of the single-line comment; it is recognized |
145 // separately by the lexical grammar and becomes part of the | 145 // separately by the lexical grammar and becomes part of the |
146 // stream of input elements for the syntactic grammar (see | 146 // stream of input elements for the syntactic grammar (see |
147 // ECMA-262, section 7.4, page 12). | 147 // ECMA-262, section 7.4). |
148 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { | 148 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { |
149 Advance(); | 149 Advance(); |
150 } | 150 } |
151 | 151 |
152 return Token::WHITESPACE; | 152 return Token::WHITESPACE; |
153 } | 153 } |
154 | 154 |
155 | 155 |
156 Token::Value JavaScriptScanner::SkipMultiLineComment() { | 156 Token::Value JavaScriptScanner::SkipMultiLineComment() { |
157 ASSERT(c0_ == '*'); | 157 ASSERT(c0_ == '*'); |
158 Advance(); | 158 Advance(); |
159 | 159 |
160 while (c0_ >= 0) { | 160 while (c0_ >= 0) { |
161 char ch = c0_; | 161 char ch = c0_; |
162 Advance(); | 162 Advance(); |
| 163 if (unicode_cache_->IsLineTerminator(ch)) { |
| 164 // Following ECMA-262, section 7.4, a comment containing |
| 165 // a newline will make the comment count as a line-terminator. |
| 166 has_line_terminator_before_next_ = true; |
| 167 } |
163 // If we have reached the end of the multi-line comment, we | 168 // If we have reached the end of the multi-line comment, we |
164 // consume the '/' and insert a whitespace. This way all | 169 // consume the '/' and insert a whitespace. This way all |
165 // multi-line comments are treated as whitespace - even the ones | 170 // multi-line comments are treated as whitespace. |
166 // containing line terminators. This contradicts ECMA-262, section | |
167 // 7.4, page 12, that says that multi-line comments containing | |
168 // line terminators should be treated as a line terminator, but it | |
169 // matches the behaviour of SpiderMonkey and KJS. | |
170 if (ch == '*' && c0_ == '/') { | 171 if (ch == '*' && c0_ == '/') { |
171 c0_ = ' '; | 172 c0_ = ' '; |
172 return Token::WHITESPACE; | 173 return Token::WHITESPACE; |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
176 // Unterminated multi-line comment. | 177 // Unterminated multi-line comment. |
177 return Token::ILLEGAL; | 178 return Token::ILLEGAL; |
178 } | 179 } |
179 | 180 |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | 944 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; |
944 break; | 945 break; |
945 case UNMATCHABLE: | 946 case UNMATCHABLE: |
946 break; | 947 break; |
947 } | 948 } |
948 // On fallthrough, it's a failure. | 949 // On fallthrough, it's a failure. |
949 state_ = UNMATCHABLE; | 950 state_ = UNMATCHABLE; |
950 } | 951 } |
951 | 952 |
952 } } // namespace v8::internal | 953 } } // namespace v8::internal |
OLD | NEW |