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

Side by Side Diff: src/conversions.cc

Issue 250793009: Merge v8converions with conversions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 7 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/elements.cc » ('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 11 matching lines...) Expand all
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdarg.h> 28 #include <stdarg.h>
29 #include <limits.h> 29 #include <limits.h>
30 #include <cmath> 30 #include <cmath>
31 31
32 #include "v8.h"
33
34 #include "assert-scope.h"
35 #include "conversions.h"
32 #include "conversions-inl.h" 36 #include "conversions-inl.h"
33 #include "dtoa.h" 37 #include "dtoa.h"
38 #include "factory.h"
34 #include "list-inl.h" 39 #include "list-inl.h"
35 #include "strtod.h" 40 #include "strtod.h"
36 #include "utils.h" 41 #include "utils.h"
37 42
38 #ifndef _STLP_VENDOR_CSTD 43 #ifndef _STLP_VENDOR_CSTD
39 // STLPort doesn't import fpclassify into the std namespace. 44 // STLPort doesn't import fpclassify into the std namespace.
40 using std::fpclassify; 45 using std::fpclassify;
41 #endif 46 #endif
42 47
43 namespace v8 { 48 namespace v8 {
44 namespace internal { 49 namespace internal {
45 50
46 51
52 namespace {
53
54 // C++-style iterator adaptor for StringCharacterStream
55 // (unlike C++ iterators the end-marker has different type).
56 class StringCharacterStreamIterator {
57 public:
58 class EndMarker {};
59
60 explicit StringCharacterStreamIterator(StringCharacterStream* stream);
61
62 uint16_t operator*() const;
63 void operator++();
64 bool operator==(EndMarker const&) const { return end_; }
65 bool operator!=(EndMarker const& m) const { return !end_; }
66
67 private:
68 StringCharacterStream* const stream_;
69 uint16_t current_;
70 bool end_;
71 };
72
73
74 StringCharacterStreamIterator::StringCharacterStreamIterator(
75 StringCharacterStream* stream) : stream_(stream) {
76 ++(*this);
77 }
78
79 uint16_t StringCharacterStreamIterator::operator*() const {
80 return current_;
81 }
82
83
84 void StringCharacterStreamIterator::operator++() {
85 end_ = !stream_->HasMore();
86 if (!end_) {
87 current_ = stream_->GetNext();
88 }
89 }
90 } // End anonymous namespace.
91
92
47 double StringToDouble(UnicodeCache* unicode_cache, 93 double StringToDouble(UnicodeCache* unicode_cache,
48 const char* str, int flags, double empty_string_val) { 94 const char* str, int flags, double empty_string_val) {
49 // We cast to const uint8_t* here to avoid instantiating the 95 // We cast to const uint8_t* here to avoid instantiating the
50 // InternalStringToDouble() template for const char* as well. 96 // InternalStringToDouble() template for const char* as well.
51 const uint8_t* start = reinterpret_cast<const uint8_t*>(str); 97 const uint8_t* start = reinterpret_cast<const uint8_t*>(str);
52 const uint8_t* end = start + StrLength(str); 98 const uint8_t* end = start + StrLength(str);
53 return InternalStringToDouble(unicode_cache, start, end, flags, 99 return InternalStringToDouble(unicode_cache, start, end, flags,
54 empty_string_val); 100 empty_string_val);
55 } 101 }
56 102
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // If the number has a decimal part, leave room for the period. 498 // If the number has a decimal part, leave room for the period.
453 if (decimal_pos > 0) result_size++; 499 if (decimal_pos > 0) result_size++;
454 // Allocate result and fill in the parts. 500 // Allocate result and fill in the parts.
455 SimpleStringBuilder builder(result_size + 1); 501 SimpleStringBuilder builder(result_size + 1);
456 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); 502 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size);
457 if (decimal_pos > 0) builder.AddCharacter('.'); 503 if (decimal_pos > 0) builder.AddCharacter('.');
458 builder.AddSubstring(decimal_buffer, decimal_pos); 504 builder.AddSubstring(decimal_buffer, decimal_pos);
459 return builder.Finalize(); 505 return builder.Finalize();
460 } 506 }
461 507
508
509 double StringToDouble(UnicodeCache* unicode_cache,
510 String* string,
511 int flags,
512 double empty_string_val) {
513 DisallowHeapAllocation no_gc;
514 String::FlatContent flat = string->GetFlatContent();
515 // ECMA-262 section 15.1.2.3, empty string is NaN
516 if (flat.IsAscii()) {
517 return StringToDouble(
518 unicode_cache, flat.ToOneByteVector(), flags, empty_string_val);
519 } else {
520 return StringToDouble(
521 unicode_cache, flat.ToUC16Vector(), flags, empty_string_val);
522 }
523 }
524
525
462 } } // namespace v8::internal 526 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/conversions.h ('k') | src/elements.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698