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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/function-bind.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-function.cc
diff --git a/src/runtime/runtime-function.cc b/src/runtime/runtime-function.cc
index d644d37e42b2fff45685eb2c7604c5c68c801a3d..c58b01c27050cacad5181aca14ddf6e9edd0f7fc 100644
--- a/src/runtime/runtime-function.cc
+++ b/src/runtime/runtime-function.cc
@@ -443,9 +443,18 @@ RUNTIME_FUNCTION(Runtime_FunctionBindArguments) {
// Update length. Have to remove the prototype first so that map migration
// is happy about the number of fields.
RUNTIME_ASSERT(bound_function->RemovePrototype());
+
+ // The new function should have the same [[Prototype]] as the bindee.
Handle<Map> bound_function_map(
isolate->native_context()->bound_function_map());
+ PrototypeIterator iter(isolate, bindee);
+ Handle<Object> proto = PrototypeIterator::GetCurrent(iter);
+ if (bound_function_map->prototype() != *proto) {
+ bound_function_map = Map::TransitionToPrototype(bound_function_map, proto,
+ REGULAR_PROTOTYPE);
+ }
JSObject::MigrateToMap(bound_function, bound_function_map);
+
Handle<String> length_string = isolate->factory()->length_string();
PropertyAttributes attr =
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
« 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