| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 Handle<Object> val = Handle<Object>(frame->GetParameter(i), isolate); | 383 Handle<Object> val = Handle<Object>(frame->GetParameter(i), isolate); |
| 384 param_data[prefix_argc + i] = val; | 384 param_data[prefix_argc + i] = val; |
| 385 } | 385 } |
| 386 return param_data; | 386 return param_data; |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 | 390 |
| 391 RUNTIME_FUNCTION(Runtime_FunctionBindArguments) { | 391 RUNTIME_FUNCTION(Runtime_FunctionBindArguments) { |
| 392 HandleScope scope(isolate); | 392 HandleScope scope(isolate); |
| 393 DCHECK(args.length() == 4); | 393 DCHECK(args.length() == 5); |
| 394 CONVERT_ARG_HANDLE_CHECKED(JSFunction, bound_function, 0); | 394 CONVERT_ARG_HANDLE_CHECKED(JSFunction, bound_function, 0); |
| 395 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, bindee, 1); | 395 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, bindee, 1); |
| 396 CONVERT_ARG_HANDLE_CHECKED(Object, this_object, 2); | 396 CONVERT_ARG_HANDLE_CHECKED(Object, this_object, 2); |
| 397 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3); | 397 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3); |
| 398 CONVERT_ARG_HANDLE_CHECKED(Object, proto, 4); |
| 398 | 399 |
| 399 // TODO(lrn): Create bound function in C++ code from premade shared info. | 400 // TODO(lrn): Create bound function in C++ code from premade shared info. |
| 400 bound_function->shared()->set_bound(true); | 401 bound_function->shared()->set_bound(true); |
| 401 bound_function->shared()->set_optimized_code_map( | 402 bound_function->shared()->set_optimized_code_map( |
| 402 isolate->heap()->cleared_optimized_code_map()); | 403 isolate->heap()->cleared_optimized_code_map()); |
| 403 bound_function->shared()->set_inferred_name(isolate->heap()->empty_string()); | 404 bound_function->shared()->set_inferred_name(isolate->heap()->empty_string()); |
| 404 bound_function->shared()->set_construct_stub( | 405 bound_function->shared()->set_construct_stub( |
| 405 *isolate->builtins()->JSBuiltinsConstructStub()); | 406 *isolate->builtins()->JSBuiltinsConstructStub()); |
| 406 // Get all arguments of calling function (Function.prototype.bind). | 407 // Get all arguments of calling function (Function.prototype.bind). |
| 407 int argc = 0; | 408 int argc = 0; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 for (int j = 0; j < argc; j++, out_index++) { | 440 for (int j = 0; j < argc; j++, out_index++) { |
| 440 new_bindings->set_binding(out_index, *arguments[j + 1]); | 441 new_bindings->set_binding(out_index, *arguments[j + 1]); |
| 441 } | 442 } |
| 442 new_bindings->set_map_no_write_barrier(isolate->heap()->fixed_array_map()); | 443 new_bindings->set_map_no_write_barrier(isolate->heap()->fixed_array_map()); |
| 443 bound_function->set_function_bindings(*new_bindings); | 444 bound_function->set_function_bindings(*new_bindings); |
| 444 | 445 |
| 445 // Update length. Have to remove the prototype first so that map migration | 446 // Update length. Have to remove the prototype first so that map migration |
| 446 // is happy about the number of fields. | 447 // is happy about the number of fields. |
| 447 RUNTIME_ASSERT(bound_function->RemovePrototype()); | 448 RUNTIME_ASSERT(bound_function->RemovePrototype()); |
| 448 | 449 |
| 449 // The new function should have the same [[Prototype]] as the bindee. | 450 // The new function should have the given prototype. |
| 450 Handle<Map> bound_function_map = | 451 Handle<Map> bound_function_map = |
| 451 bindee->IsConstructor() | 452 bindee->IsConstructor() |
| 452 ? isolate->bound_function_with_constructor_map() | 453 ? isolate->bound_function_with_constructor_map() |
| 453 : isolate->bound_function_without_constructor_map(); | 454 : isolate->bound_function_without_constructor_map(); |
| 454 PrototypeIterator iter(isolate, bindee); | |
| 455 Handle<Object> proto = PrototypeIterator::GetCurrent(iter); | |
| 456 if (bound_function_map->prototype() != *proto) { | 455 if (bound_function_map->prototype() != *proto) { |
| 457 bound_function_map = Map::TransitionToPrototype(bound_function_map, proto, | 456 bound_function_map = Map::TransitionToPrototype(bound_function_map, proto, |
| 458 REGULAR_PROTOTYPE); | 457 REGULAR_PROTOTYPE); |
| 459 } | 458 } |
| 460 JSObject::MigrateToMap(bound_function, bound_function_map); | 459 JSObject::MigrateToMap(bound_function, bound_function_map); |
| 461 DCHECK_EQ(bindee->IsConstructor(), bound_function->IsConstructor()); | 460 DCHECK_EQ(bindee->IsConstructor(), bound_function->IsConstructor()); |
| 462 | 461 |
| 463 Handle<String> length_string = isolate->factory()->length_string(); | 462 Handle<String> length_string = isolate->factory()->length_string(); |
| 464 // These attributes must be kept in sync with how the bootstrapper | 463 // These attributes must be kept in sync with how the bootstrapper |
| 465 // configures the bound_function_map retrieved above. | 464 // configures the bound_function_map retrieved above. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 614 |
| 616 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { | 615 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { |
| 617 HandleScope scope(isolate); | 616 HandleScope scope(isolate); |
| 618 DCHECK(args.length() == 0); | 617 DCHECK(args.length() == 0); |
| 619 THROW_NEW_ERROR_RETURN_FAILURE(isolate, | 618 THROW_NEW_ERROR_RETURN_FAILURE(isolate, |
| 620 NewTypeError(MessageTemplate::kStrongArity)); | 619 NewTypeError(MessageTemplate::kStrongArity)); |
| 621 } | 620 } |
| 622 | 621 |
| 623 } // namespace internal | 622 } // namespace internal |
| 624 } // namespace v8 | 623 } // namespace v8 |
| OLD | NEW |