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 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, from, | |
1462 Object::ToObject(isolate, next_source)); | |
Toon Verwaest
2015/12/11 10:06:06
This cannot fail anymore right?
Jakob Kummerow
2015/12/11 12:04:10
Done.
| |
1463 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]](). | |
1464 Handle<FixedArray> keys; | |
1465 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1466 isolate, keys, JSReceiver::GetKeys(from, JSReceiver::OWN_ONLY, | |
1467 ALL_PROPERTIES, KEEP_NUMBERS)); | |
1468 // 4c. Repeat for each element nextKey of keys in List order, | |
1469 for (int j = 0; j < keys->length(); ++j) { | |
1470 Handle<Object> next_key(keys->get(j), isolate); | |
1471 // 4c i. Let desc be ? from.[[GetOwnProperty]](nextKey). | |
1472 PropertyDescriptor desc; | |
1473 Maybe<bool> found = | |
1474 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); | |
1475 if (found.IsNothing()) return isolate->heap()->exception(); | |
1476 // 4c ii. If desc is not undefined and desc.[[Enumerable]] is true, then | |
1477 if (found.FromJust() && desc.enumerable()) { | |
1478 // 4c ii 1. Let propValue be ? Get(from, nextKey). | |
1479 Handle<Object> prop_value; | |
1480 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1481 isolate, prop_value, | |
1482 Runtime::GetObjectProperty(isolate, from, next_key, STRICT)); | |
1483 // 4c ii 2. Let status be ? Set(to, nextKey, propValue, true). | |
1484 Handle<Object> status; | |
1485 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1486 isolate, status, Runtime::SetObjectProperty(isolate, to, next_key, | |
1487 prop_value, STRICT)); | |
1488 } | |
1489 } | |
1490 } | |
1491 // 5. Return to. | |
1492 return *to; | |
1493 } | |
1494 | |
1495 | |
1437 // ES6 section 26.1.3 Reflect.defineProperty | 1496 // ES6 section 26.1.3 Reflect.defineProperty |
1438 BUILTIN(ReflectDefineProperty) { | 1497 BUILTIN(ReflectDefineProperty) { |
1439 HandleScope scope(isolate); | 1498 HandleScope scope(isolate); |
1440 DCHECK_EQ(4, args.length()); | 1499 DCHECK_EQ(4, args.length()); |
1441 Handle<Object> target = args.at<Object>(1); | 1500 Handle<Object> target = args.at<Object>(1); |
1442 Handle<Object> key = args.at<Object>(2); | 1501 Handle<Object> key = args.at<Object>(2); |
1443 Handle<Object> attributes = args.at<Object>(3); | 1502 Handle<Object> attributes = args.at<Object>(3); |
1444 | 1503 |
1445 if (!target->IsJSReceiver()) { | 1504 if (!target->IsJSReceiver()) { |
1446 THROW_NEW_ERROR_RETURN_FAILURE( | 1505 THROW_NEW_ERROR_RETURN_FAILURE( |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2435 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 2494 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
2436 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2495 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
2437 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2496 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
2438 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2497 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
2439 #undef DEFINE_BUILTIN_ACCESSOR_C | 2498 #undef DEFINE_BUILTIN_ACCESSOR_C |
2440 #undef DEFINE_BUILTIN_ACCESSOR_A | 2499 #undef DEFINE_BUILTIN_ACCESSOR_A |
2441 | 2500 |
2442 | 2501 |
2443 } // namespace internal | 2502 } // namespace internal |
2444 } // namespace v8 | 2503 } // namespace v8 |
OLD | NEW |