| 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 #include <limits.h> | 5 #include <limits.h> |
| 6 #include <stdarg.h> | 6 #include <stdarg.h> |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "src/v8.h" | 9 #include "src/v8.h" |
| 10 | 10 |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 if (decimal_pos > 0) result_size++; | 476 if (decimal_pos > 0) result_size++; |
| 477 // Allocate result and fill in the parts. | 477 // Allocate result and fill in the parts. |
| 478 SimpleStringBuilder builder(result_size + 1); | 478 SimpleStringBuilder builder(result_size + 1); |
| 479 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 479 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
| 480 if (decimal_pos > 0) builder.AddCharacter('.'); | 480 if (decimal_pos > 0) builder.AddCharacter('.'); |
| 481 builder.AddSubstring(decimal_buffer, decimal_pos); | 481 builder.AddSubstring(decimal_buffer, decimal_pos); |
| 482 return builder.Finalize(); | 482 return builder.Finalize(); |
| 483 } | 483 } |
| 484 | 484 |
| 485 | 485 |
| 486 double StringToDouble(UnicodeCache* unicode_cache, | 486 double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string, |
| 487 String* string, | 487 int flags, double empty_string_val) { |
| 488 int flags, | 488 Handle<String> flattened = String::Flatten(string); |
| 489 double empty_string_val) { | 489 { |
| 490 DisallowHeapAllocation no_gc; | 490 DisallowHeapAllocation no_gc; |
| 491 String::FlatContent flat = string->GetFlatContent(); | 491 String::FlatContent flat = flattened->GetFlatContent(); |
| 492 // ECMA-262 section 15.1.2.3, empty string is NaN | 492 DCHECK(flat.IsFlat()); |
| 493 if (flat.IsOneByte()) { | 493 // ECMA-262 section 15.1.2.3, empty string is NaN |
| 494 return StringToDouble( | 494 if (flat.IsOneByte()) { |
| 495 unicode_cache, flat.ToOneByteVector(), flags, empty_string_val); | 495 return StringToDouble(unicode_cache, flat.ToOneByteVector(), flags, |
| 496 } else { | 496 empty_string_val); |
| 497 return StringToDouble( | 497 } else { |
| 498 unicode_cache, flat.ToUC16Vector(), flags, empty_string_val); | 498 return StringToDouble(unicode_cache, flat.ToUC16Vector(), flags, |
| 499 empty_string_val); |
| 500 } |
| 499 } | 501 } |
| 500 } | 502 } |
| 501 | 503 |
| 502 | 504 |
| 503 } } // namespace v8::internal | 505 } } // namespace v8::internal |
| OLD | NEW |