OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "src/scanner.h" | 9 #include "src/scanner.h" |
10 | 10 |
11 #include "include/v8stdint.h" | 11 #include "include/v8stdint.h" |
12 #include "src/char-predicates-inl.h" | 12 #include "src/char-predicates-inl.h" |
13 #include "src/conversions-inl.h" | 13 #include "src/conversions-inl.h" |
14 #include "src/list-inl.h" | 14 #include "src/list-inl.h" |
15 #include "src/v8.h" | 15 #include "src/v8.h" |
16 #include "src/parser.h" | 16 #include "src/parser.h" |
17 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 | |
22 Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const { | |
23 if (is_one_byte()) { | |
24 return isolate->factory()->InternalizeOneByteString(one_byte_literal()); | |
25 } | |
26 return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); | |
27 } | |
28 | |
29 | |
21 // ---------------------------------------------------------------------------- | 30 // ---------------------------------------------------------------------------- |
22 // Scanner | 31 // Scanner |
23 | 32 |
24 Scanner::Scanner(UnicodeCache* unicode_cache) | 33 Scanner::Scanner(UnicodeCache* unicode_cache) |
25 : unicode_cache_(unicode_cache), | 34 : unicode_cache_(unicode_cache), |
26 octal_pos_(Location::invalid()), | 35 octal_pos_(Location::invalid()), |
27 harmony_scoping_(false), | 36 harmony_scoping_(false), |
28 harmony_modules_(false), | 37 harmony_modules_(false), |
29 harmony_numeric_literals_(false) { } | 38 harmony_numeric_literals_(false) { } |
30 | 39 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 // stream of input elements for the syntactic grammar (see | 296 // stream of input elements for the syntactic grammar (see |
288 // ECMA-262, section 7.4). | 297 // ECMA-262, section 7.4). |
289 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { | 298 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { |
290 Advance(); | 299 Advance(); |
291 } | 300 } |
292 | 301 |
293 return Token::WHITESPACE; | 302 return Token::WHITESPACE; |
294 } | 303 } |
295 | 304 |
296 | 305 |
306 Token::Value Scanner::SkipMagicComment() { | |
307 TryToParseMagicComment(); | |
308 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { | |
309 Advance(); | |
310 } | |
311 | |
312 return Token::WHITESPACE; | |
313 } | |
314 | |
315 | |
316 void Scanner::TryToParseMagicComment() { | |
317 // Magic comments are of the form: //[#@]\s<name>=\s*<value>\s*.* and this | |
318 // function will just return if it cannot parse a magic comment. | |
319 if (!unicode_cache_->IsWhiteSpace(c0_)) | |
320 return; | |
321 Advance(); | |
322 LiteralBuffer name; | |
323 while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_) && | |
324 c0_ != '=') { | |
325 name.AddChar(c0_); | |
326 Advance(); | |
327 } | |
328 if (!name.is_one_byte()) return; | |
329 Vector<const uint8_t> name_literal = name.one_byte_literal(); | |
330 LiteralBuffer* value; | |
331 if (name_literal.IsEqualTo(STATIC_ASCII_VECTOR("sourceURL"))) { | |
332 value = &source_url_; | |
333 } else if (name_literal.IsEqualTo(STATIC_ASCII_VECTOR("sourceMappingURL"))) { | |
334 value = &source_mapping_url_; | |
335 } else { | |
336 return; | |
337 } | |
338 if (c0_ != '=') | |
339 return; | |
340 Advance(); | |
341 value->Reset(); | |
342 while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) { | |
343 Advance(); | |
344 } | |
345 while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_)) { | |
yurys
2014/06/10 14:41:04
This will stop at first whitepace while ContentSea
yurys
2014/06/10 14:46:53
As Vsevolod pointed out sourceURLs that contain wh
| |
346 value->AddChar(c0_); | |
347 Advance(); | |
348 } | |
349 } | |
350 | |
351 | |
297 Token::Value Scanner::SkipMultiLineComment() { | 352 Token::Value Scanner::SkipMultiLineComment() { |
298 ASSERT(c0_ == '*'); | 353 ASSERT(c0_ == '*'); |
299 Advance(); | 354 Advance(); |
300 | 355 |
301 while (c0_ >= 0) { | 356 while (c0_ >= 0) { |
302 uc32 ch = c0_; | 357 uc32 ch = c0_; |
303 Advance(); | 358 Advance(); |
304 if (unicode_cache_->IsLineTerminator(ch)) { | 359 if (unicode_cache_->IsLineTerminator(ch)) { |
305 // Following ECMA-262, section 7.4, a comment containing | 360 // Following ECMA-262, section 7.4, a comment containing |
306 // a newline will make the comment count as a line-terminator. | 361 // a newline will make the comment count as a line-terminator. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 | 506 |
452 case '%': | 507 case '%': |
453 // % %= | 508 // % %= |
454 token = Select('=', Token::ASSIGN_MOD, Token::MOD); | 509 token = Select('=', Token::ASSIGN_MOD, Token::MOD); |
455 break; | 510 break; |
456 | 511 |
457 case '/': | 512 case '/': |
458 // / // /* /= | 513 // / // /* /= |
459 Advance(); | 514 Advance(); |
460 if (c0_ == '/') { | 515 if (c0_ == '/') { |
461 token = SkipSingleLineComment(); | 516 Advance(); |
517 if (c0_ == '@' || c0_ == '#') { | |
518 Advance(); | |
519 token = SkipMagicComment(); | |
520 } else { | |
521 PushBack(c0_); | |
522 token = SkipSingleLineComment(); | |
523 } | |
462 } else if (c0_ == '*') { | 524 } else if (c0_ == '*') { |
463 token = SkipMultiLineComment(); | 525 token = SkipMultiLineComment(); |
464 } else if (c0_ == '=') { | 526 } else if (c0_ == '=') { |
465 token = Select(Token::ASSIGN_DIV); | 527 token = Select(Token::ASSIGN_DIV); |
466 } else { | 528 } else { |
467 token = Token::DIV; | 529 token = Token::DIV; |
468 } | 530 } |
469 break; | 531 break; |
470 | 532 |
471 case '&': | 533 case '&': |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 return isolate->factory()->NewStringFromOneByte( | 1161 return isolate->factory()->NewStringFromOneByte( |
1100 next_literal_one_byte_string(), tenured).ToHandleChecked(); | 1162 next_literal_one_byte_string(), tenured).ToHandleChecked(); |
1101 } else { | 1163 } else { |
1102 return isolate->factory()->NewStringFromTwoByte( | 1164 return isolate->factory()->NewStringFromTwoByte( |
1103 next_literal_two_byte_string(), tenured).ToHandleChecked(); | 1165 next_literal_two_byte_string(), tenured).ToHandleChecked(); |
1104 } | 1166 } |
1105 } | 1167 } |
1106 | 1168 |
1107 | 1169 |
1108 Handle<String> Scanner::AllocateInternalizedString(Isolate* isolate) { | 1170 Handle<String> Scanner::AllocateInternalizedString(Isolate* isolate) { |
1109 if (is_literal_one_byte()) { | 1171 return current_.literal_chars->Internalize(isolate); |
1110 return isolate->factory()->InternalizeOneByteString( | |
1111 literal_one_byte_string()); | |
1112 } else { | |
1113 return isolate->factory()->InternalizeTwoByteString( | |
1114 literal_two_byte_string()); | |
1115 } | |
1116 } | 1172 } |
1117 | 1173 |
1118 | 1174 |
1119 double Scanner::DoubleValue() { | 1175 double Scanner::DoubleValue() { |
1120 ASSERT(is_literal_one_byte()); | 1176 ASSERT(is_literal_one_byte()); |
1121 return StringToDouble( | 1177 return StringToDouble( |
1122 unicode_cache_, | 1178 unicode_cache_, |
1123 literal_one_byte_string(), | 1179 literal_one_byte_string(), |
1124 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); | 1180 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); |
1125 } | 1181 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1271 } | 1327 } |
1272 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1328 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1273 } | 1329 } |
1274 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1330 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1275 | 1331 |
1276 backing_store_.AddBlock(bytes); | 1332 backing_store_.AddBlock(bytes); |
1277 return backing_store_.EndSequence().start(); | 1333 return backing_store_.EndSequence().start(); |
1278 } | 1334 } |
1279 | 1335 |
1280 } } // namespace v8::internal | 1336 } } // namespace v8::internal |
OLD | NEW |