OLD | NEW |
---|---|
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 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1826 Handle<AllocationSite> allocation_site) { | 1826 Handle<AllocationSite> allocation_site) { |
1827 CALL_HEAP_FUNCTION( | 1827 CALL_HEAP_FUNCTION( |
1828 isolate(), | 1828 isolate(), |
1829 isolate()->heap()->AllocateJSObjectFromMap( | 1829 isolate()->heap()->AllocateJSObjectFromMap( |
1830 *map, | 1830 *map, |
1831 pretenure, | 1831 pretenure, |
1832 allocation_site.is_null() ? NULL : *allocation_site), | 1832 allocation_site.is_null() ? NULL : *allocation_site), |
1833 JSObject); | 1833 JSObject); |
1834 } | 1834 } |
1835 | 1835 |
1836 Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity, | |
1837 PretenureFlag pretenure) { | |
1838 DCHECK(map->is_dictionary_map()); | |
1839 Handle<FixedArray> object_properties = | |
1840 NameDictionary::New(isolate(), capacity); | |
1841 Handle<JSObject> js_object = NewJSObjectFromMap(map, pretenure); | |
1842 js_object->set_properties(*object_properties); | |
1843 return js_object; | |
1844 } | |
1836 | 1845 |
1837 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, | 1846 Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, |
1838 PretenureFlag pretenure) { | 1847 PretenureFlag pretenure) { |
1839 Map* map = isolate()->get_initial_js_array_map(elements_kind); | 1848 Map* map = isolate()->get_initial_js_array_map(elements_kind); |
1840 if (map == nullptr) { | 1849 if (map == nullptr) { |
1841 Context* native_context = isolate()->context()->native_context(); | 1850 Context* native_context = isolate()->context()->native_context(); |
1842 JSFunction* array_function = native_context->array_function(); | 1851 JSFunction* array_function = native_context->array_function(); |
1843 map = array_function->initial_map(); | 1852 map = array_function->initial_map(); |
1844 } | 1853 } |
1845 return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure)); | 1854 return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure)); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2595 | 2604 |
2596 | 2605 |
2597 Handle<JSWeakMap> Factory::NewJSWeakMap() { | 2606 Handle<JSWeakMap> Factory::NewJSWeakMap() { |
2598 // TODO(adamk): Currently the map is only created three times per | 2607 // TODO(adamk): Currently the map is only created three times per |
2599 // isolate. If it's created more often, the map should be moved into the | 2608 // isolate. If it's created more often, the map should be moved into the |
2600 // strong root list. | 2609 // strong root list. |
2601 Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); | 2610 Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); |
2602 return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); | 2611 return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map)); |
2603 } | 2612 } |
2604 | 2613 |
2605 | |
2606 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, | 2614 Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
Toon Verwaest
2017/03/14 13:27:47
Isn't this the native context?
Camillo Bruni
2017/03/17 16:40:55
yup, changed.
| |
2607 int number_of_properties, | 2615 int number_of_properties, |
2616 bool has_null_prototype, | |
2608 bool* is_result_from_cache) { | 2617 bool* is_result_from_cache) { |
2609 const int kMapCacheSize = 128; | 2618 const int kMapCacheSize = 128; |
2610 | 2619 |
2620 // Ignoring number_of_properties for force dictionary map with __proto__:null. | |
2621 if (has_null_prototype) { | |
2622 *is_result_from_cache = true; | |
2623 return handle(context->slow_object_with_null_prototype_map(), isolate()); | |
2624 } | |
2611 // We do not cache maps for too many properties or when running builtin code. | 2625 // We do not cache maps for too many properties or when running builtin code. |
2612 if (number_of_properties > kMapCacheSize || | 2626 if (number_of_properties > kMapCacheSize || |
2613 isolate()->bootstrapper()->IsActive()) { | 2627 isolate()->bootstrapper()->IsActive()) { |
2614 *is_result_from_cache = false; | 2628 *is_result_from_cache = false; |
2615 Handle<Map> map = Map::Create(isolate(), number_of_properties); | 2629 Handle<Map> map = Map::Create(isolate(), number_of_properties); |
2616 return map; | 2630 return map; |
2617 } | 2631 } |
2618 *is_result_from_cache = true; | 2632 *is_result_from_cache = true; |
2619 if (number_of_properties == 0) { | 2633 if (number_of_properties == 0) { |
2620 // Reuse the initial map of the Object function if the literal has no | 2634 // Reuse the initial map of the Object function if the literal has no |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2874 Handle<AccessorInfo> prototype = | 2888 Handle<AccessorInfo> prototype = |
2875 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2889 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
2876 Descriptor d = Descriptor::AccessorConstant( | 2890 Descriptor d = Descriptor::AccessorConstant( |
2877 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 2891 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); |
2878 map->AppendDescriptor(&d); | 2892 map->AppendDescriptor(&d); |
2879 } | 2893 } |
2880 } | 2894 } |
2881 | 2895 |
2882 } // namespace internal | 2896 } // namespace internal |
2883 } // namespace v8 | 2897 } // namespace v8 |
OLD | NEW |