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 if (!function->shared()->is_generator()) { | 1301 // TODO(littledan): Why do we have this is_generator test when |
| 1302 // NewFunctionPrototype already handles finding an appropriately |
| 1303 // shared prototype? |
| 1304 if (!function->shared()->is_resumable()) { |
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()) { |
1331 // Generator prototypes can share maps since they don't have "constructor" | 1334 // Generator and async function prototypes can share maps since they |
1332 // properties. | 1335 // don't 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 { |
| 1338 CHECK(!function->shared()->is_async()); |
1335 // Each function prototype gets a fresh map to avoid unwanted sharing of | 1339 // Each function prototype gets a fresh map to avoid unwanted sharing of |
1336 // maps between prototypes of different constructors. | 1340 // maps between prototypes of different constructors. |
1337 Handle<JSFunction> object_function(native_context->object_function()); | 1341 Handle<JSFunction> object_function(native_context->object_function()); |
1338 DCHECK(object_function->has_initial_map()); | 1342 DCHECK(object_function->has_initial_map()); |
1339 new_map = handle(object_function->initial_map()); | 1343 new_map = handle(object_function->initial_map()); |
1340 } | 1344 } |
1341 | 1345 |
1342 DCHECK(!new_map->is_prototype_map()); | 1346 DCHECK(!new_map->is_prototype_map()); |
1343 Handle<JSObject> prototype = NewJSObjectFromMap(new_map); | 1347 Handle<JSObject> prototype = NewJSObjectFromMap(new_map); |
1344 | 1348 |
1345 if (!function->shared()->is_generator()) { | 1349 if (!function->shared()->is_resumable()) { |
1346 JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM); | 1350 JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM); |
1347 } | 1351 } |
1348 | 1352 |
1349 return prototype; | 1353 return prototype; |
1350 } | 1354 } |
1351 | 1355 |
1352 | 1356 |
1353 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( | 1357 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
1354 Handle<SharedFunctionInfo> info, | 1358 Handle<SharedFunctionInfo> info, |
1355 Handle<Context> context, | 1359 Handle<Context> context, |
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2390 } | 2394 } |
2391 | 2395 |
2392 | 2396 |
2393 Handle<Object> Factory::ToBoolean(bool value) { | 2397 Handle<Object> Factory::ToBoolean(bool value) { |
2394 return value ? true_value() : false_value(); | 2398 return value ? true_value() : false_value(); |
2395 } | 2399 } |
2396 | 2400 |
2397 | 2401 |
2398 } // namespace internal | 2402 } // namespace internal |
2399 } // namespace v8 | 2403 } // namespace v8 |
OLD | NEW |