Chromium Code Reviews| Index: src/runtime/runtime-object.cc |
| diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc |
| index c1477769bacdd569ff3d4903cc7ea4806d632509..7eef0de4ade575a4314891e86b6e3262b19d780d 100644 |
| --- a/src/runtime/runtime-object.cc |
| +++ b/src/runtime/runtime-object.cc |
| @@ -750,6 +750,57 @@ RUNTIME_FUNCTION(Runtime_DefineGetterPropertyUnchecked) { |
| return isolate->heap()->undefined_value(); |
| } |
| +RUNTIME_FUNCTION(Runtime_CopyDataProperties) { |
| + HandleScope scope(isolate); |
| + DCHECK(args.length() == 2); |
| + CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); |
| + CONVERT_ARG_HANDLE_CHECKED(Object, source, 1); |
| + |
| + // 2. If source is undefined or null, let keys be an empty List. |
| + if (source->IsUndefined(isolate) || source->IsNull(isolate)) { |
| + return isolate->heap()->undefined_value(); |
| + } |
| + |
| + // 3. Else, |
| + // 3a. Let from be ToObject(nextSource). |
| + // Only non-empty strings and JSReceivers have enumerable properties. |
| + 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.
|
| + // 3b. Let keys be ? from.[[OwnPropertyKeys]](). |
| + Handle<FixedArray> keys; |
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, keys, |
| + KeyAccumulator::GetKeys(from, KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, |
| + GetKeysConversion::kKeepNumbers)); |
| + |
| + // 4. Repeat for each element nextKey of keys in List order, |
| + for (int j = 0; j < keys->length(); ++j) { |
| + Handle<Object> next_key(keys->get(j), isolate); |
| + // 4a i. Let desc be ? from.[[GetOwnProperty]](nextKey). |
| + PropertyDescriptor desc; |
| + Maybe<bool> found = |
| + JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); |
| + if (found.IsNothing()) return isolate->heap()->exception(); |
| + // 4a ii. If desc is not undefined and desc.[[Enumerable]] is true, then |
| + if (found.FromJust() && desc.enumerable()) { |
| + // 4a ii 1. Let propValue be ? Get(from, nextKey). |
| + Handle<Object> prop_value; |
| + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, prop_value, |
| + Runtime::GetObjectProperty(isolate, from, next_key)); |
| + |
| + // 4a ii 2. Perform ? CreateDataProperty(target, nextKey, propValue). |
| + bool success; |
| + LookupIterator it = LookupIterator::PropertyOrElement( |
| + isolate, target, next_key, &success, LookupIterator::OWN); |
| + if (!success) return isolate->heap()->exception(); |
| + MAYBE_RETURN(JSReceiver::CreateDataProperty(&it, prop_value, |
| + Object::THROW_ON_ERROR), |
| + isolate->heap()->exception()); |
| + } |
| + } |
| + |
| + return isolate->heap()->undefined_value(); |
| +} |
| RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) { |
| HandleScope scope(isolate); |