| 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 <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); | 376 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 377 double len = DoubleToInteger(input->Number()); | 377 double len = DoubleToInteger(input->Number()); |
| 378 if (len <= 0.0) { | 378 if (len <= 0.0) { |
| 379 len = 0.0; | 379 len = 0.0; |
| 380 } else if (len >= kMaxSafeInteger) { | 380 } else if (len >= kMaxSafeInteger) { |
| 381 len = kMaxSafeInteger; | 381 len = kMaxSafeInteger; |
| 382 } | 382 } |
| 383 return isolate->factory()->NewNumber(len); | 383 return isolate->factory()->NewNumber(len); |
| 384 } | 384 } |
| 385 | 385 |
| 386 // static |
| 387 MaybeHandle<Object> Object::ToIndex(Isolate* isolate, Handle<Object> input, |
| 388 MessageTemplate::Template error_index) { |
| 389 if (input->IsUndefined(isolate)) return isolate->factory()->NewNumber(0.0); |
| 390 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 391 double len = DoubleToInteger(input->Number()) + 0.0; |
| 392 auto js_len = isolate->factory()->NewNumber(len); |
| 393 if (len < 0.0 || len > kMaxSafeInteger) { |
| 394 THROW_NEW_ERROR(isolate, NewRangeError(error_index, js_len), Object); |
| 395 } |
| 396 return js_len; |
| 397 } |
| 386 | 398 |
| 387 bool Object::BooleanValue() { | 399 bool Object::BooleanValue() { |
| 388 if (IsSmi()) return Smi::cast(this)->value() != 0; | 400 if (IsSmi()) return Smi::cast(this)->value() != 0; |
| 389 DCHECK(IsHeapObject()); | 401 DCHECK(IsHeapObject()); |
| 390 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 402 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
| 391 if (IsBoolean()) return IsTrue(isolate); | 403 if (IsBoolean()) return IsTrue(isolate); |
| 392 if (IsUndefined(isolate) || IsNull(isolate)) return false; | 404 if (IsUndefined(isolate) || IsNull(isolate)) return false; |
| 393 if (IsUndetectable()) return false; // Undetectable object is false. | 405 if (IsUndetectable()) return false; // Undetectable object is false. |
| 394 if (IsString()) return String::cast(this)->length() != 0; | 406 if (IsString()) return String::cast(this)->length() != 0; |
| 395 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 407 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
| (...skipping 18860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19256 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, | 19268 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, |
| 19257 PrototypeIterator::END_AT_NULL); | 19269 PrototypeIterator::END_AT_NULL); |
| 19258 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { | 19270 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { |
| 19259 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; | 19271 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; |
| 19260 } | 19272 } |
| 19261 return false; | 19273 return false; |
| 19262 } | 19274 } |
| 19263 | 19275 |
| 19264 } // namespace internal | 19276 } // namespace internal |
| 19265 } // namespace v8 | 19277 } // namespace v8 |
| OLD | NEW |