| 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 29 matching lines...) Expand all Loading... |
| 40 Object*& operator[] (int index) { | 40 Object*& operator[] (int index) { |
| 41 DCHECK(index < length()); | 41 DCHECK(index < length()); |
| 42 return Arguments::operator[](index); | 42 return Arguments::operator[](index); |
| 43 } | 43 } |
| 44 | 44 |
| 45 template <class S> Handle<S> at(int index) { | 45 template <class S> Handle<S> at(int index) { |
| 46 DCHECK(index < length()); | 46 DCHECK(index < length()); |
| 47 return Arguments::at<S>(index); | 47 return Arguments::at<S>(index); |
| 48 } | 48 } |
| 49 | 49 |
| 50 Handle<Object> atOrUndefined(Isolate* isolate, int index) { |
| 51 if (index >= length()) { |
| 52 return isolate->factory()->undefined_value(); |
| 53 } |
| 54 return at<Object>(index); |
| 55 } |
| 56 |
| 50 Handle<Object> receiver() { | 57 Handle<Object> receiver() { |
| 51 return Arguments::at<Object>(0); | 58 return Arguments::at<Object>(0); |
| 52 } | 59 } |
| 53 | 60 |
| 54 Handle<JSFunction> target(); | 61 Handle<JSFunction> target(); |
| 55 Handle<HeapObject> new_target(); | 62 Handle<HeapObject> new_target(); |
| 56 | 63 |
| 57 // Gets the total number of arguments including the receiver (but | 64 // Gets the total number of arguments including the receiver (but |
| 58 // excluding extra arguments). | 65 // excluding extra arguments). |
| 59 int length() const; | 66 int length() const; |
| (...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 Handle<Object> object = args.at<Object>(1); | 1430 Handle<Object> object = args.at<Object>(1); |
| 1424 Maybe<bool> result = Object::IsArray(object); | 1431 Maybe<bool> result = Object::IsArray(object); |
| 1425 MAYBE_RETURN(result, isolate->heap()->exception()); | 1432 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 1426 return *isolate->factory()->ToBoolean(result.FromJust()); | 1433 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 1427 } | 1434 } |
| 1428 | 1435 |
| 1429 | 1436 |
| 1430 // ES6 19.1.2.1 Object.assign | 1437 // ES6 19.1.2.1 Object.assign |
| 1431 BUILTIN(ObjectAssign) { | 1438 BUILTIN(ObjectAssign) { |
| 1432 HandleScope scope(isolate); | 1439 HandleScope scope(isolate); |
| 1433 Handle<Object> target = | 1440 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 1434 args.length() > 1 | |
| 1435 ? args.at<Object>(1) | |
| 1436 : Handle<Object>::cast(isolate->factory()->undefined_value()); | |
| 1437 | 1441 |
| 1438 // 1. Let to be ? ToObject(target). | 1442 // 1. Let to be ? ToObject(target). |
| 1439 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target, | 1443 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target, |
| 1440 Execution::ToObject(isolate, target)); | 1444 Execution::ToObject(isolate, target)); |
| 1441 Handle<JSReceiver> to = Handle<JSReceiver>::cast(target); | 1445 Handle<JSReceiver> to = Handle<JSReceiver>::cast(target); |
| 1442 // 2. If only one argument was passed, return to. | 1446 // 2. If only one argument was passed, return to. |
| 1443 if (args.length() == 2) return *to; | 1447 if (args.length() == 2) return *to; |
| 1444 // 3. Let sources be the List of argument values starting with the | 1448 // 3. Let sources be the List of argument values starting with the |
| 1445 // second argument. | 1449 // second argument. |
| 1446 // 4. For each element nextSource of sources, in ascending index order, | 1450 // 4. For each element nextSource of sources, in ascending index order, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 Maybe<bool> result = JSReceiver::DeletePropertyOrElement( | 1610 Maybe<bool> result = JSReceiver::DeletePropertyOrElement( |
| 1607 Handle<JSReceiver>::cast(target), name, SLOPPY); | 1611 Handle<JSReceiver>::cast(target), name, SLOPPY); |
| 1608 MAYBE_RETURN(result, isolate->heap()->exception()); | 1612 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 1609 return *isolate->factory()->ToBoolean(result.FromJust()); | 1613 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 1610 } | 1614 } |
| 1611 | 1615 |
| 1612 | 1616 |
| 1613 // ES6 section 26.1.6 Reflect.get | 1617 // ES6 section 26.1.6 Reflect.get |
| 1614 BUILTIN(ReflectGet) { | 1618 BUILTIN(ReflectGet) { |
| 1615 HandleScope scope(isolate); | 1619 HandleScope scope(isolate); |
| 1616 Handle<Object> undef = isolate->factory()->undefined_value(); | 1620 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 1617 Handle<Object> target = args.length() > 1 ? args.at<Object>(1) : undef; | 1621 Handle<Object> key = args.atOrUndefined(isolate, 2); |
| 1618 Handle<Object> key = args.length() > 2 ? args.at<Object>(2) : undef; | |
| 1619 Handle<Object> receiver = args.length() > 3 ? args.at<Object>(3) : target; | 1622 Handle<Object> receiver = args.length() > 3 ? args.at<Object>(3) : target; |
| 1620 | 1623 |
| 1621 if (!target->IsJSReceiver()) { | 1624 if (!target->IsJSReceiver()) { |
| 1622 THROW_NEW_ERROR_RETURN_FAILURE( | 1625 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1623 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 1626 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 1624 isolate->factory()->NewStringFromAsciiChecked( | 1627 isolate->factory()->NewStringFromAsciiChecked( |
| 1625 "Reflect.get"))); | 1628 "Reflect.get"))); |
| 1626 } | 1629 } |
| 1627 | 1630 |
| 1628 Handle<Name> name; | 1631 Handle<Name> name; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 Maybe<bool> result = JSReceiver::PreventExtensions( | 1770 Maybe<bool> result = JSReceiver::PreventExtensions( |
| 1768 Handle<JSReceiver>::cast(target), Object::DONT_THROW); | 1771 Handle<JSReceiver>::cast(target), Object::DONT_THROW); |
| 1769 MAYBE_RETURN(result, isolate->heap()->exception()); | 1772 MAYBE_RETURN(result, isolate->heap()->exception()); |
| 1770 return *isolate->factory()->ToBoolean(result.FromJust()); | 1773 return *isolate->factory()->ToBoolean(result.FromJust()); |
| 1771 } | 1774 } |
| 1772 | 1775 |
| 1773 | 1776 |
| 1774 // ES6 section 26.1.13 Reflect.set | 1777 // ES6 section 26.1.13 Reflect.set |
| 1775 BUILTIN(ReflectSet) { | 1778 BUILTIN(ReflectSet) { |
| 1776 HandleScope scope(isolate); | 1779 HandleScope scope(isolate); |
| 1777 Handle<Object> undef = isolate->factory()->undefined_value(); | 1780 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 1778 Handle<Object> target = args.length() > 1 ? args.at<Object>(1) : undef; | 1781 Handle<Object> key = args.atOrUndefined(isolate, 2); |
| 1779 Handle<Object> key = args.length() > 2 ? args.at<Object>(2) : undef; | 1782 Handle<Object> value = args.atOrUndefined(isolate, 3); |
| 1780 Handle<Object> value = args.length() > 3 ? args.at<Object>(3) : undef; | |
| 1781 Handle<Object> receiver = args.length() > 4 ? args.at<Object>(4) : target; | 1783 Handle<Object> receiver = args.length() > 4 ? args.at<Object>(4) : target; |
| 1782 | 1784 |
| 1783 if (!target->IsJSReceiver()) { | 1785 if (!target->IsJSReceiver()) { |
| 1784 THROW_NEW_ERROR_RETURN_FAILURE( | 1786 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1785 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, | 1787 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 1786 isolate->factory()->NewStringFromAsciiChecked( | 1788 isolate->factory()->NewStringFromAsciiChecked( |
| 1787 "Reflect.set"))); | 1789 "Reflect.set"))); |
| 1788 } | 1790 } |
| 1789 | 1791 |
| 1790 Handle<Name> name; | 1792 Handle<Name> name; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 isolate, | 2048 isolate, |
| 2047 NewTypeError(MessageTemplate::kConstructorNotFunction, | 2049 NewTypeError(MessageTemplate::kConstructorNotFunction, |
| 2048 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); | 2050 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); |
| 2049 } | 2051 } |
| 2050 | 2052 |
| 2051 | 2053 |
| 2052 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. | 2054 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. |
| 2053 BUILTIN(ProxyConstructor_ConstructStub) { | 2055 BUILTIN(ProxyConstructor_ConstructStub) { |
| 2054 HandleScope scope(isolate); | 2056 HandleScope scope(isolate); |
| 2055 DCHECK(isolate->proxy_function()->IsConstructor()); | 2057 DCHECK(isolate->proxy_function()->IsConstructor()); |
| 2056 Handle<Object> target; | 2058 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 2057 if (args.length() < 2) { | 2059 Handle<Object> handler = args.atOrUndefined(isolate, 2); |
| 2058 target = isolate->factory()->undefined_value(); | |
| 2059 } else { | |
| 2060 target = args.at<Object>(1); | |
| 2061 } | |
| 2062 Handle<Object> handler; | |
| 2063 if (args.length() < 3) { | |
| 2064 handler = isolate->factory()->undefined_value(); | |
| 2065 } else { | |
| 2066 handler = args.at<Object>(2); | |
| 2067 } | |
| 2068 // The ConstructStub is executed in the context of the caller, so we need | 2060 // The ConstructStub is executed in the context of the caller, so we need |
| 2069 // to enter the callee context first before raising an exception. | 2061 // to enter the callee context first before raising an exception. |
| 2070 isolate->set_context(args.target()->context()); | 2062 isolate->set_context(args.target()->context()); |
| 2071 Handle<JSProxy> result; | 2063 Handle<JSProxy> result; |
| 2072 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | 2064 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
| 2073 JSProxy::New(isolate, target, handler)); | 2065 JSProxy::New(isolate, target, handler)); |
| 2074 return *result; | 2066 return *result; |
| 2075 } | 2067 } |
| 2076 | 2068 |
| 2077 | 2069 |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2700 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 2692 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 2701 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2693 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 2702 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2694 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 2703 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2695 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 2704 #undef DEFINE_BUILTIN_ACCESSOR_C | 2696 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 2705 #undef DEFINE_BUILTIN_ACCESSOR_A | 2697 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 2706 | 2698 |
| 2707 | 2699 |
| 2708 } // namespace internal | 2700 } // namespace internal |
| 2709 } // namespace v8 | 2701 } // namespace v8 |
| OLD | NEW |