Changeset 103922 in webkit
- Timestamp:
- Jan 2, 2012 8:32:00 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r103921 r103922 1 2012-01-02 Gavin Barraclough <barraclough@apple.com> 2 3 ES5 prohibits parseInt from supporting octal 4 https://bugs.webkit.org/show_bug.cgi?id=75455 5 6 Reviewed by Sam Weinig. 7 8 See sections 15.1.2.2 and annex E. 9 10 * fast/js/kde/GlobalObject-expected.txt: 11 * fast/js/kde/script-tests/GlobalObject.js: 12 - Change test to check for correct result. 13 * sputnik/Implementation_Diagnostics/S15.1.2.2_D1.1-expected.txt: 14 * sputnik/Implementation_Diagnostics/S15.1.2.2_D1.2-expected.txt: 15 - One test asserts parseInt handles octal, one asserts it does not! 16 This patch switches which one passes & which fails. 17 1 18 2012-01-02 Gavin Barraclough <barraclough@apple.com> 2 19 -
trunk/LayoutTests/fast/js/kde/GlobalObject-expected.txt
r11962 r103922 39 39 PASS isNaN(parseInt('Infinity')) is true 40 40 PASS parseInt("15") is 15 41 PASS parseInt("01 7") is 1541 PASS parseInt("015") is 15 42 42 PASS parseInt("0xf") is 15 43 43 PASS parseInt("15", 0) is 15 -
trunk/LayoutTests/fast/js/kde/script-tests/GlobalObject.js
r98407 r103922 47 47 // all should return 15 48 48 shouldBe('parseInt("15")', "15"); 49 shouldBe('parseInt("01 7")', "15"); /// The spec says it's ok, and even encouraged, to parse this as 17!49 shouldBe('parseInt("015")', "15"); // ES5 prohibits parseInt from handling octal, see annex E. 50 50 shouldBe('parseInt("0xf")', "15"); 51 51 shouldBe('parseInt("15", 0)', "15"); -
trunk/LayoutTests/sputnik/Implementation_Diagnostics/S15.1.2.2_D1.1-expected.txt
r58534 r103922 1 1 S15.1.2.2_D1.1 2 2 3 PASS 3 FAIL SputnikError: #1: parseInt("08") === parseInt("08", 8) 4 4 5 5 TEST COMPLETE -
trunk/LayoutTests/sputnik/Implementation_Diagnostics/S15.1.2.2_D1.2-expected.txt
r58534 r103922 1 1 S15.1.2.2_D1.2 2 2 3 FAIL SputnikError: #1: parseInt("08") === parseInt("08", 10) 3 PASS 4 4 5 5 TEST COMPLETE -
trunk/Source/JavaScriptCore/ChangeLog
r103921 r103922 1 2012-01-02 Gavin Barraclough <barraclough@apple.com> 2 3 ES5 prohibits parseInt from supporting octal 4 https://bugs.webkit.org/show_bug.cgi?id=75455 5 6 Reviewed by Sam Weinig. 7 8 See sections 15.1.2.2 and annex E. 9 10 * runtime/JSGlobalObjectFunctions.cpp: 11 (JSC::parseInt): 12 1 13 2012-01-02 Gavin Barraclough <barraclough@apple.com> 2 14 -
trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r102182 r103922 231 231 } 232 232 233 // ES5.1 15.1.2.2 233 234 template <typename CharType> 234 235 ALWAYS_INLINE 235 236 static double parseInt(const UString& s, const CharType* data, int radix) 236 237 { 238 // 1. Let inputString be ToString(string). 239 // 2. Let S be a newly created substring of inputString consisting of the first character that is not a 240 // StrWhiteSpaceChar and all characters following that character. (In other words, remove leading white 241 // space.) If inputString does not contain any such characters, let S be the empty string. 237 242 int length = s.length(); 238 243 int p = 0; 239 240 244 while (p < length && isStrWhiteSpace(data[p])) 241 245 ++p; 242 246 247 // 3. Let sign be 1. 248 // 4. If S is not empty and the first character of S is a minus sign -, let sign be -1. 249 // 5. If S is not empty and the first character of S is a plus sign + or a minus sign -, then remove the first character from S. 243 250 double sign = 1; 244 251 if (p < length) { … … 251 258 } 252 259 260 // 6. Let R = ToInt32(radix). 261 // 7. Let stripPrefix be true. 262 // 8. If R != 0,then 263 // b. If R != 16, let stripPrefix be false. 264 // 9. Else, R == 0 265 // a. LetR = 10. 266 // 10. If stripPrefix is true, then 267 // a. If the length of S is at least 2 and the first two characters of S are either ―0x or ―0X, 268 // then remove the first two characters from S and let R = 16. 269 // 11. If S contains any character that is not a radix-R digit, then let Z be the substring of S 270 // consisting of all characters before the first such character; otherwise, let Z be S. 253 271 if ((radix == 0 || radix == 16) && length - p >= 2 && data[p] == '0' && (data[p + 1] == 'x' || data[p + 1] == 'X')) { 254 272 radix = 16; 255 273 p += 2; 256 } else if (radix == 0) { 257 if (p < length && data[p] == '0') 258 radix = 8; 259 else 260 radix = 10; 261 } 262 274 } else if (radix == 0) 275 radix = 10; 276 277 // 8.a If R < 2 or R > 36, then return NaN. 263 278 if (radix < 2 || radix > 36) 264 279 return std::numeric_limits<double>::quiet_NaN(); 265 280 281 // 13. Let mathInt be the mathematical integer value that is represented by Z in radix-R notation, using the letters 282 // A-Z and a-z for digits with values 10 through 35. (However, if R is 10 and Z contains more than 20 significant 283 // digits, every significant digit after the 20th may be replaced by a 0 digit, at the option of the implementation; 284 // and if R is not 2, 4, 8, 10, 16, or 32, then mathInt may be an implementation-dependent approximation to the 285 // mathematical integer value that is represented by Z in radix-R notation.) 286 // 14. Let number be the Number value for mathInt. 266 287 int firstDigitPosition = p; 267 288 bool sawDigit = false; … … 276 297 ++p; 277 298 } 278 279 299 if (number >= mantissaOverflowLowerBound) { 280 300 if (radix == 10) … … 284 304 } 285 305 306 // 12. If Z is empty, return NaN. 286 307 if (!sawDigit) 287 308 return std::numeric_limits<double>::quiet_NaN(); 288 309 310 // 15. Return sign x number. 289 311 return sign * number; 290 312 }
Note: See TracChangeset
for help on using the changeset viewer.