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

Side by Side Diff: src/runtime/runtime-function.cc

Issue 1217603005: [es6] Function bind should preserve [[Prototype]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Only transition map to prototype if the prototype is not already correct Created 5 years, 5 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 | « no previous file | test/mjsunit/function-bind.js » ('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 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/cpu-profiler.h" 10 #include "src/cpu-profiler.h"
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // Copy arguments, skipping the first which is "this_arg". 436 // Copy arguments, skipping the first which is "this_arg".
437 for (int j = 0; j < argc; j++, i++) { 437 for (int j = 0; j < argc; j++, i++) {
438 new_bindings->set(i, *arguments[j + 1]); 438 new_bindings->set(i, *arguments[j + 1]);
439 } 439 }
440 new_bindings->set_map_no_write_barrier(isolate->heap()->fixed_array_map()); 440 new_bindings->set_map_no_write_barrier(isolate->heap()->fixed_array_map());
441 bound_function->set_function_bindings(*new_bindings); 441 bound_function->set_function_bindings(*new_bindings);
442 442
443 // Update length. Have to remove the prototype first so that map migration 443 // Update length. Have to remove the prototype first so that map migration
444 // is happy about the number of fields. 444 // is happy about the number of fields.
445 RUNTIME_ASSERT(bound_function->RemovePrototype()); 445 RUNTIME_ASSERT(bound_function->RemovePrototype());
446
447 // The new function should have the same [[Prototype]] as the bindee.
446 Handle<Map> bound_function_map( 448 Handle<Map> bound_function_map(
447 isolate->native_context()->bound_function_map()); 449 isolate->native_context()->bound_function_map());
450 PrototypeIterator iter(isolate, bindee);
451 Handle<Object> proto = PrototypeIterator::GetCurrent(iter);
452 if (bound_function_map->prototype() != *proto) {
453 bound_function_map = Map::TransitionToPrototype(bound_function_map, proto,
454 REGULAR_PROTOTYPE);
455 }
448 JSObject::MigrateToMap(bound_function, bound_function_map); 456 JSObject::MigrateToMap(bound_function, bound_function_map);
457
449 Handle<String> length_string = isolate->factory()->length_string(); 458 Handle<String> length_string = isolate->factory()->length_string();
450 PropertyAttributes attr = 459 PropertyAttributes attr =
451 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); 460 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
452 RETURN_FAILURE_ON_EXCEPTION( 461 RETURN_FAILURE_ON_EXCEPTION(
453 isolate, JSObject::SetOwnPropertyIgnoreAttributes( 462 isolate, JSObject::SetOwnPropertyIgnoreAttributes(
454 bound_function, length_string, new_length, attr)); 463 bound_function, length_string, new_length, attr));
455 return *bound_function; 464 return *bound_function;
456 } 465 }
457 466
458 467
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 634
626 635
627 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { 636 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) {
628 HandleScope scope(isolate); 637 HandleScope scope(isolate);
629 DCHECK(args.length() == 0); 638 DCHECK(args.length() == 0);
630 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 639 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
631 NewTypeError(MessageTemplate::kStrongArity)); 640 NewTypeError(MessageTemplate::kStrongArity));
632 } 641 }
633 } // namespace internal 642 } // namespace internal
634 } // namespace v8 643 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/function-bind.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698