| 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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 THROW_NEW_ERROR(isolate, NewRangeError(error_index, js_len), Object); | 437 THROW_NEW_ERROR(isolate, NewRangeError(error_index, js_len), Object); |
| 438 } | 438 } |
| 439 return js_len; | 439 return js_len; |
| 440 } | 440 } |
| 441 | 441 |
| 442 bool Object::BooleanValue() { | 442 bool Object::BooleanValue() { |
| 443 if (IsSmi()) return Smi::cast(this)->value() != 0; | 443 if (IsSmi()) return Smi::cast(this)->value() != 0; |
| 444 DCHECK(IsHeapObject()); | 444 DCHECK(IsHeapObject()); |
| 445 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 445 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
| 446 if (IsBoolean()) return IsTrue(isolate); | 446 if (IsBoolean()) return IsTrue(isolate); |
| 447 if (IsUndefined(isolate) || IsNull(isolate)) return false; | 447 if (IsNullOrUndefined(isolate)) return false; |
| 448 if (IsUndetectable()) return false; // Undetectable object is false. | 448 if (IsUndetectable()) return false; // Undetectable object is false. |
| 449 if (IsString()) return String::cast(this)->length() != 0; | 449 if (IsString()) return String::cast(this)->length() != 0; |
| 450 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 450 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
| 451 return true; | 451 return true; |
| 452 } | 452 } |
| 453 | 453 |
| 454 | 454 |
| 455 namespace { | 455 namespace { |
| 456 | 456 |
| 457 // TODO(bmeurer): Maybe we should introduce a marker interface Number, | 457 // TODO(bmeurer): Maybe we should introduce a marker interface Number, |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 } | 880 } |
| 881 | 881 |
| 882 | 882 |
| 883 // static | 883 // static |
| 884 MaybeHandle<Object> Object::GetMethod(Handle<JSReceiver> receiver, | 884 MaybeHandle<Object> Object::GetMethod(Handle<JSReceiver> receiver, |
| 885 Handle<Name> name) { | 885 Handle<Name> name) { |
| 886 Handle<Object> func; | 886 Handle<Object> func; |
| 887 Isolate* isolate = receiver->GetIsolate(); | 887 Isolate* isolate = receiver->GetIsolate(); |
| 888 ASSIGN_RETURN_ON_EXCEPTION(isolate, func, | 888 ASSIGN_RETURN_ON_EXCEPTION(isolate, func, |
| 889 JSReceiver::GetProperty(receiver, name), Object); | 889 JSReceiver::GetProperty(receiver, name), Object); |
| 890 if (func->IsNull(isolate) || func->IsUndefined(isolate)) { | 890 if (func->IsNullOrUndefined(isolate)) { |
| 891 return isolate->factory()->undefined_value(); | 891 return isolate->factory()->undefined_value(); |
| 892 } | 892 } |
| 893 if (!func->IsCallable()) { | 893 if (!func->IsCallable()) { |
| 894 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction, | 894 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction, |
| 895 func, name, receiver), | 895 func, name, receiver), |
| 896 Object); | 896 Object); |
| 897 } | 897 } |
| 898 return func; | 898 return func; |
| 899 } | 899 } |
| 900 | 900 |
| (...skipping 10982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11883 if (r < 0) { | 11883 if (r < 0) { |
| 11884 result = ComparisonResult::kLessThan; | 11884 result = ComparisonResult::kLessThan; |
| 11885 } else if (r > 0) { | 11885 } else if (r > 0) { |
| 11886 result = ComparisonResult::kGreaterThan; | 11886 result = ComparisonResult::kGreaterThan; |
| 11887 } | 11887 } |
| 11888 return result; | 11888 return result; |
| 11889 } | 11889 } |
| 11890 | 11890 |
| 11891 Object* String::IndexOf(Isolate* isolate, Handle<Object> receiver, | 11891 Object* String::IndexOf(Isolate* isolate, Handle<Object> receiver, |
| 11892 Handle<Object> search, Handle<Object> position) { | 11892 Handle<Object> search, Handle<Object> position) { |
| 11893 if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate)) { | 11893 if (receiver->IsNullOrUndefined(isolate)) { |
| 11894 THROW_NEW_ERROR_RETURN_FAILURE( | 11894 THROW_NEW_ERROR_RETURN_FAILURE( |
| 11895 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, | 11895 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, |
| 11896 isolate->factory()->NewStringFromAsciiChecked( | 11896 isolate->factory()->NewStringFromAsciiChecked( |
| 11897 "String.prototype.indexOf"))); | 11897 "String.prototype.indexOf"))); |
| 11898 } | 11898 } |
| 11899 Handle<String> receiver_string; | 11899 Handle<String> receiver_string; |
| 11900 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver_string, | 11900 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver_string, |
| 11901 Object::ToString(isolate, receiver)); | 11901 Object::ToString(isolate, receiver)); |
| 11902 | 11902 |
| 11903 Handle<String> search_string; | 11903 Handle<String> search_string; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12084 return i; | 12084 return i; |
| 12085 } | 12085 } |
| 12086 } | 12086 } |
| 12087 return -1; | 12087 return -1; |
| 12088 } | 12088 } |
| 12089 | 12089 |
| 12090 } // namespace | 12090 } // namespace |
| 12091 | 12091 |
| 12092 Object* String::LastIndexOf(Isolate* isolate, Handle<Object> receiver, | 12092 Object* String::LastIndexOf(Isolate* isolate, Handle<Object> receiver, |
| 12093 Handle<Object> search, Handle<Object> position) { | 12093 Handle<Object> search, Handle<Object> position) { |
| 12094 if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate)) { | 12094 if (receiver->IsNullOrUndefined(isolate)) { |
| 12095 THROW_NEW_ERROR_RETURN_FAILURE( | 12095 THROW_NEW_ERROR_RETURN_FAILURE( |
| 12096 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, | 12096 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, |
| 12097 isolate->factory()->NewStringFromAsciiChecked( | 12097 isolate->factory()->NewStringFromAsciiChecked( |
| 12098 "String.prototype.lastIndexOf"))); | 12098 "String.prototype.lastIndexOf"))); |
| 12099 } | 12099 } |
| 12100 Handle<String> receiver_string; | 12100 Handle<String> receiver_string; |
| 12101 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver_string, | 12101 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver_string, |
| 12102 Object::ToString(isolate, receiver)); | 12102 Object::ToString(isolate, receiver)); |
| 12103 | 12103 |
| 12104 Handle<String> search_string; | 12104 Handle<String> search_string; |
| (...skipping 8386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20491 // depend on this. | 20491 // depend on this. |
| 20492 return DICTIONARY_ELEMENTS; | 20492 return DICTIONARY_ELEMENTS; |
| 20493 } | 20493 } |
| 20494 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20494 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
| 20495 return kind; | 20495 return kind; |
| 20496 } | 20496 } |
| 20497 } | 20497 } |
| 20498 | 20498 |
| 20499 } // namespace internal | 20499 } // namespace internal |
| 20500 } // namespace v8 | 20500 } // namespace v8 |
| OLD | NEW |