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 if (input->IsUndefined(isolate)) return isolate->factory()->NewNumber(0.0); |
| 234 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 235 double len = DoubleToInteger(input->Number()) + 0.0; |
| 236 if (len < 0.0 || len > kMaxSafeInteger) { |
| 237 THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kInvalidIndex), |
| 238 Object); |
| 239 } |
| 240 return isolate->factory()->NewNumber(len); |
| 241 } |
231 | 242 |
232 bool Object::BooleanValue() { | 243 bool Object::BooleanValue() { |
233 if (IsSmi()) return Smi::cast(this)->value() != 0; | 244 if (IsSmi()) return Smi::cast(this)->value() != 0; |
234 DCHECK(IsHeapObject()); | 245 DCHECK(IsHeapObject()); |
235 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 246 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
236 if (IsBoolean()) return IsTrue(isolate); | 247 if (IsBoolean()) return IsTrue(isolate); |
237 if (IsUndefined(isolate) || IsNull(isolate)) return false; | 248 if (IsUndefined(isolate) || IsNull(isolate)) return false; |
238 if (IsUndetectable()) return false; // Undetectable object is false. | 249 if (IsUndetectable()) return false; // Undetectable object is false. |
239 if (IsString()) return String::cast(this)->length() != 0; | 250 if (IsString()) return String::cast(this)->length() != 0; |
240 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 251 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
(...skipping 18758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18999 | 19010 |
19000 Object* data_obj = | 19011 Object* data_obj = |
19001 constructor->shared()->get_api_func_data()->access_check_info(); | 19012 constructor->shared()->get_api_func_data()->access_check_info(); |
19002 if (data_obj->IsUndefined(isolate)) return nullptr; | 19013 if (data_obj->IsUndefined(isolate)) return nullptr; |
19003 | 19014 |
19004 return AccessCheckInfo::cast(data_obj); | 19015 return AccessCheckInfo::cast(data_obj); |
19005 } | 19016 } |
19006 | 19017 |
19007 } // namespace internal | 19018 } // namespace internal |
19008 } // namespace v8 | 19019 } // namespace v8 |
OLD | NEW |