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

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

Issue 1290743005: Make some foo.h headers usable without foo-inl.h header. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: As per offline comment. Created 5 years, 4 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
« no previous file with comments | « src/conversions.h ('k') | src/layout-descriptor.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 // 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 #ifndef V8_CONVERSIONS_INL_H_ 5 #ifndef V8_CONVERSIONS_INL_H_
6 #define V8_CONVERSIONS_INL_H_ 6 #define V8_CONVERSIONS_INL_H_
7 7
8 #include <float.h> // Required for DBL_MAX and on Win32 for finite() 8 #include <float.h> // Required for DBL_MAX and on Win32 for finite()
9 #include <limits.h> // Required for INT_MAX etc. 9 #include <limits.h> // Required for INT_MAX etc.
10 #include <stdarg.h> 10 #include <stdarg.h>
11 #include <cmath> 11 #include <cmath>
12 #include "src/globals.h" // Required for V8_INFINITY 12 #include "src/globals.h" // Required for V8_INFINITY
13 13
14 // ---------------------------------------------------------------------------- 14 // ----------------------------------------------------------------------------
15 // Extra POSIX/ANSI functions for Win32/MSVC. 15 // Extra POSIX/ANSI functions for Win32/MSVC.
16 16
17 #include "src/base/bits.h" 17 #include "src/base/bits.h"
18 #include "src/base/platform/platform.h" 18 #include "src/base/platform/platform.h"
19 #include "src/conversions.h" 19 #include "src/conversions.h"
20 #include "src/double.h" 20 #include "src/double.h"
21 #include "src/objects-inl.h"
21 #include "src/scanner.h" 22 #include "src/scanner.h"
22 #include "src/strtod.h" 23 #include "src/strtod.h"
23 24
24 namespace v8 { 25 namespace v8 {
25 namespace internal { 26 namespace internal {
26 27
27 inline double JunkStringValue() { 28 inline double JunkStringValue() {
28 return bit_cast<double, uint64_t>(kQuietNaNMask); 29 return bit_cast<double, uint64_t>(kQuietNaNMask);
29 } 30 }
30 31
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (exponent < 0) { 91 if (exponent < 0) {
91 if (exponent <= -Double::kSignificandSize) return 0; 92 if (exponent <= -Double::kSignificandSize) return 0;
92 return d.Sign() * static_cast<int32_t>(d.Significand() >> -exponent); 93 return d.Sign() * static_cast<int32_t>(d.Significand() >> -exponent);
93 } else { 94 } else {
94 if (exponent > 31) return 0; 95 if (exponent > 31) return 0;
95 return d.Sign() * static_cast<int32_t>(d.Significand() << exponent); 96 return d.Sign() * static_cast<int32_t>(d.Significand() << exponent);
96 } 97 }
97 } 98 }
98 99
99 100
101 bool IsSmiDouble(double value) {
102 return !IsMinusZero(value) && value >= Smi::kMinValue &&
103 value <= Smi::kMaxValue && value == FastI2D(FastD2I(value));
104 }
105
106
107 bool IsInt32Double(double value) {
108 return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt &&
109 value == FastI2D(FastD2I(value));
110 }
111
112
113 bool IsUint32Double(double value) {
114 return !IsMinusZero(value) && value >= 0 && value <= kMaxUInt32 &&
115 value == FastUI2D(FastD2UI(value));
116 }
117
118
119 int32_t NumberToInt32(Object* number) {
120 if (number->IsSmi()) return Smi::cast(number)->value();
121 return DoubleToInt32(number->Number());
122 }
123
124
125 uint32_t NumberToUint32(Object* number) {
126 if (number->IsSmi()) return Smi::cast(number)->value();
127 return DoubleToUint32(number->Number());
128 }
129
130
131 bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) {
132 SealHandleScope shs(isolate);
133 if (number->IsSmi()) {
134 int value = Smi::cast(number)->value();
135 DCHECK(static_cast<unsigned>(Smi::kMaxValue) <=
136 std::numeric_limits<size_t>::max());
137 if (value >= 0) {
138 *result = static_cast<size_t>(value);
139 return true;
140 }
141 return false;
142 } else {
143 DCHECK(number->IsHeapNumber());
144 double value = HeapNumber::cast(number)->value();
145 if (value >= 0 && value <= std::numeric_limits<size_t>::max()) {
146 *result = static_cast<size_t>(value);
147 return true;
148 } else {
149 return false;
150 }
151 }
152 }
153
154
155 size_t NumberToSize(Isolate* isolate, Object* number) {
156 size_t result = 0;
157 bool is_valid = TryNumberToSize(isolate, number, &result);
158 CHECK(is_valid);
159 return result;
160 }
161
162
100 template <class Iterator, class EndMark> 163 template <class Iterator, class EndMark>
101 bool SubStringEquals(Iterator* current, 164 bool SubStringEquals(Iterator* current,
102 EndMark end, 165 EndMark end,
103 const char* substring) { 166 const char* substring) {
104 DCHECK(**current == *substring); 167 DCHECK(**current == *substring);
105 for (substring++; *substring != '\0'; substring++) { 168 for (substring++; *substring != '\0'; substring++) {
106 ++*current; 169 ++*current;
107 if (*current == end || **current != *substring) return false; 170 if (*current == end || **current != *substring) return false;
108 } 171 }
109 ++*current; 172 ++*current;
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 SLOW_DCHECK(buffer_pos < kBufferSize); 748 SLOW_DCHECK(buffer_pos < kBufferSize);
686 buffer[buffer_pos] = '\0'; 749 buffer[buffer_pos] = '\0';
687 750
688 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); 751 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent);
689 return (sign == NEGATIVE) ? -converted : converted; 752 return (sign == NEGATIVE) ? -converted : converted;
690 } 753 }
691 754
692 } } // namespace v8::internal 755 } } // namespace v8::internal
693 756
694 #endif // V8_CONVERSIONS_INL_H_ 757 #endif // V8_CONVERSIONS_INL_H_
OLDNEW
« no previous file with comments | « src/conversions.h ('k') | src/layout-descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698