Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: src/builtins.cc

Issue 2044113002: Turn Function.prototype.bind into a hydrogen stub optimized for the common case (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Ports Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
Igor Sheludko 2016/06/07 16:24:34 Please fix comment wrapping.
4335 // tailcall to the builtin directly.
4336 RUNTIME_FUNCTION(Runtime_FunctionBind) {
4337 DCHECK_EQ(2, args.length());
4338 Arguments* incoming = reinterpret_cast<Arguments*>(args[0]);
4339 // Rewrap the arguments as builtins arguments.
4340 BuiltinArguments<BuiltinExtraArguments::kNone> caller_args(
4341 incoming->length() + 1, incoming->arguments() + 1);
4342 return DoFunctionBind(isolate, caller_args);
4343 }
4344
4327 // ES6 section 19.2.3.5 Function.prototype.toString ( ) 4345 // ES6 section 19.2.3.5 Function.prototype.toString ( )
4328 BUILTIN(FunctionPrototypeToString) { 4346 BUILTIN(FunctionPrototypeToString) {
4329 HandleScope scope(isolate); 4347 HandleScope scope(isolate);
4330 Handle<Object> receiver = args.receiver(); 4348 Handle<Object> receiver = args.receiver();
4331 if (receiver->IsJSBoundFunction()) { 4349 if (receiver->IsJSBoundFunction()) {
4332 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver)); 4350 return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver));
4333 } else if (receiver->IsJSFunction()) { 4351 } else if (receiver->IsJSFunction()) {
4334 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver)); 4352 return *JSFunction::ToString(Handle<JSFunction>::cast(receiver));
4335 } 4353 }
4336 THROW_NEW_ERROR_RETURN_FAILURE( 4354 THROW_NEW_ERROR_RETURN_FAILURE(
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
5807 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 5825 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
5808 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 5826 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
5809 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 5827 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
5810 #undef DEFINE_BUILTIN_ACCESSOR_C 5828 #undef DEFINE_BUILTIN_ACCESSOR_C
5811 #undef DEFINE_BUILTIN_ACCESSOR_A 5829 #undef DEFINE_BUILTIN_ACCESSOR_A
5812 #undef DEFINE_BUILTIN_ACCESSOR_T 5830 #undef DEFINE_BUILTIN_ACCESSOR_T
5813 #undef DEFINE_BUILTIN_ACCESSOR_H 5831 #undef DEFINE_BUILTIN_ACCESSOR_H
5814 5832
5815 } // namespace internal 5833 } // namespace internal
5816 } // namespace v8 5834 } // namespace v8
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698