OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3250 return function; | 3250 return function; |
3251 } | 3251 } |
3252 | 3252 |
3253 | 3253 |
3254 MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) { | 3254 MaybeObject* Heap::AllocateFunctionPrototype(JSFunction* function) { |
3255 // Allocate the prototype. Make sure to use the object function | 3255 // Allocate the prototype. Make sure to use the object function |
3256 // from the function's context, since the function can be from a | 3256 // from the function's context, since the function can be from a |
3257 // different context. | 3257 // different context. |
3258 JSFunction* object_function = | 3258 JSFunction* object_function = |
3259 function->context()->global_context()->object_function(); | 3259 function->context()->global_context()->object_function(); |
| 3260 |
| 3261 // Each function prototype gets a copy of the object function map. |
| 3262 // This avoid unwanted sharing of maps between prototypes of different |
| 3263 // constructors. |
| 3264 Map* new_map; |
| 3265 ASSERT(object_function->has_initial_map()); |
| 3266 { MaybeObject* maybe_map = |
| 3267 object_function->initial_map()->CopyDropTransitions(); |
| 3268 if (!maybe_map->To<Map>(&new_map)) return maybe_map; |
| 3269 } |
3260 Object* prototype; | 3270 Object* prototype; |
3261 { MaybeObject* maybe_prototype = AllocateJSObject(object_function); | 3271 { MaybeObject* maybe_prototype = AllocateJSObjectFromMap(new_map); |
3262 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; | 3272 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
3263 } | 3273 } |
3264 // When creating the prototype for the function we must set its | 3274 // When creating the prototype for the function we must set its |
3265 // constructor to the function. | 3275 // constructor to the function. |
3266 Object* result; | 3276 Object* result; |
3267 { MaybeObject* maybe_result = | 3277 { MaybeObject* maybe_result = |
3268 JSObject::cast(prototype)->SetLocalPropertyIgnoreAttributes( | 3278 JSObject::cast(prototype)->SetLocalPropertyIgnoreAttributes( |
3269 constructor_symbol(), function, DONT_ENUM); | 3279 constructor_symbol(), function, DONT_ENUM); |
3270 if (!maybe_result->ToObject(&result)) return maybe_result; | 3280 if (!maybe_result->ToObject(&result)) return maybe_result; |
3271 } | 3281 } |
(...skipping 3084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6356 } | 6366 } |
6357 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6367 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6358 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6368 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6359 next = chunk->next_chunk(); | 6369 next = chunk->next_chunk(); |
6360 isolate_->memory_allocator()->Free(chunk); | 6370 isolate_->memory_allocator()->Free(chunk); |
6361 } | 6371 } |
6362 chunks_queued_for_free_ = NULL; | 6372 chunks_queued_for_free_ = NULL; |
6363 } | 6373 } |
6364 | 6374 |
6365 } } // namespace v8::internal | 6375 } } // namespace v8::internal |
OLD | NEW |