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 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1421 NewRangeError(MessageTemplate::kInvalidArrayLength), | 1421 NewRangeError(MessageTemplate::kInvalidArrayLength), |
1422 JSArray); | 1422 JSArray); |
1423 } | 1423 } |
1424 } | 1424 } |
1425 } | 1425 } |
1426 return ElementsAccessor::Concat(isolate, args, n_arguments); | 1426 return ElementsAccessor::Concat(isolate, args, n_arguments); |
1427 } | 1427 } |
1428 | 1428 |
1429 } // namespace | 1429 } // namespace |
1430 | 1430 |
1431 | |
1431 // ES6 22.1.3.1 Array.prototype.concat | 1432 // ES6 22.1.3.1 Array.prototype.concat |
1432 BUILTIN(ArrayConcat) { | 1433 BUILTIN(ArrayConcat) { |
1433 HandleScope scope(isolate); | 1434 HandleScope scope(isolate); |
1434 | 1435 |
1435 Handle<Object> receiver; | 1436 Handle<Object> receiver = args.receiver(); |
1436 if (!Object::ToObject(isolate, handle(args[0], isolate)) | 1437 // TODO(bmeurer): Do we really care about the exact exception message here? |
Yang
2016/01/15 12:42:34
I don't think this is important. As long as you ad
| |
1437 .ToHandle(&receiver)) { | 1438 if (receiver->IsNull() || receiver->IsUndefined()) { |
1438 THROW_NEW_ERROR_RETURN_FAILURE( | 1439 THROW_NEW_ERROR_RETURN_FAILURE( |
1439 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, | 1440 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, |
1440 isolate->factory()->NewStringFromAsciiChecked( | 1441 isolate->factory()->NewStringFromAsciiChecked( |
1441 "Array.prototype.concat"))); | 1442 "Array.prototype.concat"))); |
1442 } | 1443 } |
1444 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1445 isolate, receiver, Object::ToObject(isolate, args.receiver())); | |
1443 args[0] = *receiver; | 1446 args[0] = *receiver; |
1444 | 1447 |
1445 Handle<JSArray> result_array; | 1448 Handle<JSArray> result_array; |
1446 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { | 1449 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { |
1447 return *result_array; | 1450 return *result_array; |
1448 } | 1451 } |
1449 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 1452 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
1450 return Slow_ArrayConcat(&args, isolate); | 1453 return Slow_ArrayConcat(&args, isolate); |
1451 } | 1454 } |
1452 | 1455 |
1453 | 1456 |
1454 // ES6 22.1.2.2 Array.isArray | 1457 // ES6 22.1.2.2 Array.isArray |
1455 BUILTIN(ArrayIsArray) { | 1458 BUILTIN(ArrayIsArray) { |
1456 HandleScope scope(isolate); | 1459 HandleScope scope(isolate); |
1457 DCHECK_EQ(2, args.length()); | 1460 DCHECK_EQ(2, args.length()); |
1458 Handle<Object> object = args.at<Object>(1); | 1461 Handle<Object> object = args.at<Object>(1); |
1459 Maybe<bool> result = Object::IsArray(object); | 1462 Maybe<bool> result = Object::IsArray(object); |
1460 MAYBE_RETURN(result, isolate->heap()->exception()); | 1463 MAYBE_RETURN(result, isolate->heap()->exception()); |
1461 return *isolate->factory()->ToBoolean(result.FromJust()); | 1464 return *isolate->factory()->ToBoolean(result.FromJust()); |
1462 } | 1465 } |
1463 | 1466 |
1464 | 1467 |
1465 // ES6 19.1.2.1 Object.assign | 1468 // ES6 19.1.2.1 Object.assign |
1466 BUILTIN(ObjectAssign) { | 1469 BUILTIN(ObjectAssign) { |
1467 HandleScope scope(isolate); | 1470 HandleScope scope(isolate); |
1468 Handle<Object> target = args.atOrUndefined(isolate, 1); | 1471 Handle<Object> target = args.atOrUndefined(isolate, 1); |
1469 | 1472 |
1470 // 1. Let to be ? ToObject(target). | 1473 // 1. Let to be ? ToObject(target). |
1471 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target, | 1474 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target, |
1472 Execution::ToObject(isolate, target)); | 1475 Object::ToObject(isolate, target)); |
1473 Handle<JSReceiver> to = Handle<JSReceiver>::cast(target); | 1476 Handle<JSReceiver> to = Handle<JSReceiver>::cast(target); |
1474 // 2. If only one argument was passed, return to. | 1477 // 2. If only one argument was passed, return to. |
1475 if (args.length() == 2) return *to; | 1478 if (args.length() == 2) return *to; |
1476 // 3. Let sources be the List of argument values starting with the | 1479 // 3. Let sources be the List of argument values starting with the |
1477 // second argument. | 1480 // second argument. |
1478 // 4. For each element nextSource of sources, in ascending index order, | 1481 // 4. For each element nextSource of sources, in ascending index order, |
1479 for (int i = 2; i < args.length(); ++i) { | 1482 for (int i = 2; i < args.length(); ++i) { |
1480 Handle<Object> next_source = args.at<Object>(i); | 1483 Handle<Object> next_source = args.at<Object>(i); |
1481 // 4a. If nextSource is undefined or null, let keys be an empty List. | 1484 // 4a. If nextSource is undefined or null, let keys be an empty List. |
1482 if (next_source->IsUndefined() || next_source->IsNull()) continue; | 1485 if (next_source->IsUndefined() || next_source->IsNull()) continue; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1562 return *object; | 1565 return *object; |
1563 } | 1566 } |
1564 | 1567 |
1565 | 1568 |
1566 // ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O ) | 1569 // ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O ) |
1567 BUILTIN(ObjectGetOwnPropertySymbols) { | 1570 BUILTIN(ObjectGetOwnPropertySymbols) { |
1568 HandleScope scope(isolate); | 1571 HandleScope scope(isolate); |
1569 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1572 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1570 Handle<JSReceiver> receiver; | 1573 Handle<JSReceiver> receiver; |
1571 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1574 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
1572 Execution::ToObject(isolate, object)); | 1575 Object::ToObject(isolate, object)); |
1573 Handle<FixedArray> keys; | 1576 Handle<FixedArray> keys; |
1574 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1577 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1575 isolate, keys, JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, | 1578 isolate, keys, JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, |
1576 SKIP_STRINGS, CONVERT_TO_STRING)); | 1579 SKIP_STRINGS, CONVERT_TO_STRING)); |
1577 return *isolate->factory()->NewJSArrayWithElements(keys); | 1580 return *isolate->factory()->NewJSArrayWithElements(keys); |
1578 } | 1581 } |
1579 | 1582 |
1580 | 1583 |
1581 // ES6 section 19.1.2.11 Object.isExtensible ( O ) | 1584 // ES6 section 19.1.2.11 Object.isExtensible ( O ) |
1582 BUILTIN(ObjectIsExtensible) { | 1585 BUILTIN(ObjectIsExtensible) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1616 return isolate->heap()->ToBoolean(result.FromJust()); | 1619 return isolate->heap()->ToBoolean(result.FromJust()); |
1617 } | 1620 } |
1618 | 1621 |
1619 | 1622 |
1620 // ES6 section 19.1.2.14 Object.keys ( O ) | 1623 // ES6 section 19.1.2.14 Object.keys ( O ) |
1621 BUILTIN(ObjectKeys) { | 1624 BUILTIN(ObjectKeys) { |
1622 HandleScope scope(isolate); | 1625 HandleScope scope(isolate); |
1623 Handle<Object> object = args.atOrUndefined(isolate, 1); | 1626 Handle<Object> object = args.atOrUndefined(isolate, 1); |
1624 Handle<JSReceiver> receiver; | 1627 Handle<JSReceiver> receiver; |
1625 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 1628 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
1626 Execution::ToObject(isolate, object)); | 1629 Object::ToObject(isolate, object)); |
1627 Handle<FixedArray> keys; | 1630 Handle<FixedArray> keys; |
1628 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1631 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1629 isolate, keys, | 1632 isolate, keys, |
1630 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, | 1633 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, |
1631 CONVERT_TO_STRING)); | 1634 CONVERT_TO_STRING)); |
1632 return *isolate->factory()->NewJSArrayWithElements(keys); | 1635 return *isolate->factory()->NewJSArrayWithElements(keys); |
1633 } | 1636 } |
1634 | 1637 |
1635 | 1638 |
1636 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) | 1639 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) |
(...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3978 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 3981 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
3979 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 3982 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
3980 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 3983 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
3981 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 3984 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
3982 #undef DEFINE_BUILTIN_ACCESSOR_C | 3985 #undef DEFINE_BUILTIN_ACCESSOR_C |
3983 #undef DEFINE_BUILTIN_ACCESSOR_A | 3986 #undef DEFINE_BUILTIN_ACCESSOR_A |
3984 | 3987 |
3985 | 3988 |
3986 } // namespace internal | 3989 } // namespace internal |
3987 } // namespace v8 | 3990 } // namespace v8 |
OLD | NEW |