| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // ---------------------------------------------------------------------------- | 60 // ---------------------------------------------------------------------------- |
| 61 // Scanner | 61 // Scanner |
| 62 | 62 |
| 63 Scanner::Scanner(Isolate* isolate) | 63 Scanner::Scanner(Isolate* isolate) |
| 64 : scanner_constants_(isolate->scanner_constants()) { | 64 : scanner_constants_(isolate->scanner_constants()), |
| 65 octal_pos_(kNoOctalLocation) { |
| 65 } | 66 } |
| 66 | 67 |
| 67 | 68 |
| 68 uc32 Scanner::ScanHexEscape(uc32 c, int length) { | 69 uc32 Scanner::ScanHexEscape(uc32 c, int length) { |
| 69 ASSERT(length <= 4); // prevent overflow | 70 ASSERT(length <= 4); // prevent overflow |
| 70 | 71 |
| 71 uc32 digits[4]; | 72 uc32 digits[4]; |
| 72 uc32 x = 0; | 73 uc32 x = 0; |
| 73 for (int i = 0; i < length; i++) { | 74 for (int i = 0; i < length; i++) { |
| 74 digits[i] = c0_; | 75 digits[i] = c0_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 Advance(); | 90 Advance(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 return x; | 93 return x; |
| 93 } | 94 } |
| 94 | 95 |
| 95 | 96 |
| 96 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of | 97 // Octal escapes of the forms '\0xx' and '\xxx' are not a part of |
| 97 // ECMA-262. Other JS VMs support them. | 98 // ECMA-262. Other JS VMs support them. |
| 98 uc32 Scanner::ScanOctalEscape(uc32 c, int length) { | 99 uc32 Scanner::ScanOctalEscape(uc32 c, int length) { |
| 100 octal_pos_ = source_pos() - 1; // Already advanced |
| 99 uc32 x = c - '0'; | 101 uc32 x = c - '0'; |
| 100 for (int i = 0; i < length; i++) { | 102 for (int i = 0; i < length; i++) { |
| 101 int d = c0_ - '0'; | 103 int d = c0_ - '0'; |
| 102 if (d < 0 || d > 7) break; | 104 if (d < 0 || d > 7) break; |
| 103 int nx = x * 8 + d; | 105 int nx = x * 8 + d; |
| 104 if (nx >= 256) break; | 106 if (nx >= 256) break; |
| 105 x = nx; | 107 x = nx; |
| 106 Advance(); | 108 Advance(); |
| 107 } | 109 } |
| 108 return x; | 110 return x; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 AddLiteralCharAdvance(); | 594 AddLiteralCharAdvance(); |
| 593 } | 595 } |
| 594 } else if ('0' <= c0_ && c0_ <= '7') { | 596 } else if ('0' <= c0_ && c0_ <= '7') { |
| 595 // (possible) octal number | 597 // (possible) octal number |
| 596 kind = OCTAL; | 598 kind = OCTAL; |
| 597 while (true) { | 599 while (true) { |
| 598 if (c0_ == '8' || c0_ == '9') { | 600 if (c0_ == '8' || c0_ == '9') { |
| 599 kind = DECIMAL; | 601 kind = DECIMAL; |
| 600 break; | 602 break; |
| 601 } | 603 } |
| 602 if (c0_ < '0' || '7' < c0_) break; | 604 if (c0_ < '0' || '7' < c0_) { |
| 605 // Octal literal finished. |
| 606 octal_pos_ = next_.location.beg_pos; |
| 607 break; |
| 608 } |
| 603 AddLiteralCharAdvance(); | 609 AddLiteralCharAdvance(); |
| 604 } | 610 } |
| 605 } | 611 } |
| 606 } | 612 } |
| 607 | 613 |
| 608 // Parse decimal digits and allow trailing fractional part. | 614 // Parse decimal digits and allow trailing fractional part. |
| 609 if (kind == DECIMAL) { | 615 if (kind == DECIMAL) { |
| 610 ScanDecimalDigits(); // optional | 616 ScanDecimalDigits(); // optional |
| 611 if (c0_ == '.') { | 617 if (c0_ == '.') { |
| 612 AddLiteralCharAdvance(); | 618 AddLiteralCharAdvance(); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | 905 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; |
| 900 break; | 906 break; |
| 901 case UNMATCHABLE: | 907 case UNMATCHABLE: |
| 902 break; | 908 break; |
| 903 } | 909 } |
| 904 // On fallthrough, it's a failure. | 910 // On fallthrough, it's a failure. |
| 905 state_ = UNMATCHABLE; | 911 state_ = UNMATCHABLE; |
| 906 } | 912 } |
| 907 | 913 |
| 908 } } // namespace v8::internal | 914 } } // namespace v8::internal |
| OLD | NEW |