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 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 | 1437 |
1438 Handle<JSArray> result_array; | 1438 Handle<JSArray> result_array; |
1439 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { | 1439 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { |
1440 return *result_array; | 1440 return *result_array; |
1441 } | 1441 } |
1442 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 1442 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
1443 return Slow_ArrayConcat(&args, isolate); | 1443 return Slow_ArrayConcat(&args, isolate); |
1444 } | 1444 } |
1445 | 1445 |
1446 | 1446 |
| 1447 // ES6 section 26.1.4 Reflect.deleteProperty |
| 1448 BUILTIN(ReflectDeleteProperty) { |
| 1449 HandleScope scope(isolate); |
| 1450 DCHECK_EQ(3, args.length()); |
| 1451 Handle<Object> target = args.at<Object>(1); |
| 1452 Handle<Object> key = args.at<Object>(2); |
| 1453 |
| 1454 if (!target->IsJSReceiver()) { |
| 1455 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1456 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 1457 isolate->factory()->NewStringFromAsciiChecked( |
| 1458 "Reflect.deleteProperty"))); |
| 1459 } |
| 1460 |
| 1461 Handle<Name> name; |
| 1462 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 1463 Object::ToName(isolate, key)); |
| 1464 |
| 1465 Handle<Object> result; |
| 1466 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1467 isolate, result, JSReceiver::DeletePropertyOrElement( |
| 1468 Handle<JSReceiver>::cast(target), name)); |
| 1469 |
| 1470 return *result; |
| 1471 } |
| 1472 |
| 1473 |
| 1474 // ES6 section 26.1.6 Reflect.get |
| 1475 BUILTIN(ReflectGet) { |
| 1476 HandleScope scope(isolate); |
| 1477 DCHECK_LE(3, args.length()); |
| 1478 DCHECK_LE(args.length(), 4); |
| 1479 Handle<Object> target = args.at<Object>(1); |
| 1480 Handle<Object> key = args.at<Object>(2); |
| 1481 // Handle<Object> receiver = args.length() == 4 ? args.at<Object>(3) : target; |
| 1482 // |
| 1483 // TODO(neis): We ignore the receiver argument for now because |
| 1484 // GetPropertyOrElement doesn't support it yet. |
| 1485 |
| 1486 if (!target->IsJSReceiver()) { |
| 1487 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1488 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 1489 isolate->factory()->NewStringFromAsciiChecked( |
| 1490 "Reflect.get"))); |
| 1491 } |
| 1492 |
| 1493 Handle<Name> name; |
| 1494 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 1495 Object::ToName(isolate, key)); |
| 1496 |
| 1497 Handle<Object> result; |
| 1498 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1499 isolate, result, Object::GetPropertyOrElement(target, name)); |
| 1500 |
| 1501 return *result; |
| 1502 } |
| 1503 |
| 1504 |
| 1505 // ES6 section 26.1.9 Reflect.has |
| 1506 BUILTIN(ReflectHas) { |
| 1507 HandleScope scope(isolate); |
| 1508 DCHECK_EQ(3, args.length()); |
| 1509 Handle<Object> target = args.at<Object>(1); |
| 1510 Handle<Object> key = args.at<Object>(2); |
| 1511 |
| 1512 if (!target->IsJSReceiver()) { |
| 1513 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1514 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 1515 isolate->factory()->NewStringFromAsciiChecked( |
| 1516 "Reflect.has"))); |
| 1517 } |
| 1518 |
| 1519 Handle<Name> name; |
| 1520 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name, |
| 1521 Object::ToName(isolate, key)); |
| 1522 |
| 1523 Maybe<bool> maybe = |
| 1524 JSReceiver::HasProperty(Handle<JSReceiver>::cast(target), name); |
| 1525 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 1526 return *isolate->factory()->ToBoolean(maybe.FromJust()); |
| 1527 } |
| 1528 |
| 1529 |
| 1530 // ES6 section 26.1.10 Reflect.isExtensible |
| 1531 BUILTIN(ReflectIsExtensible) { |
| 1532 HandleScope scope(isolate); |
| 1533 DCHECK_EQ(2, args.length()); |
| 1534 Handle<Object> target = args.at<Object>(1); |
| 1535 |
| 1536 if (!target->IsJSReceiver()) { |
| 1537 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1538 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 1539 isolate->factory()->NewStringFromAsciiChecked( |
| 1540 "Reflect.isExtensible"))); |
| 1541 } |
| 1542 |
| 1543 // TODO(neis): For now, we ignore proxies. Once proxies are fully |
| 1544 // implemented, do something like the following: |
| 1545 /* |
| 1546 Maybe<bool> maybe = JSReceiver::IsExtensible( |
| 1547 Handle<JSReceiver>::cast(target)); |
| 1548 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 1549 return *isolate->factory()->ToBoolean(maybe.FromJust()); |
| 1550 */ |
| 1551 |
| 1552 if (target->IsJSObject()) { |
| 1553 return *isolate->factory()->ToBoolean( |
| 1554 JSObject::IsExtensible(Handle<JSObject>::cast(target))); |
| 1555 } |
| 1556 return *isolate->factory()->false_value(); |
| 1557 } |
| 1558 |
| 1559 |
1447 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) | 1560 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) |
1448 BUILTIN(DateToPrimitive) { | 1561 BUILTIN(DateToPrimitive) { |
1449 HandleScope scope(isolate); | 1562 HandleScope scope(isolate); |
1450 DCHECK_EQ(2, args.length()); | 1563 DCHECK_EQ(2, args.length()); |
1451 if (!args.receiver()->IsJSReceiver()) { | 1564 if (!args.receiver()->IsJSReceiver()) { |
1452 THROW_NEW_ERROR_RETURN_FAILURE( | 1565 THROW_NEW_ERROR_RETURN_FAILURE( |
1453 isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, | 1566 isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, |
1454 isolate->factory()->NewStringFromAsciiChecked( | 1567 isolate->factory()->NewStringFromAsciiChecked( |
1455 "Date.prototype [ @@toPrimitive ]"), | 1568 "Date.prototype [ @@toPrimitive ]"), |
1456 args.receiver())); | 1569 args.receiver())); |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 2202 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
2090 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2203 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
2091 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2204 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
2092 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2205 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
2093 #undef DEFINE_BUILTIN_ACCESSOR_C | 2206 #undef DEFINE_BUILTIN_ACCESSOR_C |
2094 #undef DEFINE_BUILTIN_ACCESSOR_A | 2207 #undef DEFINE_BUILTIN_ACCESSOR_A |
2095 | 2208 |
2096 | 2209 |
2097 } // namespace internal | 2210 } // namespace internal |
2098 } // namespace v8 | 2211 } // namespace v8 |
OLD | NEW |