OLD | NEW |
---|---|
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 3945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3956 function->set_shared(shared); | 3956 function->set_shared(shared); |
3957 function->set_code(shared->code()); | 3957 function->set_code(shared->code()); |
3958 function->set_prototype_or_initial_map(prototype); | 3958 function->set_prototype_or_initial_map(prototype); |
3959 function->set_context(undefined_value()); | 3959 function->set_context(undefined_value()); |
3960 function->set_literals_or_bindings(empty_fixed_array()); | 3960 function->set_literals_or_bindings(empty_fixed_array()); |
3961 function->set_next_function_link(undefined_value()); | 3961 function->set_next_function_link(undefined_value()); |
3962 } | 3962 } |
3963 | 3963 |
3964 | 3964 |
3965 MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) { | 3965 MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) { |
3966 // Allocate the prototype. Make sure to use the object function | 3966 // Make sure to use globals from the function's context, since the function |
3967 // from the function's context, since the function can be from a | 3967 // can be from a different context. |
3968 // different context. | 3968 Context* native_context = function->context()->native_context(); |
3969 JSFunction* object_function = | 3969 bool needs_constructor_property; |
3970 function->context()->native_context()->object_function(); | |
3971 | |
3972 // Each function prototype gets a copy of the object function map. | |
3973 // This avoid unwanted sharing of maps between prototypes of different | |
3974 // constructors. | |
3975 Map* new_map; | 3970 Map* new_map; |
3976 ASSERT(object_function->has_initial_map()); | 3971 if (function->shared()->is_generator()) { |
3977 MaybeObject* maybe_map = object_function->initial_map()->Copy(); | 3972 // Generator prototypes can share maps since they don't have "constructor" |
rossberg
2013/04/09 16:44:14
Hm, according to the class diagram they have.
| |
3978 if (!maybe_map->To(&new_map)) return maybe_map; | 3973 // properties. |
3974 new_map = native_context->generator_iterator_prototype_map(); | |
3975 needs_constructor_property = false; | |
3976 } else { | |
3977 // Each function prototype gets a fresh map to avoid unwanted sharing of | |
3978 // maps between prototypes of different constructors. | |
3979 JSFunction* object_function = native_context->object_function(); | |
3980 ASSERT(object_function->has_initial_map()); | |
3981 MaybeObject* maybe_map = object_function->initial_map()->Copy(); | |
3982 if (!maybe_map->To(&new_map)) return maybe_map; | |
3983 needs_constructor_property = true; | |
3984 } | |
3979 | 3985 |
3980 Object* prototype; | 3986 Object* prototype; |
3981 MaybeObject* maybe_prototype = AllocateJSObjectFromMap(new_map); | 3987 MaybeObject* maybe_prototype = AllocateJSObjectFromMap(new_map); |
3982 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; | 3988 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
3983 | 3989 |
3984 // When creating the prototype for the function we must set its | 3990 if (needs_constructor_property) { |
3985 // constructor to the function. | 3991 MaybeObject* maybe_failure = |
3986 MaybeObject* maybe_failure = | 3992 JSObject::cast(prototype)->SetLocalPropertyIgnoreAttributes( |
3987 JSObject::cast(prototype)->SetLocalPropertyIgnoreAttributes( | 3993 constructor_string(), function, DONT_ENUM); |
3988 constructor_string(), function, DONT_ENUM); | 3994 if (maybe_failure->IsFailure()) return maybe_failure; |
3989 if (maybe_failure->IsFailure()) return maybe_failure; | 3995 } |
3990 | 3996 |
3991 return prototype; | 3997 return prototype; |
3992 } | 3998 } |
3993 | 3999 |
3994 | 4000 |
3995 MaybeObject* Heap::AllocateFunction(Map* function_map, | 4001 MaybeObject* Heap::AllocateFunction(Map* function_map, |
3996 SharedFunctionInfo* shared, | 4002 SharedFunctionInfo* shared, |
3997 Object* prototype, | 4003 Object* prototype, |
3998 PretenureFlag pretenure) { | 4004 PretenureFlag pretenure) { |
3999 AllocationSpace space = | 4005 AllocationSpace space = |
(...skipping 3820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7820 static_cast<int>(object_sizes_last_time_[index])); | 7826 static_cast<int>(object_sizes_last_time_[index])); |
7821 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7827 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
7822 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7828 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7823 | 7829 |
7824 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7830 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7825 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7831 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7826 ClearObjectStats(); | 7832 ClearObjectStats(); |
7827 } | 7833 } |
7828 | 7834 |
7829 } } // namespace v8::internal | 7835 } } // namespace v8::internal |
OLD | NEW |