OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 BUILTIN(ArrayIsArray) { | 1427 BUILTIN(ArrayIsArray) { |
1428 HandleScope scope(isolate); | 1428 HandleScope scope(isolate); |
1429 DCHECK_EQ(2, args.length()); | 1429 DCHECK_EQ(2, args.length()); |
1430 Handle<Object> object = args.at<Object>(1); | 1430 Handle<Object> object = args.at<Object>(1); |
1431 Maybe<bool> result = Object::IsArray(object); | 1431 Maybe<bool> result = Object::IsArray(object); |
1432 MAYBE_RETURN(result, isolate->heap()->exception()); | 1432 MAYBE_RETURN(result, isolate->heap()->exception()); |
1433 return *isolate->factory()->ToBoolean(result.FromJust()); | 1433 return *isolate->factory()->ToBoolean(result.FromJust()); |
1434 } | 1434 } |
1435 | 1435 |
1436 | 1436 |
| 1437 // ES6 19.1.2.1 Object.assign |
| 1438 BUILTIN(ObjectAssign) { |
| 1439 HandleScope scope(isolate); |
| 1440 Handle<Object> target = |
| 1441 args.length() > 1 |
| 1442 ? args.at<Object>(1) |
| 1443 : Handle<Object>::cast(isolate->factory()->undefined_value()); |
| 1444 |
| 1445 // 1. Let to be ? ToObject(target). |
| 1446 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target, |
| 1447 Execution::ToObject(isolate, target)); |
| 1448 Handle<JSReceiver> to = Handle<JSReceiver>::cast(target); |
| 1449 // 2. If only one argument was passed, return to. |
| 1450 if (args.length() == 2) return *to; |
| 1451 // 3. Let sources be the List of argument values starting with the |
| 1452 // second argument. |
| 1453 // 4. For each element nextSource of sources, in ascending index order, |
| 1454 for (int i = 2; i < args.length(); ++i) { |
| 1455 Handle<Object> next_source = args.at<Object>(i); |
| 1456 // 4a. If nextSource is undefined or null, let keys be an empty List. |
| 1457 if (next_source->IsUndefined() || next_source->IsNull()) continue; |
| 1458 // 4b. Else, |
| 1459 // 4b i. Let from be ToObject(nextSource). |
| 1460 Handle<JSReceiver> from = |
| 1461 Object::ToObject(isolate, next_source).ToHandleChecked(); |
| 1462 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]](). |
| 1463 Handle<FixedArray> keys; |
| 1464 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1465 isolate, keys, JSReceiver::GetKeys(from, JSReceiver::OWN_ONLY, |
| 1466 ALL_PROPERTIES, KEEP_NUMBERS)); |
| 1467 // 4c. Repeat for each element nextKey of keys in List order, |
| 1468 for (int j = 0; j < keys->length(); ++j) { |
| 1469 Handle<Object> next_key(keys->get(j), isolate); |
| 1470 // 4c i. Let desc be ? from.[[GetOwnProperty]](nextKey). |
| 1471 PropertyDescriptor desc; |
| 1472 Maybe<bool> found = |
| 1473 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); |
| 1474 if (found.IsNothing()) return isolate->heap()->exception(); |
| 1475 // 4c ii. If desc is not undefined and desc.[[Enumerable]] is true, then |
| 1476 if (found.FromJust() && desc.enumerable()) { |
| 1477 // 4c ii 1. Let propValue be ? Get(from, nextKey). |
| 1478 Handle<Object> prop_value; |
| 1479 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1480 isolate, prop_value, |
| 1481 Runtime::GetObjectProperty(isolate, from, next_key, STRICT)); |
| 1482 // 4c ii 2. Let status be ? Set(to, nextKey, propValue, true). |
| 1483 Handle<Object> status; |
| 1484 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1485 isolate, status, Runtime::SetObjectProperty(isolate, to, next_key, |
| 1486 prop_value, STRICT)); |
| 1487 } |
| 1488 } |
| 1489 } |
| 1490 // 5. Return to. |
| 1491 return *to; |
| 1492 } |
| 1493 |
| 1494 |
1437 // ES6 section 26.1.3 Reflect.defineProperty | 1495 // ES6 section 26.1.3 Reflect.defineProperty |
1438 BUILTIN(ReflectDefineProperty) { | 1496 BUILTIN(ReflectDefineProperty) { |
1439 HandleScope scope(isolate); | 1497 HandleScope scope(isolate); |
1440 DCHECK_EQ(4, args.length()); | 1498 DCHECK_EQ(4, args.length()); |
1441 Handle<Object> target = args.at<Object>(1); | 1499 Handle<Object> target = args.at<Object>(1); |
1442 Handle<Object> key = args.at<Object>(2); | 1500 Handle<Object> key = args.at<Object>(2); |
1443 Handle<Object> attributes = args.at<Object>(3); | 1501 Handle<Object> attributes = args.at<Object>(3); |
1444 | 1502 |
1445 if (!target->IsJSReceiver()) { | 1503 if (!target->IsJSReceiver()) { |
1446 THROW_NEW_ERROR_RETURN_FAILURE( | 1504 THROW_NEW_ERROR_RETURN_FAILURE( |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2448 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 2506 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
2449 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2507 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
2450 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2508 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
2451 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2509 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
2452 #undef DEFINE_BUILTIN_ACCESSOR_C | 2510 #undef DEFINE_BUILTIN_ACCESSOR_C |
2453 #undef DEFINE_BUILTIN_ACCESSOR_A | 2511 #undef DEFINE_BUILTIN_ACCESSOR_A |
2454 | 2512 |
2455 | 2513 |
2456 } // namespace internal | 2514 } // namespace internal |
2457 } // namespace v8 | 2515 } // namespace v8 |
OLD | NEW |