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

Side by Side Diff: src/factory.cc

Issue 447293002: Mark as prototype only after instantiating the function (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/bootstrapper.cc ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/conversions.h" 8 #include "src/conversions.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 1261
1262 1262
1263 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1263 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1264 Handle<Code> code, 1264 Handle<Code> code,
1265 Handle<Object> prototype, 1265 Handle<Object> prototype,
1266 bool read_only_prototype) { 1266 bool read_only_prototype) {
1267 Handle<Map> map = read_only_prototype 1267 Handle<Map> map = read_only_prototype
1268 ? isolate()->sloppy_function_with_readonly_prototype_map() 1268 ? isolate()->sloppy_function_with_readonly_prototype_map()
1269 : isolate()->sloppy_function_map(); 1269 : isolate()->sloppy_function_map();
1270 Handle<JSFunction> result = NewFunction(map, name, code); 1270 Handle<JSFunction> result = NewFunction(map, name, code);
1271 if (!prototype->IsTheHole()) {
1272 Handle<JSObject> js_proto = Handle<JSObject>::cast(prototype);
1273 Handle<Map> new_map = Map::CopyAsPrototypeMap(handle(js_proto->map()));
1274 JSObject::MigrateToMap(js_proto, new_map);
1275 }
1276 result->set_prototype_or_initial_map(*prototype); 1271 result->set_prototype_or_initial_map(*prototype);
1277 return result; 1272 return result;
1278 } 1273 }
1279 1274
1280 1275
1281 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1276 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1282 Handle<Code> code, 1277 Handle<Code> code,
1283 Handle<Object> prototype, 1278 Handle<Object> prototype,
1284 InstanceType type, 1279 InstanceType type,
1285 int instance_size, 1280 int instance_size,
1286 bool read_only_prototype) { 1281 bool read_only_prototype) {
1287 // Allocate the function 1282 // Allocate the function
1288 Handle<JSFunction> function = NewFunction( 1283 Handle<JSFunction> function = NewFunction(
1289 name, code, prototype, read_only_prototype); 1284 name, code, prototype, read_only_prototype);
1290 1285
1291 Handle<Map> initial_map = NewMap( 1286 Handle<Map> initial_map = NewMap(
1292 type, instance_size, GetInitialFastElementsKind()); 1287 type, instance_size, GetInitialFastElementsKind());
1293 if (prototype->IsTheHole() && !function->shared()->is_generator()) { 1288 if (prototype->IsTheHole() && !function->shared()->is_generator()) {
1294 prototype = NewFunctionPrototype(function); 1289 prototype = NewFunctionPrototype(function);
1295 } 1290 }
1291
1296 initial_map->set_prototype(*prototype); 1292 initial_map->set_prototype(*prototype);
1297 function->set_initial_map(*initial_map); 1293 JSFunction::SetInitialMap(function, initial_map);
1298 initial_map->set_constructor(*function);
1299 1294
1300 return function; 1295 return function;
1301 } 1296 }
1302 1297
1303 1298
1304 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1299 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1305 Handle<Code> code, 1300 Handle<Code> code,
1306 InstanceType type, 1301 InstanceType type,
1307 int instance_size) { 1302 int instance_size) {
1308 return NewFunction(name, code, the_hole_value(), type, instance_size); 1303 return NewFunction(name, code, the_hole_value(), type, instance_size);
1309 } 1304 }
1310 1305
1311 1306
1312 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { 1307 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
1313 // Make sure to use globals from the function's context, since the function 1308 // Make sure to use globals from the function's context, since the function
1314 // can be from a different context. 1309 // can be from a different context.
1315 Handle<Context> native_context(function->context()->native_context()); 1310 Handle<Context> native_context(function->context()->native_context());
1316 Handle<Map> new_map; 1311 Handle<Map> new_map;
1317 if (function->shared()->is_generator()) { 1312 if (function->shared()->is_generator()) {
1318 // Generator prototypes can share maps since they don't have "constructor" 1313 // Generator prototypes can share maps since they don't have "constructor"
1319 // properties. 1314 // properties.
1320 new_map = handle(native_context->generator_object_prototype_map()); 1315 new_map = handle(native_context->generator_object_prototype_map());
1321 } else { 1316 } else {
1322 // Each function prototype gets a fresh map to avoid unwanted sharing of 1317 // Each function prototype gets a fresh map to avoid unwanted sharing of
1323 // maps between prototypes of different constructors. 1318 // maps between prototypes of different constructors.
1324 Handle<JSFunction> object_function(native_context->object_function()); 1319 Handle<JSFunction> object_function(native_context->object_function());
1325 DCHECK(object_function->has_initial_map()); 1320 DCHECK(object_function->has_initial_map());
1326 new_map = Map::CopyAsPrototypeMap(handle(object_function->initial_map())); 1321 new_map = handle(object_function->initial_map());
1327 } 1322 }
1328 1323
1329 Handle<JSObject> prototype = NewJSObjectFromMap(new_map); 1324 Handle<JSObject> prototype = NewJSObjectFromMap(new_map);
1330 1325
1331 if (!function->shared()->is_generator()) { 1326 if (!function->shared()->is_generator()) {
1332 JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM); 1327 JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM);
1333 } 1328 }
1334 1329
1335 return prototype; 1330 return prototype;
1336 } 1331 }
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2370 return Handle<Object>::null(); 2365 return Handle<Object>::null();
2371 } 2366 }
2372 2367
2373 2368
2374 Handle<Object> Factory::ToBoolean(bool value) { 2369 Handle<Object> Factory::ToBoolean(bool value) {
2375 return value ? true_value() : false_value(); 2370 return value ? true_value() : false_value();
2376 } 2371 }
2377 2372
2378 2373
2379 } } // namespace v8::internal 2374 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698