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

Side by Side Diff: src/conversions-inl.h

Issue 19300002: ES6: Add support for explicit octal and binary integer literals (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix long lines Created 7 years, 5 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
« no previous file with comments | « src/conversions.h ('k') | src/flag-definitions.h » ('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 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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 ++current; 508 ++current;
509 if (current == end || !isDigit(*current, 16) || sign != NONE) { 509 if (current == end || !isDigit(*current, 16) || sign != NONE) {
510 return JunkStringValue(); // "0x". 510 return JunkStringValue(); // "0x".
511 } 511 }
512 512
513 return InternalStringToIntDouble<4>(unicode_cache, 513 return InternalStringToIntDouble<4>(unicode_cache,
514 current, 514 current,
515 end, 515 end,
516 false, 516 false,
517 allow_trailing_junk); 517 allow_trailing_junk);
518
519 // It could be an explicit octal value.
520 } else if ((flags & ALLOW_OCTAL) && (*current == 'o' || *current == 'O')) {
521 ++current;
522 if (current == end || !isDigit(*current, 8) || sign != NONE) {
523 return JunkStringValue(); // "0o".
524 }
525
526 return InternalStringToIntDouble<3>(unicode_cache,
527 current,
528 end,
529 false,
530 allow_trailing_junk);
531
532 // It could be a binary value.
533 } else if ((flags & ALLOW_BINARY) && (*current == 'b' || *current == 'B')) {
534 ++current;
535 if (current == end || !isBinaryDigit(*current) || sign != NONE) {
536 return JunkStringValue(); // "0b".
537 }
538
539 return InternalStringToIntDouble<1>(unicode_cache,
540 current,
541 end,
542 false,
543 allow_trailing_junk);
518 } 544 }
519 545
520 // Ignore leading zeros in the integer part. 546 // Ignore leading zeros in the integer part.
521 while (*current == '0') { 547 while (*current == '0') {
522 ++current; 548 ++current;
523 if (current == end) return SignedZero(sign == NEGATIVE); 549 if (current == end) return SignedZero(sign == NEGATIVE);
524 } 550 }
525 } 551 }
526 552
527 bool octal = leading_zero && (flags & ALLOW_OCTALS) != 0; 553 bool octal = leading_zero && (flags & ALLOW_IMPLICIT_OCTAL) != 0;
528 554
529 // Copy significant digits of the integer part (if any) to the buffer. 555 // Copy significant digits of the integer part (if any) to the buffer.
530 while (*current >= '0' && *current <= '9') { 556 while (*current >= '0' && *current <= '9') {
531 if (significant_digits < kMaxSignificantDigits) { 557 if (significant_digits < kMaxSignificantDigits) {
532 ASSERT(buffer_pos < kBufferSize); 558 ASSERT(buffer_pos < kBufferSize);
533 buffer[buffer_pos++] = static_cast<char>(*current); 559 buffer[buffer_pos++] = static_cast<char>(*current);
534 significant_digits++; 560 significant_digits++;
535 // Will later check if it's an octal in the buffer. 561 // Will later check if it's an octal in the buffer.
536 } else { 562 } else {
537 insignificant_digits++; // Move the digit into the exponential part. 563 insignificant_digits++; // Move the digit into the exponential part.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 ASSERT(buffer_pos < kBufferSize); 695 ASSERT(buffer_pos < kBufferSize);
670 buffer[buffer_pos] = '\0'; 696 buffer[buffer_pos] = '\0';
671 697
672 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); 698 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent);
673 return (sign == NEGATIVE) ? -converted : converted; 699 return (sign == NEGATIVE) ? -converted : converted;
674 } 700 }
675 701
676 } } // namespace v8::internal 702 } } // namespace v8::internal
677 703
678 #endif // V8_CONVERSIONS_INL_H_ 704 #endif // V8_CONVERSIONS_INL_H_
OLDNEW
« no previous file with comments | « src/conversions.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698