| 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 } | |
| 243 | 231 |
| 244 bool Object::BooleanValue() { | 232 bool Object::BooleanValue() { |
| 245 if (IsSmi()) return Smi::cast(this)->value() != 0; | 233 if (IsSmi()) return Smi::cast(this)->value() != 0; |
| 246 DCHECK(IsHeapObject()); | 234 DCHECK(IsHeapObject()); |
| 247 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 235 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
| 248 if (IsBoolean()) return IsTrue(isolate); | 236 if (IsBoolean()) return IsTrue(isolate); |
| 249 if (IsUndefined(isolate) || IsNull(isolate)) return false; | 237 if (IsUndefined(isolate) || IsNull(isolate)) return false; |
| 250 if (IsUndetectable()) return false; // Undetectable object is false. | 238 if (IsUndetectable()) return false; // Undetectable object is false. |
| 251 if (IsString()) return String::cast(this)->length() != 0; | 239 if (IsString()) return String::cast(this)->length() != 0; |
| 252 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 240 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
| (...skipping 18707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18960 | 18948 |
| 18961 Object* data_obj = | 18949 Object* data_obj = |
| 18962 constructor->shared()->get_api_func_data()->access_check_info(); | 18950 constructor->shared()->get_api_func_data()->access_check_info(); |
| 18963 if (data_obj->IsUndefined(isolate)) return nullptr; | 18951 if (data_obj->IsUndefined(isolate)) return nullptr; |
| 18964 | 18952 |
| 18965 return AccessCheckInfo::cast(data_obj); | 18953 return AccessCheckInfo::cast(data_obj); |
| 18966 } | 18954 } |
| 18967 | 18955 |
| 18968 } // namespace internal | 18956 } // namespace internal |
| 18969 } // namespace v8 | 18957 } // namespace v8 |
| OLD | NEW |