| 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 18617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18858 } else { | 18869 } else { |
| 18859 // Old-style generators. | 18870 // Old-style generators. |
| 18860 int offset = continuation(); | 18871 int offset = continuation(); |
| 18861 CHECK(0 <= offset && offset < function()->code()->instruction_size()); | 18872 CHECK(0 <= offset && offset < function()->code()->instruction_size()); |
| 18862 return function()->code()->SourcePosition(offset); | 18873 return function()->code()->SourcePosition(offset); |
| 18863 } | 18874 } |
| 18864 } | 18875 } |
| 18865 | 18876 |
| 18866 } // namespace internal | 18877 } // namespace internal |
| 18867 } // namespace v8 | 18878 } // namespace v8 |
| OLD | NEW |