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

Side by Side 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 subclassing 'null' 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 unified diff | Download patch
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/arguments.h" 7 #include "src/arguments.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/debug.h" 9 #include "src/debug.h"
10 #include "src/runtime/runtime.h" 10 #include "src/runtime/runtime.h"
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 HandleScope scope(isolate); 1238 HandleScope scope(isolate);
1239 DCHECK(args.length() == 0); 1239 DCHECK(args.length() == 0);
1240 return *isolate->factory()->NewHeapNumber(0); 1240 return *isolate->factory()->NewHeapNumber(0);
1241 } 1241 }
1242 1242
1243 1243
1244 static Object* Runtime_NewObjectHelper(Isolate* isolate, 1244 static Object* Runtime_NewObjectHelper(Isolate* isolate,
1245 Handle<Object> constructor, 1245 Handle<Object> constructor,
1246 Handle<Object> original_constructor, 1246 Handle<Object> original_constructor,
1247 Handle<AllocationSite> site) { 1247 Handle<AllocationSite> site) {
1248 // TODO(dslomov): implement prototype rewiring.
1249 // The check below is a sanity check.
1250 CHECK(*constructor == *original_constructor);
1251
1252 // If the constructor isn't a proper function we throw a type error. 1248 // If the constructor isn't a proper function we throw a type error.
1253 if (!constructor->IsJSFunction()) { 1249 if (!constructor->IsJSFunction()) {
1254 Vector<Handle<Object> > arguments = HandleVector(&constructor, 1); 1250 Vector<Handle<Object> > arguments = HandleVector(&constructor, 1);
1255 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 1251 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
1256 NewTypeError("not_constructor", arguments)); 1252 NewTypeError("not_constructor", arguments));
1257 } 1253 }
1258 1254
1259 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor); 1255 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor);
1260 1256
1257 CHECK(original_constructor->IsJSFunction());
1258 Handle<JSFunction> original_function =
1259 Handle<JSFunction>::cast(original_constructor);
1260
1261
1261 // If function should not have prototype, construction is not allowed. In this 1262 // If function should not have prototype, construction is not allowed. In this
1262 // case generated code bailouts here, since function has no initial_map. 1263 // case generated code: bailouts here, since function has no initial_map.
1263 if (!function->should_have_prototype() && !function->shared()->bound()) { 1264 if (!function->should_have_prototype() && !function->shared()->bound()) {
1264 Vector<Handle<Object> > arguments = HandleVector(&constructor, 1); 1265 Vector<Handle<Object> > arguments = HandleVector(&constructor, 1);
1265 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 1266 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
1266 NewTypeError("not_constructor", arguments)); 1267 NewTypeError("not_constructor", arguments));
1267 } 1268 }
1268 1269
1269 Debug* debug = isolate->debug(); 1270 Debug* debug = isolate->debug();
1270 // Handle stepping into constructors if step into is active. 1271 // Handle stepping into constructors if step into is active.
1271 if (debug->StepInActive()) { 1272 if (debug->StepInActive()) {
1272 debug->HandleStepIn(function, Handle<Object>::null(), 0, true); 1273 debug->HandleStepIn(function, Handle<Object>::null(), 0, true);
(...skipping 20 matching lines...) Expand all
1293 // available. 1294 // available.
1294 Compiler::EnsureCompiled(function, CLEAR_EXCEPTION); 1295 Compiler::EnsureCompiled(function, CLEAR_EXCEPTION);
1295 1296
1296 Handle<JSObject> result; 1297 Handle<JSObject> result;
1297 if (site.is_null()) { 1298 if (site.is_null()) {
1298 result = isolate->factory()->NewJSObject(function); 1299 result = isolate->factory()->NewJSObject(function);
1299 } else { 1300 } else {
1300 result = isolate->factory()->NewJSObjectWithMemento(function, site); 1301 result = isolate->factory()->NewJSObjectWithMemento(function, site);
1301 } 1302 }
1302 1303
1304 if (*original_function != *function) {
arv (Not doing code reviews) 2015/02/09 17:44:39 Is this is to set up the prototype from the NewTar
Dmitry Lomov (no reviews) 2015/02/10 19:22:15 Done.
1305 if (original_function->has_instance_prototype()) {
1306 Handle<Object> prototype =
1307 handle(original_function->instance_prototype(), isolate);
1308 RETURN_FAILURE_ON_EXCEPTION(
1309 isolate, JSObject::SetPrototype(result, prototype, false));
1310 }
1311 }
1312
1303 isolate->counters()->constructed_objects()->Increment(); 1313 isolate->counters()->constructed_objects()->Increment();
1304 isolate->counters()->constructed_objects_runtime()->Increment(); 1314 isolate->counters()->constructed_objects_runtime()->Increment();
1305 1315
1306 return *result; 1316 return *result;
1307 } 1317 }
1308 1318
1309 1319
1310 RUNTIME_FUNCTION(Runtime_NewObject) { 1320 RUNTIME_FUNCTION(Runtime_NewObject) {
1311 HandleScope scope(isolate); 1321 HandleScope scope(isolate);
1312 DCHECK(args.length() == 2); 1322 DCHECK(args.length() == 2);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); 1608 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
1599 1609
1600 RETURN_FAILURE_ON_EXCEPTION( 1610 RETURN_FAILURE_ON_EXCEPTION(
1601 isolate, 1611 isolate,
1602 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), 1612 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(),
1603 setter, attrs)); 1613 setter, attrs));
1604 return isolate->heap()->undefined_value(); 1614 return isolate->heap()->undefined_value();
1605 } 1615 }
1606 } 1616 }
1607 } // namespace v8::internal 1617 } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698