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

Side by Side Diff: src/heap.cc

Issue 13542002: Calling a generator function returns a generator object (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Rebased to apply to bleeding_edge Created 7 years, 8 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4071 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 4082
4083 MaybeObject* Heap::AllocateInitialMap(JSFunction* fun) { 4083 MaybeObject* Heap::AllocateInitialMap(JSFunction* fun) {
4084 ASSERT(!fun->has_initial_map()); 4084 ASSERT(!fun->has_initial_map());
4085 4085
4086 // First create a new map with the size and number of in-object properties 4086 // First create a new map with the size and number of in-object properties
4087 // suggested by the function. 4087 // suggested by the function.
4088 InstanceType instance_type; 4088 InstanceType instance_type;
4089 int instance_size; 4089 int instance_size;
4090 int in_object_properties; 4090 int in_object_properties;
4091 if (fun->shared()->is_generator()) { 4091 if (fun->shared()->is_generator()) {
4092 // TODO(wingo): Replace with JS_GENERATOR_OBJECT_TYPE. 4092 instance_type = JS_GENERATOR_OBJECT_TYPE;
4093 instance_type = JS_OBJECT_TYPE; 4093 instance_size = JSGeneratorObject::kSize;
4094 instance_size = JSObject::kHeaderSize;
4095 in_object_properties = 0; 4094 in_object_properties = 0;
4096 } else { 4095 } else {
4097 instance_type = JS_OBJECT_TYPE; 4096 instance_type = JS_OBJECT_TYPE;
4098 instance_size = fun->shared()->CalculateInstanceSize(); 4097 instance_size = fun->shared()->CalculateInstanceSize();
4099 in_object_properties = fun->shared()->CalculateInObjectProperties(); 4098 in_object_properties = fun->shared()->CalculateInObjectProperties();
4100 } 4099 }
4101 Map* map; 4100 Map* map;
4102 MaybeObject* maybe_map = AllocateMap(instance_type, instance_size); 4101 MaybeObject* maybe_map = AllocateMap(instance_type, instance_size);
4103 if (!maybe_map->To(&map)) return maybe_map; 4102 if (!maybe_map->To(&map)) return maybe_map;
4104 4103
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
4333 } 4332 }
4334 #ifdef DEBUG 4333 #ifdef DEBUG
4335 // Make sure result is NOT a global object if valid. 4334 // Make sure result is NOT a global object if valid.
4336 Object* non_failure; 4335 Object* non_failure;
4337 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); 4336 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject());
4338 #endif 4337 #endif
4339 return result; 4338 return result;
4340 } 4339 }
4341 4340
4342 4341
4342 MaybeObject* Heap::AllocateJSGeneratorObject(JSFunction *function) {
4343 ASSERT(function->shared()->is_generator());
4344 // Allocate the initial map if absent.
4345 if (!function->has_initial_map()) {
4346 Object* initial_map;
4347 MaybeObject* maybe_initial_map = AllocateInitialMap(function);
4348 if (!maybe_initial_map->ToObject(&initial_map)) return maybe_initial_map;
Michael Starzinger 2013/04/11 19:17:39 Just use "maybe_initial_map->To()" here and make t
wingo 2013/04/12 10:50:17 Done.
4349 function->set_initial_map(Map::cast(initial_map));
4350 }
4351 Map *map = function->initial_map();
4352 ASSERT(map->IsMap());
Michael Starzinger 2013/04/11 19:17:39 This assert is obsolete, the accessor should alrea
wingo 2013/04/12 10:50:17 Done.
4353 ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
4354 JSGeneratorObject *generator;
4355 MaybeObject* maybe_generator = AllocateJSObjectFromMap(map, NOT_TENURED);
Michael Starzinger 2013/04/11 19:17:39 The NOT_TENURED flag should be the default argumen
wingo 2013/04/12 10:50:17 Done.
4356 if (!maybe_generator->To(&generator)) return maybe_generator;
4357 generator->set_function(function);
4358 generator->set_context(Smi::FromInt(0));
4359 generator->set_continuation(0);
4360 generator->set_operand_stack(Smi::FromInt(0));
4361 return generator;
4362 }
4363
4364
4343 MaybeObject* Heap::AllocateJSModule(Context* context, ScopeInfo* scope_info) { 4365 MaybeObject* Heap::AllocateJSModule(Context* context, ScopeInfo* scope_info) {
4344 // Allocate a fresh map. Modules do not have a prototype. 4366 // Allocate a fresh map. Modules do not have a prototype.
4345 Map* map; 4367 Map* map;
4346 MaybeObject* maybe_map = AllocateMap(JS_MODULE_TYPE, JSModule::kSize); 4368 MaybeObject* maybe_map = AllocateMap(JS_MODULE_TYPE, JSModule::kSize);
4347 if (!maybe_map->To(&map)) return maybe_map; 4369 if (!maybe_map->To(&map)) return maybe_map;
4348 // Allocate the object based on the map. 4370 // Allocate the object based on the map.
4349 JSModule* module; 4371 JSModule* module;
4350 MaybeObject* maybe_module = AllocateJSObjectFromMap(map, TENURED); 4372 MaybeObject* maybe_module = AllocateJSObjectFromMap(map, TENURED);
4351 if (!maybe_module->To(&module)) return maybe_module; 4373 if (!maybe_module->To(&module)) return maybe_module;
4352 module->set_context(context); 4374 module->set_context(context);
(...skipping 3480 matching lines...) Expand 10 before | Expand all | Expand 10 after
7833 static_cast<int>(object_sizes_last_time_[index])); 7855 static_cast<int>(object_sizes_last_time_[index]));
7834 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) 7856 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
7835 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7857 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7836 7858
7837 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7859 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7838 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7860 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7839 ClearObjectStats(); 7861 ClearObjectStats();
7840 } 7862 }
7841 7863
7842 } } // namespace v8::internal 7864 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698