Chromium Code Reviews| 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.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/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 JSFunction::SetName(getter, name, isolate->factory()->get_string()); | 743 JSFunction::SetName(getter, name, isolate->factory()->get_string()); |
| 744 } | 744 } |
| 745 | 745 |
| 746 RETURN_FAILURE_ON_EXCEPTION( | 746 RETURN_FAILURE_ON_EXCEPTION( |
| 747 isolate, | 747 isolate, |
| 748 JSObject::DefineAccessor(object, name, getter, | 748 JSObject::DefineAccessor(object, name, getter, |
| 749 isolate->factory()->null_value(), attrs)); | 749 isolate->factory()->null_value(), attrs)); |
| 750 return isolate->heap()->undefined_value(); | 750 return isolate->heap()->undefined_value(); |
| 751 } | 751 } |
| 752 | 752 |
| 753 RUNTIME_FUNCTION(Runtime_CopyDataProperties) { | |
| 754 HandleScope scope(isolate); | |
| 755 DCHECK(args.length() == 2); | |
| 756 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); | |
| 757 CONVERT_ARG_HANDLE_CHECKED(Object, source, 1); | |
| 758 | |
| 759 // 2. If source is undefined or null, let keys be an empty List. | |
| 760 if (source->IsUndefined(isolate) || source->IsNull(isolate)) { | |
| 761 return isolate->heap()->undefined_value(); | |
| 762 } | |
| 763 | |
| 764 // 3. Else, | |
| 765 // 3a. Let from be ToObject(nextSource). | |
| 766 // Only non-empty strings and JSReceivers have enumerable properties. | |
| 767 Handle<JSReceiver> from = Object::ToObject(isolate, source).ToHandleChecked(); | |
|
adamk
2016/12/29 00:48:45
I think everything from here down should be shared
gsathya
2016/12/29 06:40:56
Done.
| |
| 768 // 3b. Let keys be ? from.[[OwnPropertyKeys]](). | |
| 769 Handle<FixedArray> keys; | |
| 770 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 771 isolate, keys, | |
| 772 KeyAccumulator::GetKeys(from, KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, | |
| 773 GetKeysConversion::kKeepNumbers)); | |
| 774 | |
| 775 // 4. Repeat for each element nextKey of keys in List order, | |
| 776 for (int j = 0; j < keys->length(); ++j) { | |
| 777 Handle<Object> next_key(keys->get(j), isolate); | |
| 778 // 4a i. Let desc be ? from.[[GetOwnProperty]](nextKey). | |
| 779 PropertyDescriptor desc; | |
| 780 Maybe<bool> found = | |
| 781 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); | |
| 782 if (found.IsNothing()) return isolate->heap()->exception(); | |
| 783 // 4a ii. If desc is not undefined and desc.[[Enumerable]] is true, then | |
| 784 if (found.FromJust() && desc.enumerable()) { | |
| 785 // 4a ii 1. Let propValue be ? Get(from, nextKey). | |
| 786 Handle<Object> prop_value; | |
| 787 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 788 isolate, prop_value, | |
| 789 Runtime::GetObjectProperty(isolate, from, next_key)); | |
| 790 | |
| 791 // 4a ii 2. Perform ? CreateDataProperty(target, nextKey, propValue). | |
| 792 bool success; | |
| 793 LookupIterator it = LookupIterator::PropertyOrElement( | |
| 794 isolate, target, next_key, &success, LookupIterator::OWN); | |
| 795 if (!success) return isolate->heap()->exception(); | |
| 796 MAYBE_RETURN(JSReceiver::CreateDataProperty(&it, prop_value, | |
| 797 Object::THROW_ON_ERROR), | |
| 798 isolate->heap()->exception()); | |
| 799 } | |
| 800 } | |
| 801 | |
| 802 return isolate->heap()->undefined_value(); | |
| 803 } | |
| 753 | 804 |
| 754 RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) { | 805 RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) { |
| 755 HandleScope scope(isolate); | 806 HandleScope scope(isolate); |
| 756 DCHECK(args.length() == 4); | 807 DCHECK(args.length() == 4); |
| 757 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 808 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 758 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 809 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 759 CONVERT_ARG_HANDLE_CHECKED(JSFunction, setter, 2); | 810 CONVERT_ARG_HANDLE_CHECKED(JSFunction, setter, 2); |
| 760 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 811 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
| 761 | 812 |
| 762 if (String::cast(setter->shared()->name())->length() == 0) { | 813 if (String::cast(setter->shared()->name())->length() == 0) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 931 if (!success) return isolate->heap()->exception(); | 982 if (!success) return isolate->heap()->exception(); |
| 932 MAYBE_RETURN( | 983 MAYBE_RETURN( |
| 933 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 984 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
| 934 isolate->heap()->exception()); | 985 isolate->heap()->exception()); |
| 935 return *value; | 986 return *value; |
| 936 } | 987 } |
| 937 | 988 |
| 938 | 989 |
| 939 } // namespace internal | 990 } // namespace internal |
| 940 } // namespace v8 | 991 } // namespace v8 |
| OLD | NEW |