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

Side by Side Diff: src/factory.cc

Issue 2445333002: Ensure slow properties for simple {__proto__:null} literals. (Closed)
Patch Set: minor cleanup Created 3 years, 7 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 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/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/ast/ast.h" 9 #include "src/ast/ast.h"
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
(...skipping 1845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 Handle<AllocationSite> allocation_site) { 1856 Handle<AllocationSite> allocation_site) {
1857 CALL_HEAP_FUNCTION( 1857 CALL_HEAP_FUNCTION(
1858 isolate(), 1858 isolate(),
1859 isolate()->heap()->AllocateJSObjectFromMap( 1859 isolate()->heap()->AllocateJSObjectFromMap(
1860 *map, 1860 *map,
1861 pretenure, 1861 pretenure,
1862 allocation_site.is_null() ? NULL : *allocation_site), 1862 allocation_site.is_null() ? NULL : *allocation_site),
1863 JSObject); 1863 JSObject);
1864 } 1864 }
1865 1865
1866 Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity,
1867 PretenureFlag pretenure) {
1868 DCHECK(map->is_dictionary_map());
1869 Handle<FixedArray> object_properties =
1870 NameDictionary::New(isolate(), capacity);
1871 Handle<JSObject> js_object = NewJSObjectFromMap(map, pretenure);
1872 js_object->set_properties(*object_properties);
1873 return js_object;
1874 }
1866 1875
1867 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, 1876 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
1868 PretenureFlag pretenure) { 1877 PretenureFlag pretenure) {
1869 Map* map = isolate()->get_initial_js_array_map(elements_kind); 1878 Map* map = isolate()->get_initial_js_array_map(elements_kind);
1870 if (map == nullptr) { 1879 if (map == nullptr) {
1871 Context* native_context = isolate()->context()->native_context(); 1880 Context* native_context = isolate()->context()->native_context();
1872 JSFunction* array_function = native_context->array_function(); 1881 JSFunction* array_function = native_context->array_function();
1873 map = array_function->initial_map(); 1882 map = array_function->initial_map();
1874 } 1883 }
1875 return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure)); 1884 return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure));
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 2665
2657 2666
2658 Handle<JSWeakMap> Factory::NewJSWeakMap() { 2667 Handle<JSWeakMap> Factory::NewJSWeakMap() {
2659 // TODO(adamk): Currently the map is only created three times per 2668 // TODO(adamk): Currently the map is only created three times per
2660 // isolate. If it's created more often, the map should be moved into the 2669 // isolate. If it's created more often, the map should be moved into the
2661 // strong root list. 2670 // strong root list.
2662 Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); 2671 Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
2663 return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); 2672 return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map));
2664 } 2673 }
2665 2674
2666 2675 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> native_context,
2667 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
2668 int number_of_properties, 2676 int number_of_properties,
2669 bool* is_result_from_cache) { 2677 bool has_null_prototype) {
2678 DCHECK(native_context->IsNativeContext());
2670 const int kMapCacheSize = 128; 2679 const int kMapCacheSize = 128;
2671 2680
2681 // 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.
2682 if (has_null_prototype) {
2683 return handle(native_context->slow_object_with_null_prototype_map(),
2684 isolate());
2685 }
2672 // We do not cache maps for too many properties or when running builtin code. 2686 // We do not cache maps for too many properties or when running builtin code.
2673 if (number_of_properties > kMapCacheSize || 2687 if (isolate()->bootstrapper()->IsActive()) {
2674 isolate()->bootstrapper()->IsActive()) { 2688 return Map::Create(isolate(), number_of_properties);
2675 *is_result_from_cache = false;
2676 Handle<Map> map = Map::Create(isolate(), number_of_properties);
2677 return map;
2678 } 2689 }
2679 *is_result_from_cache = true; 2690 // Use initial slow object proto map for too many properties.
2691 if (number_of_properties > kMapCacheSize) {
2692 return handle(native_context->slow_object_with_object_prototype_map(),
2693 isolate());
2694 }
2680 if (number_of_properties == 0) { 2695 if (number_of_properties == 0) {
2681 // Reuse the initial map of the Object function if the literal has no 2696 // Reuse the initial map of the Object function if the literal has no
2682 // predeclared properties. 2697 // predeclared properties.
2683 return handle(context->object_function()->initial_map(), isolate()); 2698 return handle(native_context->object_function()->initial_map(), isolate());
2684 } 2699 }
2685 2700
2686 int cache_index = number_of_properties - 1; 2701 int cache_index = number_of_properties - 1;
2687 Handle<Object> maybe_cache(context->map_cache(), isolate()); 2702 Handle<Object> maybe_cache(native_context->map_cache(), isolate());
2688 if (maybe_cache->IsUndefined(isolate())) { 2703 if (maybe_cache->IsUndefined(isolate())) {
2689 // Allocate the new map cache for the native context. 2704 // Allocate the new map cache for the native context.
2690 maybe_cache = NewFixedArray(kMapCacheSize, TENURED); 2705 maybe_cache = NewFixedArray(kMapCacheSize, TENURED);
2691 context->set_map_cache(*maybe_cache); 2706 native_context->set_map_cache(*maybe_cache);
2692 } else { 2707 } else {
2693 // Check to see whether there is a matching element in the cache. 2708 // Check to see whether there is a matching element in the cache.
2694 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); 2709 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
2695 Object* result = cache->get(cache_index); 2710 Object* result = cache->get(cache_index);
2696 if (result->IsWeakCell()) { 2711 if (result->IsWeakCell()) {
2697 WeakCell* cell = WeakCell::cast(result); 2712 WeakCell* cell = WeakCell::cast(result);
2698 if (!cell->cleared()) { 2713 if (!cell->cleared()) {
2699 return handle(Map::cast(cell->value()), isolate()); 2714 Map* map = Map::cast(cell->value());
2715 DCHECK(!map->is_dictionary_map());
2716 return handle(map, isolate());
2700 } 2717 }
2701 } 2718 }
2702 } 2719 }
2703 // Create a new map and add it to the cache. 2720 // Create a new map and add it to the cache.
2704 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); 2721 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
2705 Handle<Map> map = Map::Create(isolate(), number_of_properties); 2722 Handle<Map> map = Map::Create(isolate(), number_of_properties);
2723 DCHECK(!map->is_dictionary_map());
2706 Handle<WeakCell> cell = NewWeakCell(map); 2724 Handle<WeakCell> cell = NewWeakCell(map);
2707 cache->set(cache_index, *cell); 2725 cache->set(cache_index, *cell);
2708 return map; 2726 return map;
2709 } 2727 }
2710 2728
2711 2729
2712 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, 2730 void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp,
2713 JSRegExp::Type type, 2731 JSRegExp::Type type,
2714 Handle<String> source, 2732 Handle<String> source,
2715 JSRegExp::Flags flags, 2733 JSRegExp::Flags flags,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 Handle<AccessorInfo> prototype = 2953 Handle<AccessorInfo> prototype =
2936 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); 2954 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs);
2937 Descriptor d = Descriptor::AccessorConstant( 2955 Descriptor d = Descriptor::AccessorConstant(
2938 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); 2956 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs);
2939 map->AppendDescriptor(&d); 2957 map->AppendDescriptor(&d);
2940 } 2958 }
2941 } 2959 }
2942 2960
2943 } // namespace internal 2961 } // namespace internal
2944 } // namespace v8 2962 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698