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-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 4220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4231 | 4231 |
4232 // ES6 section 19.2.1.1 Function ( p1, p2, ... , pn, body ) | 4232 // ES6 section 19.2.1.1 Function ( p1, p2, ... , pn, body ) |
4233 BUILTIN(FunctionConstructor) { | 4233 BUILTIN(FunctionConstructor) { |
4234 HandleScope scope(isolate); | 4234 HandleScope scope(isolate); |
4235 Handle<JSFunction> result; | 4235 Handle<JSFunction> result; |
4236 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4236 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
4237 isolate, result, CreateDynamicFunction(isolate, args, "function")); | 4237 isolate, result, CreateDynamicFunction(isolate, args, "function")); |
4238 return *result; | 4238 return *result; |
4239 } | 4239 } |
4240 | 4240 |
| 4241 namespace { |
4241 | 4242 |
4242 // ES6 section 19.2.3.2 Function.prototype.bind ( thisArg, ...args ) | 4243 Object* DoFunctionBind(Isolate* isolate, |
4243 BUILTIN(FunctionPrototypeBind) { | 4244 BuiltinArguments<BuiltinExtraArguments::kNone> args) { |
4244 HandleScope scope(isolate); | 4245 HandleScope scope(isolate); |
4245 DCHECK_LE(1, args.length()); | 4246 DCHECK_LE(1, args.length()); |
4246 if (!args.receiver()->IsCallable()) { | 4247 if (!args.receiver()->IsCallable()) { |
4247 THROW_NEW_ERROR_RETURN_FAILURE( | 4248 THROW_NEW_ERROR_RETURN_FAILURE( |
4248 isolate, NewTypeError(MessageTemplate::kFunctionBind)); | 4249 isolate, NewTypeError(MessageTemplate::kFunctionBind)); |
4249 } | 4250 } |
4250 | 4251 |
4251 // Allocate the bound function with the given {this_arg} and {args}. | 4252 // Allocate the bound function with the given {this_arg} and {args}. |
4252 Handle<JSReceiver> target = args.at<JSReceiver>(0); | 4253 Handle<JSReceiver> target = args.at<JSReceiver>(0); |
4253 Handle<Object> this_arg = isolate->factory()->undefined_value(); | 4254 Handle<Object> this_arg = isolate->factory()->undefined_value(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4317 } | 4318 } |
4318 LookupIterator it(function, isolate->factory()->name_string()); | 4319 LookupIterator it(function, isolate->factory()->name_string()); |
4319 DCHECK_EQ(LookupIterator::ACCESSOR, it.state()); | 4320 DCHECK_EQ(LookupIterator::ACCESSOR, it.state()); |
4320 RETURN_FAILURE_ON_EXCEPTION(isolate, | 4321 RETURN_FAILURE_ON_EXCEPTION(isolate, |
4321 JSObject::DefineOwnPropertyIgnoreAttributes( | 4322 JSObject::DefineOwnPropertyIgnoreAttributes( |
4322 &it, name, it.property_attributes())); | 4323 &it, name, it.property_attributes())); |
4323 } | 4324 } |
4324 return *function; | 4325 return *function; |
4325 } | 4326 } |
4326 | 4327 |
| 4328 } // namespace |
| 4329 |
| 4330 // ES6 section 19.2.3.2 Function.prototype.bind ( thisArg, ...args ) |
| 4331 BUILTIN(FunctionPrototypeBind) { return DoFunctionBind(isolate, args); } |
| 4332 |
| 4333 // TODO(verwaest): This is a temporary helper until the FastFunctionBind stub |
| 4334 // can tailcall to the builtin directly. |
| 4335 RUNTIME_FUNCTION(Runtime_FunctionBind) { |
| 4336 DCHECK_EQ(2, args.length()); |
| 4337 Arguments* incoming = reinterpret_cast<Arguments*>(args[0]); |
| 4338 // Rewrap the arguments as builtins arguments. |
| 4339 BuiltinArguments<BuiltinExtraArguments::kNone> caller_args( |
| 4340 incoming->length() + 1, incoming->arguments() + 1); |
| 4341 return DoFunctionBind(isolate, caller_args); |
| 4342 } |
| 4343 |
4327 // ES6 section 19.2.3.5 Function.prototype.toString ( ) | 4344 // ES6 section 19.2.3.5 Function.prototype.toString ( ) |
4328 BUILTIN(FunctionPrototypeToString) { | 4345 BUILTIN(FunctionPrototypeToString) { |
4329 HandleScope scope(isolate); | 4346 HandleScope scope(isolate); |
4330 Handle<Object> receiver = args.receiver(); | 4347 Handle<Object> receiver = args.receiver(); |
4331 if (receiver->IsJSBoundFunction()) { | 4348 if (receiver->IsJSBoundFunction()) { |
4332 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver)); | 4349 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver)); |
4333 } else if (receiver->IsJSFunction()) { | 4350 } else if (receiver->IsJSFunction()) { |
4334 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver)); | 4351 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver)); |
4335 } | 4352 } |
4336 THROW_NEW_ERROR_RETURN_FAILURE( | 4353 THROW_NEW_ERROR_RETURN_FAILURE( |
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5807 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5824 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5808 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5825 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5809 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5826 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5810 #undef DEFINE_BUILTIN_ACCESSOR_C | 5827 #undef DEFINE_BUILTIN_ACCESSOR_C |
5811 #undef DEFINE_BUILTIN_ACCESSOR_A | 5828 #undef DEFINE_BUILTIN_ACCESSOR_A |
5812 #undef DEFINE_BUILTIN_ACCESSOR_T | 5829 #undef DEFINE_BUILTIN_ACCESSOR_T |
5813 #undef DEFINE_BUILTIN_ACCESSOR_H | 5830 #undef DEFINE_BUILTIN_ACCESSOR_H |
5814 | 5831 |
5815 } // namespace internal | 5832 } // namespace internal |
5816 } // namespace v8 | 5833 } // namespace v8 |
OLD | NEW |