Chromium Code Reviews| Index: src/factory.cc |
| diff --git a/src/factory.cc b/src/factory.cc |
| index 9bcd26c37b3d9636a5fb8783d59d5d7038345893..3516bf24c45bf77ef4c7e08bfce56cc1c81756d3 100644 |
| --- a/src/factory.cc |
| +++ b/src/factory.cc |
| @@ -1863,6 +1863,15 @@ Handle<JSObject> Factory::NewJSObjectFromMap( |
| JSObject); |
| } |
| +Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity, |
| + PretenureFlag pretenure) { |
| + DCHECK(map->is_dictionary_map()); |
| + Handle<FixedArray> object_properties = |
| + NameDictionary::New(isolate(), capacity); |
| + Handle<JSObject> js_object = NewJSObjectFromMap(map, pretenure); |
| + js_object->set_properties(*object_properties); |
| + return js_object; |
| +} |
| Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, |
| PretenureFlag pretenure) { |
| @@ -2663,32 +2672,38 @@ Handle<JSWeakMap> Factory::NewJSWeakMap() { |
| return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); |
| } |
| - |
| -Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
| +Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> native_context, |
| int number_of_properties, |
| - bool* is_result_from_cache) { |
| + bool has_null_prototype) { |
| + DCHECK(native_context->IsNativeContext()); |
| const int kMapCacheSize = 128; |
| + // Ignoring number_of_properties for force dictionary map with __proto__:null. |
|
Toon Verwaest
2017/04/26 12:28:15
It's kinda silly to pass has_null_prototype throug
Camillo Bruni
2017/04/27 09:39:41
you're right, pulled check up and removed args.
|
| + if (has_null_prototype) { |
| + return handle(native_context->slow_object_with_null_prototype_map(), |
| + isolate()); |
| + } |
| // We do not cache maps for too many properties or when running builtin code. |
| - if (number_of_properties > kMapCacheSize || |
| - isolate()->bootstrapper()->IsActive()) { |
| - *is_result_from_cache = false; |
| - Handle<Map> map = Map::Create(isolate(), number_of_properties); |
| - return map; |
| + if (isolate()->bootstrapper()->IsActive()) { |
| + return Map::Create(isolate(), number_of_properties); |
| + } |
| + // Use initial slow object proto map for too many properties. |
| + if (number_of_properties > kMapCacheSize) { |
| + return handle(native_context->slow_object_with_object_prototype_map(), |
| + isolate()); |
| } |
| - *is_result_from_cache = true; |
| if (number_of_properties == 0) { |
| // Reuse the initial map of the Object function if the literal has no |
| // predeclared properties. |
| - return handle(context->object_function()->initial_map(), isolate()); |
| + return handle(native_context->object_function()->initial_map(), isolate()); |
| } |
| int cache_index = number_of_properties - 1; |
| - Handle<Object> maybe_cache(context->map_cache(), isolate()); |
| + Handle<Object> maybe_cache(native_context->map_cache(), isolate()); |
| if (maybe_cache->IsUndefined(isolate())) { |
| // Allocate the new map cache for the native context. |
| maybe_cache = NewFixedArray(kMapCacheSize, TENURED); |
| - context->set_map_cache(*maybe_cache); |
| + native_context->set_map_cache(*maybe_cache); |
| } else { |
| // Check to see whether there is a matching element in the cache. |
| Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); |
| @@ -2696,13 +2711,16 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
| if (result->IsWeakCell()) { |
| WeakCell* cell = WeakCell::cast(result); |
| if (!cell->cleared()) { |
| - return handle(Map::cast(cell->value()), isolate()); |
| + Map* map = Map::cast(cell->value()); |
| + DCHECK(!map->is_dictionary_map()); |
| + return handle(map, isolate()); |
| } |
| } |
| } |
| // Create a new map and add it to the cache. |
| Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); |
| Handle<Map> map = Map::Create(isolate(), number_of_properties); |
| + DCHECK(!map->is_dictionary_map()); |
| Handle<WeakCell> cell = NewWeakCell(map); |
| cache->set(cache_index, *cell); |
| return map; |