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/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 Loading... |
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. |
(...skipping 22 matching lines...) Expand all Loading... |
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 // Set up the prototoype using original function. |
| 1305 // TODO(dslomov): instead of setting the __proto__, |
| 1306 // use and cache the correct map. |
| 1307 if (*original_function != *function) { |
| 1308 if (original_function->has_instance_prototype()) { |
| 1309 Handle<Object> prototype = |
| 1310 handle(original_function->instance_prototype(), isolate); |
| 1311 RETURN_FAILURE_ON_EXCEPTION( |
| 1312 isolate, JSObject::SetPrototype(result, prototype, false)); |
| 1313 } |
| 1314 } |
| 1315 |
1303 isolate->counters()->constructed_objects()->Increment(); | 1316 isolate->counters()->constructed_objects()->Increment(); |
1304 isolate->counters()->constructed_objects_runtime()->Increment(); | 1317 isolate->counters()->constructed_objects_runtime()->Increment(); |
1305 | 1318 |
1306 return *result; | 1319 return *result; |
1307 } | 1320 } |
1308 | 1321 |
1309 | 1322 |
1310 RUNTIME_FUNCTION(Runtime_NewObject) { | 1323 RUNTIME_FUNCTION(Runtime_NewObject) { |
1311 HandleScope scope(isolate); | 1324 HandleScope scope(isolate); |
1312 DCHECK(args.length() == 2); | 1325 DCHECK(args.length() == 2); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 1611 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
1599 | 1612 |
1600 RETURN_FAILURE_ON_EXCEPTION( | 1613 RETURN_FAILURE_ON_EXCEPTION( |
1601 isolate, | 1614 isolate, |
1602 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), | 1615 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), |
1603 setter, attrs)); | 1616 setter, attrs)); |
1604 return isolate->heap()->undefined_value(); | 1617 return isolate->heap()->undefined_value(); |
1605 } | 1618 } |
1606 } | 1619 } |
1607 } // namespace v8::internal | 1620 } // namespace v8::internal |
OLD | NEW |