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

Unified Diff: src/runtime/runtime-object.cc

Issue 908883002: new classes: implement new.target passing to superclass constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix x64 arithmetic Created 5 years, 10 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 | « src/runtime/runtime-function.cc ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-object.cc
diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc
index bde3021df16653280c3576aa15552c39764d6bda..844c633bdb82d6438ac4a830be021251007b814c 100644
--- a/src/runtime/runtime-object.cc
+++ b/src/runtime/runtime-object.cc
@@ -1245,10 +1245,6 @@ static Object* Runtime_NewObjectHelper(Isolate* isolate,
Handle<Object> constructor,
Handle<Object> original_constructor,
Handle<AllocationSite> site) {
- // TODO(dslomov): implement prototype rewiring.
- // The check below is a sanity check.
- CHECK(*constructor == *original_constructor);
-
// If the constructor isn't a proper function we throw a type error.
if (!constructor->IsJSFunction()) {
Vector<Handle<Object> > arguments = HandleVector(&constructor, 1);
@@ -1258,6 +1254,11 @@ static Object* Runtime_NewObjectHelper(Isolate* isolate,
Handle<JSFunction> function = Handle<JSFunction>::cast(constructor);
+ CHECK(original_constructor->IsJSFunction());
+ Handle<JSFunction> original_function =
+ Handle<JSFunction>::cast(original_constructor);
+
+
// If function should not have prototype, construction is not allowed. In this
// case generated code bailouts here, since function has no initial_map.
if (!function->should_have_prototype() && !function->shared()->bound()) {
@@ -1300,6 +1301,18 @@ static Object* Runtime_NewObjectHelper(Isolate* isolate,
result = isolate->factory()->NewJSObjectWithMemento(function, site);
}
+ // Set up the prototoype using original function.
+ // TODO(dslomov): instead of setting the __proto__,
+ // use and cache the correct map.
+ if (*original_function != *function) {
+ if (original_function->has_instance_prototype()) {
+ Handle<Object> prototype =
+ handle(original_function->instance_prototype(), isolate);
+ RETURN_FAILURE_ON_EXCEPTION(
+ isolate, JSObject::SetPrototype(result, prototype, false));
+ }
+ }
+
isolate->counters()->constructed_objects()->Increment();
isolate->counters()->constructed_objects_runtime()->Increment();
« no previous file with comments | « src/runtime/runtime-function.cc ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698