OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 "src/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/counters.h" | 9 #include "src/counters.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); | 22 Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); |
23 | 23 |
24 // Unwrap the receiver {value}. | 24 // Unwrap the receiver {value}. |
25 if (value->IsJSValue()) { | 25 if (value->IsJSValue()) { |
26 value = handle(Handle<JSValue>::cast(value)->value(), isolate); | 26 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
27 } | 27 } |
28 if (!value->IsNumber()) { | 28 if (!value->IsNumber()) { |
29 THROW_NEW_ERROR_RETURN_FAILURE( | 29 THROW_NEW_ERROR_RETURN_FAILURE( |
30 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 30 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
31 isolate->factory()->NewStringFromAsciiChecked( | 31 isolate->factory()->NewStringFromAsciiChecked( |
32 "Number.prototype.toExponential"))); | 32 "Number.prototype.toExponential"), |
| 33 isolate->factory()->Number_string())); |
33 } | 34 } |
34 double const value_number = value->Number(); | 35 double const value_number = value->Number(); |
35 | 36 |
36 // Convert the {fraction_digits} to an integer first. | 37 // Convert the {fraction_digits} to an integer first. |
37 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 38 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
38 isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits)); | 39 isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits)); |
39 double const fraction_digits_number = fraction_digits->Number(); | 40 double const fraction_digits_number = fraction_digits->Number(); |
40 | 41 |
41 if (std::isnan(value_number)) return isolate->heap()->nan_string(); | 42 if (std::isnan(value_number)) return isolate->heap()->nan_string(); |
42 if (std::isinf(value_number)) { | 43 if (std::isinf(value_number)) { |
(...skipping 22 matching lines...) Expand all Loading... |
65 Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); | 66 Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1); |
66 | 67 |
67 // Unwrap the receiver {value}. | 68 // Unwrap the receiver {value}. |
68 if (value->IsJSValue()) { | 69 if (value->IsJSValue()) { |
69 value = handle(Handle<JSValue>::cast(value)->value(), isolate); | 70 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
70 } | 71 } |
71 if (!value->IsNumber()) { | 72 if (!value->IsNumber()) { |
72 THROW_NEW_ERROR_RETURN_FAILURE( | 73 THROW_NEW_ERROR_RETURN_FAILURE( |
73 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 74 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
74 isolate->factory()->NewStringFromAsciiChecked( | 75 isolate->factory()->NewStringFromAsciiChecked( |
75 "Number.prototype.toFixed"))); | 76 "Number.prototype.toFixed"), |
| 77 isolate->factory()->Number_string())); |
76 } | 78 } |
77 double const value_number = value->Number(); | 79 double const value_number = value->Number(); |
78 | 80 |
79 // Convert the {fraction_digits} to an integer first. | 81 // Convert the {fraction_digits} to an integer first. |
80 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 82 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
81 isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits)); | 83 isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits)); |
82 double const fraction_digits_number = fraction_digits->Number(); | 84 double const fraction_digits_number = fraction_digits->Number(); |
83 | 85 |
84 // Check if the {fraction_digits} are in the supported range. | 86 // Check if the {fraction_digits} are in the supported range. |
85 if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) { | 87 if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) { |
(...skipping 21 matching lines...) Expand all Loading... |
107 Handle<Object> value = args.at(0); | 109 Handle<Object> value = args.at(0); |
108 | 110 |
109 // Unwrap the receiver {value}. | 111 // Unwrap the receiver {value}. |
110 if (value->IsJSValue()) { | 112 if (value->IsJSValue()) { |
111 value = handle(Handle<JSValue>::cast(value)->value(), isolate); | 113 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
112 } | 114 } |
113 if (!value->IsNumber()) { | 115 if (!value->IsNumber()) { |
114 THROW_NEW_ERROR_RETURN_FAILURE( | 116 THROW_NEW_ERROR_RETURN_FAILURE( |
115 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 117 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
116 isolate->factory()->NewStringFromAsciiChecked( | 118 isolate->factory()->NewStringFromAsciiChecked( |
117 "Number.prototype.toLocaleString"))); | 119 "Number.prototype.toLocaleString"), |
| 120 isolate->factory()->Number_string())); |
118 } | 121 } |
119 | 122 |
120 // Turn the {value} into a String. | 123 // Turn the {value} into a String. |
121 return *isolate->factory()->NumberToString(value); | 124 return *isolate->factory()->NumberToString(value); |
122 } | 125 } |
123 | 126 |
124 // ES6 section 20.1.3.5 Number.prototype.toPrecision ( precision ) | 127 // ES6 section 20.1.3.5 Number.prototype.toPrecision ( precision ) |
125 BUILTIN(NumberPrototypeToPrecision) { | 128 BUILTIN(NumberPrototypeToPrecision) { |
126 HandleScope scope(isolate); | 129 HandleScope scope(isolate); |
127 Handle<Object> value = args.at(0); | 130 Handle<Object> value = args.at(0); |
128 Handle<Object> precision = args.atOrUndefined(isolate, 1); | 131 Handle<Object> precision = args.atOrUndefined(isolate, 1); |
129 | 132 |
130 // Unwrap the receiver {value}. | 133 // Unwrap the receiver {value}. |
131 if (value->IsJSValue()) { | 134 if (value->IsJSValue()) { |
132 value = handle(Handle<JSValue>::cast(value)->value(), isolate); | 135 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
133 } | 136 } |
134 if (!value->IsNumber()) { | 137 if (!value->IsNumber()) { |
135 THROW_NEW_ERROR_RETURN_FAILURE( | 138 THROW_NEW_ERROR_RETURN_FAILURE( |
136 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 139 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
137 isolate->factory()->NewStringFromAsciiChecked( | 140 isolate->factory()->NewStringFromAsciiChecked( |
138 "Number.prototype.toPrecision"))); | 141 "Number.prototype.toPrecision"), |
| 142 isolate->factory()->Number_string())); |
139 } | 143 } |
140 double const value_number = value->Number(); | 144 double const value_number = value->Number(); |
141 | 145 |
142 // If no {precision} was specified, just return ToString of {value}. | 146 // If no {precision} was specified, just return ToString of {value}. |
143 if (precision->IsUndefined(isolate)) { | 147 if (precision->IsUndefined(isolate)) { |
144 return *isolate->factory()->NumberToString(value); | 148 return *isolate->factory()->NumberToString(value); |
145 } | 149 } |
146 | 150 |
147 // Convert the {precision} to an integer first. | 151 // Convert the {precision} to an integer first. |
148 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, precision, | 152 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, precision, |
(...skipping 23 matching lines...) Expand all Loading... |
172 Handle<Object> radix = args.atOrUndefined(isolate, 1); | 176 Handle<Object> radix = args.atOrUndefined(isolate, 1); |
173 | 177 |
174 // Unwrap the receiver {value}. | 178 // Unwrap the receiver {value}. |
175 if (value->IsJSValue()) { | 179 if (value->IsJSValue()) { |
176 value = handle(Handle<JSValue>::cast(value)->value(), isolate); | 180 value = handle(Handle<JSValue>::cast(value)->value(), isolate); |
177 } | 181 } |
178 if (!value->IsNumber()) { | 182 if (!value->IsNumber()) { |
179 THROW_NEW_ERROR_RETURN_FAILURE( | 183 THROW_NEW_ERROR_RETURN_FAILURE( |
180 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 184 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
181 isolate->factory()->NewStringFromAsciiChecked( | 185 isolate->factory()->NewStringFromAsciiChecked( |
182 "Number.prototype.toString"))); | 186 "Number.prototype.toString"), |
| 187 isolate->factory()->Number_string())); |
183 } | 188 } |
184 double const value_number = value->Number(); | 189 double const value_number = value->Number(); |
185 | 190 |
186 // If no {radix} was specified, just return ToString of {value}. | 191 // If no {radix} was specified, just return ToString of {value}. |
187 if (radix->IsUndefined(isolate)) { | 192 if (radix->IsUndefined(isolate)) { |
188 return *isolate->factory()->NumberToString(value); | 193 return *isolate->factory()->NumberToString(value); |
189 } | 194 } |
190 | 195 |
191 // Convert the {radix} to an integer first. | 196 // Convert the {radix} to an integer first. |
192 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, radix, | 197 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, radix, |
(...skipping 26 matching lines...) Expand all Loading... |
219 } | 224 } |
220 char* const str = | 225 char* const str = |
221 DoubleToRadixCString(value_number, static_cast<int>(radix_number)); | 226 DoubleToRadixCString(value_number, static_cast<int>(radix_number)); |
222 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); | 227 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
223 DeleteArray(str); | 228 DeleteArray(str); |
224 return *result; | 229 return *result; |
225 } | 230 } |
226 | 231 |
227 } // namespace internal | 232 } // namespace internal |
228 } // namespace v8 | 233 } // namespace v8 |
OLD | NEW |