| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 // Well, there is one exception: Handle [] on strings. | 772 // Well, there is one exception: Handle [] on strings. |
| 773 Handle<String> string = Handle<String>::cast(object); | 773 Handle<String> string = Handle<String>::cast(object); |
| 774 if (index < static_cast<uint32_t>(string->length())) { | 774 if (index < static_cast<uint32_t>(string->length())) { |
| 775 return isolate->heap()->true_value(); | 775 return isolate->heap()->true_value(); |
| 776 } | 776 } |
| 777 } | 777 } |
| 778 return isolate->heap()->false_value(); | 778 return isolate->heap()->false_value(); |
| 779 } | 779 } |
| 780 | 780 |
| 781 | 781 |
| 782 // ES6 section 12.9.3, operator in. | |
| 783 RUNTIME_FUNCTION(Runtime_HasProperty) { | 782 RUNTIME_FUNCTION(Runtime_HasProperty) { |
| 784 HandleScope scope(isolate); | 783 HandleScope scope(isolate); |
| 785 DCHECK_EQ(2, args.length()); | 784 DCHECK(args.length() == 2); |
| 786 CONVERT_ARG_HANDLE_CHECKED(Object, key, 0); | 785 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); |
| 787 CONVERT_ARG_HANDLE_CHECKED(Object, object, 1); | 786 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
| 788 | 787 |
| 789 // Check that {object} is actually a receiver. | 788 Maybe<bool> maybe = JSReceiver::HasProperty(receiver, key); |
| 790 if (!object->IsJSReceiver()) { | |
| 791 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 792 isolate, | |
| 793 NewTypeError(MessageTemplate::kInvalidInOperatorUse, key, object)); | |
| 794 } | |
| 795 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); | |
| 796 | |
| 797 // Check for fast element case. | |
| 798 uint32_t index = 0; | |
| 799 if (key->ToArrayIndex(&index)) { | |
| 800 Maybe<bool> maybe = JSReceiver::HasElement(receiver, index); | |
| 801 if (!maybe.IsJust()) return isolate->heap()->exception(); | |
| 802 return isolate->heap()->ToBoolean(maybe.FromJust()); | |
| 803 } | |
| 804 | |
| 805 // Convert {key} to a Name first. | |
| 806 Handle<Name> name; | |
| 807 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, | |
| 808 Runtime::ToName(isolate, key)); | |
| 809 | |
| 810 // Lookup property by {name} on {receiver}. | |
| 811 Maybe<bool> maybe = JSReceiver::HasProperty(receiver, name); | |
| 812 if (!maybe.IsJust()) return isolate->heap()->exception(); | 789 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 813 return isolate->heap()->ToBoolean(maybe.FromJust()); | 790 return isolate->heap()->ToBoolean(maybe.FromJust()); |
| 814 } | 791 } |
| 792 |
| 793 |
| 794 RUNTIME_FUNCTION(Runtime_HasElement) { |
| 795 HandleScope scope(isolate); |
| 796 DCHECK(args.length() == 2); |
| 797 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); |
| 798 CONVERT_SMI_ARG_CHECKED(index, 1); |
| 799 |
| 800 Maybe<bool> maybe = JSReceiver::HasElement(receiver, index); |
| 801 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 802 return isolate->heap()->ToBoolean(maybe.FromJust()); |
| 803 } |
| 815 | 804 |
| 816 | 805 |
| 817 RUNTIME_FUNCTION(Runtime_IsPropertyEnumerable) { | 806 RUNTIME_FUNCTION(Runtime_IsPropertyEnumerable) { |
| 818 HandleScope scope(isolate); | 807 HandleScope scope(isolate); |
| 819 DCHECK(args.length() == 2); | 808 DCHECK(args.length() == 2); |
| 820 | 809 |
| 821 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 810 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 822 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); | 811 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
| 823 | 812 |
| 824 Maybe<PropertyAttributes> maybe = | 813 Maybe<PropertyAttributes> maybe = |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 Handle<JSReceiver> receiver; | 1461 Handle<JSReceiver> receiver; |
| 1473 if (JSReceiver::ToObject(isolate, object).ToHandle(&receiver)) { | 1462 if (JSReceiver::ToObject(isolate, object).ToHandle(&receiver)) { |
| 1474 return *receiver; | 1463 return *receiver; |
| 1475 } | 1464 } |
| 1476 THROW_NEW_ERROR_RETURN_FAILURE( | 1465 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1477 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); | 1466 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); |
| 1478 } | 1467 } |
| 1479 | 1468 |
| 1480 } // namespace internal | 1469 } // namespace internal |
| 1481 } // namespace v8 | 1470 } // namespace v8 |
| OLD | NEW |