| 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 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 SLOPPY, restriction, | 1532 SLOPPY, restriction, |
| 1533 RelocInfo::kNoPosition); | 1533 RelocInfo::kNoPosition); |
| 1534 } | 1534 } |
| 1535 | 1535 |
| 1536 } // namespace | 1536 } // namespace |
| 1537 | 1537 |
| 1538 | 1538 |
| 1539 // ES6 section 18.2.1 eval (x) | 1539 // ES6 section 18.2.1 eval (x) |
| 1540 BUILTIN(GlobalEval) { | 1540 BUILTIN(GlobalEval) { |
| 1541 HandleScope scope(isolate); | 1541 HandleScope scope(isolate); |
| 1542 DCHECK_LE(1, args.length()); | 1542 Handle<Object> x = args.atOrUndefined(isolate, 1); |
| 1543 Handle<Object> x = args.at<Object>(1); | |
| 1544 Handle<JSFunction> target = args.target(); | 1543 Handle<JSFunction> target = args.target(); |
| 1545 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); | 1544 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); |
| 1546 if (!x->IsString()) return *x; | 1545 if (!x->IsString()) return *x; |
| 1547 Handle<JSFunction> function; | 1546 Handle<JSFunction> function; |
| 1548 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1547 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1549 isolate, function, | 1548 isolate, function, |
| 1550 CompileString(handle(target->native_context(), isolate), | 1549 CompileString(handle(target->native_context(), isolate), |
| 1551 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); | 1550 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); |
| 1552 Handle<Object> result; | 1551 Handle<Object> result; |
| 1553 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1552 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 } | 2033 } |
| 2035 function->set_name(*name); | 2034 function->set_name(*name); |
| 2036 return *function; | 2035 return *function; |
| 2037 } | 2036 } |
| 2038 | 2037 |
| 2039 | 2038 |
| 2040 // ES6 section 19.2.3.5 Function.prototype.toString ( ) | 2039 // ES6 section 19.2.3.5 Function.prototype.toString ( ) |
| 2041 BUILTIN(FunctionPrototypeToString) { | 2040 BUILTIN(FunctionPrototypeToString) { |
| 2042 HandleScope scope(isolate); | 2041 HandleScope scope(isolate); |
| 2043 Handle<Object> receiver = args.receiver(); | 2042 Handle<Object> receiver = args.receiver(); |
| 2044 | |
| 2045 if (receiver->IsJSBoundFunction()) { | 2043 if (receiver->IsJSBoundFunction()) { |
| 2046 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver)); | 2044 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver)); |
| 2047 } else if (receiver->IsJSFunction()) { | 2045 } else if (receiver->IsJSFunction()) { |
| 2048 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver)); | 2046 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver)); |
| 2049 } | 2047 } |
| 2050 THROW_NEW_ERROR_RETURN_FAILURE( | 2048 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2051 isolate, NewTypeError(MessageTemplate::kNotGeneric, | 2049 isolate, NewTypeError(MessageTemplate::kNotGeneric, |
| 2052 isolate->factory()->NewStringFromAsciiChecked( | 2050 isolate->factory()->NewStringFromAsciiChecked( |
| 2053 "Function.prototype.toString"))); | 2051 "Function.prototype.toString"))); |
| 2054 } | 2052 } |
| 2055 | 2053 |
| 2056 | 2054 |
| 2057 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) | 2055 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) |
| 2058 BUILTIN(GeneratorFunctionConstructor) { | 2056 BUILTIN(GeneratorFunctionConstructor) { |
| 2059 HandleScope scope(isolate); | 2057 HandleScope scope(isolate); |
| 2060 Handle<JSFunction> result; | 2058 Handle<JSFunction> result; |
| 2061 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2059 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2062 isolate, result, CreateDynamicFunction(isolate, args, "function*")); | 2060 isolate, result, CreateDynamicFunction(isolate, args, "function*")); |
| 2063 return *result; | 2061 return *result; |
| 2064 } | 2062 } |
| 2065 | 2063 |
| 2066 | 2064 |
| 2067 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. | 2065 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. |
| 2068 BUILTIN(SymbolConstructor) { | 2066 BUILTIN(SymbolConstructor) { |
| 2069 HandleScope scope(isolate); | 2067 HandleScope scope(isolate); |
| 2070 DCHECK_EQ(2, args.length()); | |
| 2071 Handle<Symbol> result = isolate->factory()->NewSymbol(); | 2068 Handle<Symbol> result = isolate->factory()->NewSymbol(); |
| 2072 Handle<Object> description = args.at<Object>(1); | 2069 Handle<Object> description = args.atOrUndefined(isolate, 1); |
| 2073 if (!description->IsUndefined()) { | 2070 if (!description->IsUndefined()) { |
| 2074 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, | 2071 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, |
| 2075 Object::ToString(isolate, description)); | 2072 Object::ToString(isolate, description)); |
| 2076 result->set_name(*description); | 2073 result->set_name(*description); |
| 2077 } | 2074 } |
| 2078 return *result; | 2075 return *result; |
| 2079 } | 2076 } |
| 2080 | 2077 |
| 2081 | 2078 |
| 2082 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. | 2079 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case. |
| 2083 BUILTIN(SymbolConstructor_ConstructStub) { | 2080 BUILTIN(SymbolConstructor_ConstructStub) { |
| 2084 HandleScope scope(isolate); | 2081 HandleScope scope(isolate); |
| 2085 // The ConstructStub is executed in the context of the caller, so we need | |
| 2086 // to enter the callee context first before raising an exception. | |
| 2087 isolate->set_context(args.target()->context()); | |
| 2088 THROW_NEW_ERROR_RETURN_FAILURE( | 2082 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2089 isolate, NewTypeError(MessageTemplate::kNotConstructor, | 2083 isolate, NewTypeError(MessageTemplate::kNotConstructor, |
| 2090 isolate->factory()->Symbol_string())); | 2084 isolate->factory()->Symbol_string())); |
| 2091 } | 2085 } |
| 2092 | 2086 |
| 2093 | 2087 |
| 2094 // ES6 19.1.3.6 Object.prototype.toString | 2088 // ES6 19.1.3.6 Object.prototype.toString |
| 2095 BUILTIN(ObjectProtoToString) { | 2089 BUILTIN(ObjectProtoToString) { |
| 2096 HandleScope scope(isolate); | 2090 HandleScope scope(isolate); |
| 2097 Handle<Object> object = args.at<Object>(0); | 2091 Handle<Object> object = args.at<Object>(0); |
| 2098 Handle<String> result; | 2092 Handle<String> result; |
| 2099 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2093 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 2100 isolate, result, JSObject::ObjectProtoToString(isolate, object)); | 2094 isolate, result, JSObject::ObjectProtoToString(isolate, object)); |
| 2101 return *result; | 2095 return *result; |
| 2102 } | 2096 } |
| 2103 | 2097 |
| 2104 | 2098 |
| 2105 namespace { | |
| 2106 | |
| 2107 } // namespace | |
| 2108 | |
| 2109 | |
| 2110 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case. | 2099 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case. |
| 2111 BUILTIN(ProxyConstructor) { | 2100 BUILTIN(ProxyConstructor) { |
| 2112 HandleScope scope(isolate); | 2101 HandleScope scope(isolate); |
| 2113 THROW_NEW_ERROR_RETURN_FAILURE( | 2102 THROW_NEW_ERROR_RETURN_FAILURE( |
| 2114 isolate, | 2103 isolate, |
| 2115 NewTypeError(MessageTemplate::kConstructorNotFunction, | 2104 NewTypeError(MessageTemplate::kConstructorNotFunction, |
| 2116 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); | 2105 isolate->factory()->NewStringFromAsciiChecked("Proxy"))); |
| 2117 } | 2106 } |
| 2118 | 2107 |
| 2119 | 2108 |
| 2120 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. | 2109 // ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Construct]] case. |
| 2121 BUILTIN(ProxyConstructor_ConstructStub) { | 2110 BUILTIN(ProxyConstructor_ConstructStub) { |
| 2122 HandleScope scope(isolate); | 2111 HandleScope scope(isolate); |
| 2123 DCHECK(isolate->proxy_function()->IsConstructor()); | 2112 DCHECK(isolate->proxy_function()->IsConstructor()); |
| 2124 Handle<Object> target = args.atOrUndefined(isolate, 1); | 2113 Handle<Object> target = args.atOrUndefined(isolate, 1); |
| 2125 Handle<Object> handler = args.atOrUndefined(isolate, 2); | 2114 Handle<Object> handler = args.atOrUndefined(isolate, 2); |
| 2126 // The ConstructStub is executed in the context of the caller, so we need | |
| 2127 // to enter the callee context first before raising an exception. | |
| 2128 isolate->set_context(args.target()->context()); | |
| 2129 Handle<JSProxy> result; | 2115 Handle<JSProxy> result; |
| 2130 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, | 2116 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
| 2131 JSProxy::New(isolate, target, handler)); | 2117 JSProxy::New(isolate, target, handler)); |
| 2132 return *result; | 2118 return *result; |
| 2133 } | 2119 } |
| 2134 | 2120 |
| 2135 | 2121 |
| 2136 // ----------------------------------------------------------------------------- | 2122 // ----------------------------------------------------------------------------- |
| 2137 // Throwers for restricted function properties and strict arguments object | 2123 // Throwers for restricted function properties and strict arguments object |
| 2138 // properties | 2124 // properties |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2758 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 2744 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 2759 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2745 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 2760 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2746 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 2761 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2747 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 2762 #undef DEFINE_BUILTIN_ACCESSOR_C | 2748 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 2763 #undef DEFINE_BUILTIN_ACCESSOR_A | 2749 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 2764 | 2750 |
| 2765 | 2751 |
| 2766 } // namespace internal | 2752 } // namespace internal |
| 2767 } // namespace v8 | 2753 } // namespace v8 |
| OLD | NEW |