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/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 bool read_only_prototype, | 1291 bool read_only_prototype, |
1292 bool install_constructor, | 1292 bool install_constructor, |
1293 bool is_strict) { | 1293 bool is_strict) { |
1294 // Allocate the function | 1294 // Allocate the function |
1295 Handle<JSFunction> function = | 1295 Handle<JSFunction> function = |
1296 NewFunction(name, code, prototype, read_only_prototype, is_strict); | 1296 NewFunction(name, code, prototype, read_only_prototype, is_strict); |
1297 | 1297 |
1298 ElementsKind elements_kind = | 1298 ElementsKind elements_kind = |
1299 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; | 1299 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; |
1300 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); | 1300 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); |
1301 // TODO(littledan): Why do we have this is_generator test when | |
1302 // NewFunctionPrototype already handles finding an appropriately | |
1303 // shared prototype? | |
1301 if (!function->shared()->is_generator()) { | 1304 if (!function->shared()->is_generator()) { |
1302 if (prototype->IsTheHole()) { | 1305 if (prototype->IsTheHole()) { |
1303 prototype = NewFunctionPrototype(function); | 1306 prototype = NewFunctionPrototype(function); |
1304 } else if (install_constructor) { | 1307 } else if (install_constructor) { |
1305 JSObject::AddProperty(Handle<JSObject>::cast(prototype), | 1308 JSObject::AddProperty(Handle<JSObject>::cast(prototype), |
1306 constructor_string(), function, DONT_ENUM); | 1309 constructor_string(), function, DONT_ENUM); |
1307 } | 1310 } |
1308 } | 1311 } |
1309 | 1312 |
1310 JSFunction::SetInitialMap(function, initial_map, | 1313 JSFunction::SetInitialMap(function, initial_map, |
1311 Handle<JSReceiver>::cast(prototype)); | 1314 Handle<JSReceiver>::cast(prototype)); |
1312 | 1315 |
1313 return function; | 1316 return function; |
1314 } | 1317 } |
1315 | 1318 |
1316 | 1319 |
1317 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1320 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
1318 Handle<Code> code, | 1321 Handle<Code> code, |
1319 InstanceType type, | 1322 InstanceType type, |
1320 int instance_size) { | 1323 int instance_size) { |
1321 return NewFunction(name, code, the_hole_value(), type, instance_size); | 1324 return NewFunction(name, code, the_hole_value(), type, instance_size); |
1322 } | 1325 } |
1323 | 1326 |
1324 | 1327 |
1325 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { | 1328 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
1326 // Make sure to use globals from the function's context, since the function | 1329 // Make sure to use globals from the function's context, since the function |
1327 // can be from a different context. | 1330 // can be from a different context. |
1328 Handle<Context> native_context(function->context()->native_context()); | 1331 Handle<Context> native_context(function->context()->native_context()); |
1329 Handle<Map> new_map; | 1332 Handle<Map> new_map; |
1330 if (function->shared()->is_generator()) { | 1333 if (function->shared()->is_resumable()) { |
caitp (gmail)
2016/05/20 13:35:56
Based on how generator_object_prototype_map is cre
Dan Ehrenberg
2016/05/20 14:59:19
Oh you're right, oops. The new patch asserts that
| |
1331 // Generator prototypes can share maps since they don't have "constructor" | 1334 // Generator and async function prototypes can share maps since they don't |
1332 // properties. | 1335 // have "constructor" properties. |
1333 new_map = handle(native_context->generator_object_prototype_map()); | 1336 new_map = handle(native_context->generator_object_prototype_map()); |
1334 } else { | 1337 } else { |
1335 // Each function prototype gets a fresh map to avoid unwanted sharing of | 1338 // Each function prototype gets a fresh map to avoid unwanted sharing of |
1336 // maps between prototypes of different constructors. | 1339 // maps between prototypes of different constructors. |
1337 Handle<JSFunction> object_function(native_context->object_function()); | 1340 Handle<JSFunction> object_function(native_context->object_function()); |
1338 DCHECK(object_function->has_initial_map()); | 1341 DCHECK(object_function->has_initial_map()); |
1339 new_map = handle(object_function->initial_map()); | 1342 new_map = handle(object_function->initial_map()); |
1340 } | 1343 } |
1341 | 1344 |
1342 DCHECK(!new_map->is_prototype_map()); | 1345 DCHECK(!new_map->is_prototype_map()); |
1343 Handle<JSObject> prototype = NewJSObjectFromMap(new_map); | 1346 Handle<JSObject> prototype = NewJSObjectFromMap(new_map); |
1344 | 1347 |
1345 if (!function->shared()->is_generator()) { | 1348 if (!function->shared()->is_resumable()) { |
1346 JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM); | 1349 JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM); |
1347 } | 1350 } |
1348 | 1351 |
1349 return prototype; | 1352 return prototype; |
1350 } | 1353 } |
1351 | 1354 |
1352 | 1355 |
1353 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( | 1356 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
1354 Handle<SharedFunctionInfo> info, | 1357 Handle<SharedFunctionInfo> info, |
1355 Handle<Context> context, | 1358 Handle<Context> context, |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1669 } | 1672 } |
1670 } | 1673 } |
1671 | 1674 |
1672 array->set_elements(*elms); | 1675 array->set_elements(*elms); |
1673 array->set_length(Smi::FromInt(length)); | 1676 array->set_length(Smi::FromInt(length)); |
1674 } | 1677 } |
1675 | 1678 |
1676 | 1679 |
1677 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( | 1680 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( |
1678 Handle<JSFunction> function) { | 1681 Handle<JSFunction> function) { |
1679 DCHECK(function->shared()->is_resumable()); | 1682 DCHECK(function->shared()->is_generator()); |
1680 JSFunction::EnsureHasInitialMap(function); | 1683 JSFunction::EnsureHasInitialMap(function); |
1681 Handle<Map> map(function->initial_map()); | 1684 Handle<Map> map(function->initial_map()); |
1682 DCHECK_EQ(JS_GENERATOR_OBJECT_TYPE, map->instance_type()); | 1685 DCHECK_EQ(JS_GENERATOR_OBJECT_TYPE, map->instance_type()); |
1683 CALL_HEAP_FUNCTION( | 1686 CALL_HEAP_FUNCTION( |
1684 isolate(), | 1687 isolate(), |
1685 isolate()->heap()->AllocateJSObjectFromMap(*map), | 1688 isolate()->heap()->AllocateJSObjectFromMap(*map), |
1686 JSGeneratorObject); | 1689 JSGeneratorObject); |
1687 } | 1690 } |
1688 | 1691 |
1689 | 1692 |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2392 } | 2395 } |
2393 | 2396 |
2394 | 2397 |
2395 Handle<Object> Factory::ToBoolean(bool value) { | 2398 Handle<Object> Factory::ToBoolean(bool value) { |
2396 return value ? true_value() : false_value(); | 2399 return value ? true_value() : false_value(); |
2397 } | 2400 } |
2398 | 2401 |
2399 | 2402 |
2400 } // namespace internal | 2403 } // namespace internal |
2401 } // namespace v8 | 2404 } // namespace v8 |
OLD | NEW |