Changeset 24394 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Jul 17, 2007, 7:25:38 PM (18 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function.cpp
r24244 r24394 5 5 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 6 * Copyright (C) 2003 Apple Computer, Inc. 7 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 7 8 * 8 9 * This library is free software; you can redistribute it and/or … … 26 27 #include "function.h" 27 28 29 #include "dtoa.h" 28 30 #include "internal.h" 29 31 #include "function_object.h" … … 670 672 } 671 673 674 double parseIntOverflow(const char* s, int length, int radix) 675 { 676 double number = 0.0; 677 double radixMultiplier = 1.0; 678 679 for (const char* p = s + length - 1; p >= s; p--) { 680 if (radixMultiplier == Inf) { 681 if (*p != '0') { 682 number = Inf; 683 break; 684 } 685 } else { 686 int digit = parseDigit(*p, radix); 687 number += digit * radixMultiplier; 688 } 689 690 radixMultiplier *= radix; 691 } 692 693 return number; 694 } 695 672 696 static double parseInt(const UString& s, int radix) 673 697 { … … 702 726 return NaN; 703 727 728 int firstDigitPosition = p; 704 729 bool sawDigit = false; 705 730 double number = 0; … … 712 737 number += digit; 713 738 ++p; 739 } 740 741 if (number >= mantissaOverflowLowerBound) { 742 if (radix == 10) 743 number = kjs_strtod(s.substr(firstDigitPosition, p - firstDigitPosition).ascii(), 0); 744 else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32) 745 number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).ascii(), p - firstDigitPosition, radix); 714 746 } 715 747 -
trunk/JavaScriptCore/kjs/function.h
r21889 r24394 233 233 }; 234 234 235 static const double mantissaOverflowLowerBound = 9007199254740992.0; 236 double parseIntOverflow(const char* s, int length, int radix); 237 235 238 UString escapeStringForPrettyPrinting(const UString& s); 236 239 -
trunk/JavaScriptCore/kjs/lexer.cpp
r20304 r24394 4 4 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 5 5 * Copyright (C) 2006 Apple Computer, Inc. 6 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 6 7 * 7 8 * This library is free software; you can redistribute it and/or … … 28 29 #include <string.h> 29 30 31 #include "function.h" 30 32 #include "interpreter.h" 31 33 #include "nodes.h" … … 473 475 dval += convertHex(c); 474 476 } 477 478 if (dval >= mantissaOverflowLowerBound) 479 dval = parseIntOverflow(buffer8 + 2, p - (buffer8 + 3), 16); 480 475 481 state = Number; 476 482 } else if (state == Octal) { // scan octal number … … 480 486 dval += c - '0'; 481 487 } 488 489 if (dval >= mantissaOverflowLowerBound) 490 dval = parseIntOverflow(buffer8 + 1, p - (buffer8 + 2), 8); 491 482 492 state = Number; 483 493 } -
trunk/JavaScriptCore/kjs/ustring.cpp
r20004 r24394 4 4 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 5 5 * Copyright (C) 2004 Apple Computer, Inc. 6 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 6 7 * 7 8 * This library is free software; you can redistribute it and/or … … 27 28 #include "JSLock.h" 28 29 #include "dtoa.h" 30 #include "function.h" 29 31 #include "identifier.h" 30 32 #include "operations.h" … … 889 891 // hex number ? 890 892 if (*c == '0' && (*(c+1) == 'x' || *(c+1) == 'X')) { 893 const char* firstDigitPosition = c + 2; 891 894 c++; 892 895 d = 0.0; … … 899 902 break; 900 903 } 904 905 if (d >= mantissaOverflowLowerBound) 906 d = parseIntOverflow(firstDigitPosition, c - firstDigitPosition, 16); 901 907 } else { 902 908 // regular number ? 903 909 char *end; 904 910 d = kjs_strtod(c, &end); 905 if ((d != 0.0 || end != c) && d != HUGE_VAL && d != -HUGE_VAL) {911 if ((d != 0.0 || end != c) && d != Inf && d != -Inf) { 906 912 c = end; 907 913 } else { 908 // infinity ?909 d = 1.0; 914 double sign = 1.0; 915 910 916 if (*c == '+') 911 917 c++; 912 918 else if (*c == '-') { 913 d= -1.0;919 sign = -1.0; 914 920 c++; 915 921 } 916 if (strncmp(c, "Infinity", 8) != 0) 922 923 // We used strtod() to do the conversion. However, strtod() handles 924 // infinite values slightly differently than JavaScript in that it 925 // converts the string "inf" with any capitalization to infinity, 926 // whereas the ECMA spec requires that it be converted to NaN. 927 928 if (strncmp(c, "Infinity", 8) == 0) { 929 d = sign * Inf; 930 c += 8; 931 } else if ((d == Inf || d == -Inf) && *c != 'I' && *c != 'i') 932 c = end; 933 else 917 934 return NaN; 918 d = d * Inf;919 c += 8;920 935 } 921 936 }
Note:
See TracChangeset
for help on using the changeset viewer.