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/v8.h" | 5 #include "src/v8.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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 int array_size = JSFunction::kBoundArgumentsStartIndex + argc; | 428 int array_size = JSFunction::kBoundArgumentsStartIndex + argc; |
429 new_bindings = isolate->factory()->NewFixedArray(array_size); | 429 new_bindings = isolate->factory()->NewFixedArray(array_size); |
430 new_bindings->set(JSFunction::kBoundFunctionIndex, *bindee); | 430 new_bindings->set(JSFunction::kBoundFunctionIndex, *bindee); |
431 new_bindings->set(JSFunction::kBoundThisIndex, *this_object); | 431 new_bindings->set(JSFunction::kBoundThisIndex, *this_object); |
432 i = 2; | 432 i = 2; |
433 } | 433 } |
434 // Copy arguments, skipping the first which is "this_arg". | 434 // Copy arguments, skipping the first which is "this_arg". |
435 for (int j = 0; j < argc; j++, i++) { | 435 for (int j = 0; j < argc; j++, i++) { |
436 new_bindings->set(i, *arguments[j + 1]); | 436 new_bindings->set(i, *arguments[j + 1]); |
437 } | 437 } |
438 new_bindings->set_map_no_write_barrier( | 438 new_bindings->set_map_no_write_barrier(isolate->heap()->fixed_array_map()); |
439 isolate->heap()->fixed_cow_array_map()); | |
440 bound_function->set_function_bindings(*new_bindings); | 439 bound_function->set_function_bindings(*new_bindings); |
441 | 440 |
442 // Update length. Have to remove the prototype first so that map migration | 441 // Update length. Have to remove the prototype first so that map migration |
443 // is happy about the number of fields. | 442 // is happy about the number of fields. |
444 RUNTIME_ASSERT(bound_function->RemovePrototype()); | 443 RUNTIME_ASSERT(bound_function->RemovePrototype()); |
445 Handle<Map> bound_function_map( | 444 Handle<Map> bound_function_map( |
446 isolate->native_context()->bound_function_map()); | 445 isolate->native_context()->bound_function_map()); |
447 JSObject::MigrateToMap(bound_function, bound_function_map); | 446 JSObject::MigrateToMap(bound_function, bound_function_map); |
448 Handle<String> length_string = isolate->factory()->length_string(); | 447 Handle<String> length_string = isolate->factory()->length_string(); |
449 PropertyAttributes attr = | 448 PropertyAttributes attr = |
450 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY); | 449 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY); |
451 RETURN_FAILURE_ON_EXCEPTION( | 450 RETURN_FAILURE_ON_EXCEPTION( |
452 isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 451 isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
453 bound_function, length_string, new_length, attr)); | 452 bound_function, length_string, new_length, attr)); |
454 return *bound_function; | 453 return *bound_function; |
455 } | 454 } |
456 | 455 |
457 | 456 |
458 RUNTIME_FUNCTION(Runtime_BoundFunctionGetBindings) { | 457 RUNTIME_FUNCTION(Runtime_BoundFunctionGetBindings) { |
459 HandleScope handles(isolate); | 458 HandleScope handles(isolate); |
460 DCHECK(args.length() == 1); | 459 DCHECK(args.length() == 1); |
461 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, callable, 0); | 460 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, callable, 0); |
462 if (callable->IsJSFunction()) { | 461 if (callable->IsJSFunction()) { |
463 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); | 462 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); |
464 if (function->shared()->bound()) { | 463 if (function->shared()->bound()) { |
| 464 RUNTIME_ASSERT(function->function_bindings()->IsFixedArray()); |
465 Handle<FixedArray> bindings(function->function_bindings()); | 465 Handle<FixedArray> bindings(function->function_bindings()); |
466 RUNTIME_ASSERT(bindings->map() == isolate->heap()->fixed_cow_array_map()); | |
467 return *isolate->factory()->NewJSArrayWithElements(bindings); | 466 return *isolate->factory()->NewJSArrayWithElements(bindings); |
468 } | 467 } |
469 } | 468 } |
470 return isolate->heap()->undefined_value(); | 469 return isolate->heap()->undefined_value(); |
471 } | 470 } |
472 | 471 |
473 | 472 |
474 RUNTIME_FUNCTION(Runtime_NewObjectFromBound) { | 473 RUNTIME_FUNCTION(Runtime_NewObjectFromBound) { |
475 HandleScope scope(isolate); | 474 HandleScope scope(isolate); |
476 DCHECK(args.length() == 1); | 475 DCHECK(args.length() == 1); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 615 |
617 | 616 |
618 RUNTIME_FUNCTION(RuntimeReference_IsFunction) { | 617 RUNTIME_FUNCTION(RuntimeReference_IsFunction) { |
619 SealHandleScope shs(isolate); | 618 SealHandleScope shs(isolate); |
620 DCHECK(args.length() == 1); | 619 DCHECK(args.length() == 1); |
621 CONVERT_ARG_CHECKED(Object, obj, 0); | 620 CONVERT_ARG_CHECKED(Object, obj, 0); |
622 return isolate->heap()->ToBoolean(obj->IsJSFunction()); | 621 return isolate->heap()->ToBoolean(obj->IsJSFunction()); |
623 } | 622 } |
624 } | 623 } |
625 } // namespace v8::internal | 624 } // namespace v8::internal |
OLD | NEW |