OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); | 221 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
222 double len = DoubleToInteger(input->Number()); | 222 double len = DoubleToInteger(input->Number()); |
223 if (len <= 0.0) { | 223 if (len <= 0.0) { |
224 len = 0.0; | 224 len = 0.0; |
225 } else if (len >= kMaxSafeInteger) { | 225 } else if (len >= kMaxSafeInteger) { |
226 len = kMaxSafeInteger; | 226 len = kMaxSafeInteger; |
227 } | 227 } |
228 return isolate->factory()->NewNumber(len); | 228 return isolate->factory()->NewNumber(len); |
229 } | 229 } |
230 | 230 |
| 231 // static |
| 232 MaybeHandle<Object> Object::ToIndex(Isolate* isolate, Handle<Object> input, |
| 233 MessageTemplate::Template error_index) { |
| 234 if (input->IsUndefined(isolate)) return isolate->factory()->NewNumber(0.0); |
| 235 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 236 double len = DoubleToInteger(input->Number()) + 0.0; |
| 237 auto js_len = isolate->factory()->NewNumber(len); |
| 238 if (len < 0.0 || len > kMaxSafeInteger) { |
| 239 THROW_NEW_ERROR(isolate, NewRangeError(error_index, js_len), Object); |
| 240 } |
| 241 return js_len; |
| 242 } |
231 | 243 |
232 bool Object::BooleanValue() { | 244 bool Object::BooleanValue() { |
233 if (IsSmi()) return Smi::cast(this)->value() != 0; | 245 if (IsSmi()) return Smi::cast(this)->value() != 0; |
234 DCHECK(IsHeapObject()); | 246 DCHECK(IsHeapObject()); |
235 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 247 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
236 if (IsBoolean()) return IsTrue(isolate); | 248 if (IsBoolean()) return IsTrue(isolate); |
237 if (IsUndefined(isolate) || IsNull(isolate)) return false; | 249 if (IsUndefined(isolate) || IsNull(isolate)) return false; |
238 if (IsUndetectable()) return false; // Undetectable object is false. | 250 if (IsUndetectable()) return false; // Undetectable object is false. |
239 if (IsString()) return String::cast(this)->length() != 0; | 251 if (IsString()) return String::cast(this)->length() != 0; |
240 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 252 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
(...skipping 18696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18937 | 18949 |
18938 Object* data_obj = | 18950 Object* data_obj = |
18939 constructor->shared()->get_api_func_data()->access_check_info(); | 18951 constructor->shared()->get_api_func_data()->access_check_info(); |
18940 if (data_obj->IsUndefined(isolate)) return nullptr; | 18952 if (data_obj->IsUndefined(isolate)) return nullptr; |
18941 | 18953 |
18942 return AccessCheckInfo::cast(data_obj); | 18954 return AccessCheckInfo::cast(data_obj); |
18943 } | 18955 } |
18944 | 18956 |
18945 } // namespace internal | 18957 } // namespace internal |
18946 } // namespace v8 | 18958 } // namespace v8 |
OLD | NEW |