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

Side by Side Diff: src/bootstrapper.cc

Issue 1411653002: Install iterator meta objects via utils object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 5 years, 2 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
« no previous file with comments | « no previous file | src/heap/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/base/utils/random-number-generator.h" 9 #include "src/base/utils/random-number-generator.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void CreateRoots(); 157 void CreateRoots();
158 // Creates the empty function. Used for creating a context from scratch. 158 // Creates the empty function. Used for creating a context from scratch.
159 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); 159 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
160 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 160 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
161 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower(); 161 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower();
162 Handle<JSFunction> GetStrictArgumentsPoisonFunction(); 162 Handle<JSFunction> GetStrictArgumentsPoisonFunction();
163 Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name); 163 Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name);
164 164
165 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); 165 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
166 void CreateStrongModeFunctionMaps(Handle<JSFunction> empty); 166 void CreateStrongModeFunctionMaps(Handle<JSFunction> empty);
167 void CreateIteratorMaps();
167 168
168 // Make the "arguments" and "caller" properties throw a TypeError on access. 169 // Make the "arguments" and "caller" properties throw a TypeError on access.
169 void AddRestrictedFunctionProperties(Handle<Map> map); 170 void AddRestrictedFunctionProperties(Handle<Map> map);
170 171
171 // Creates the global objects using the global proxy and the template passed 172 // Creates the global objects using the global proxy and the template passed
172 // in through the API. We call this regardless of whether we are building a 173 // in through the API. We call this regardless of whether we are building a
173 // context from scratch or using a deserialized one from the partial snapshot 174 // context from scratch or using a deserialized one from the partial snapshot
174 // but in the latter case we don't use the objects it produces directly, as 175 // but in the latter case we don't use the objects it produces directly, as
175 // we have to used the deserialized ones that are linked together with the 176 // we have to used the deserialized ones that are linked together with the
176 // rest of the context snapshot. 177 // rest of the context snapshot.
(...skipping 15 matching lines...) Expand all
192 // global proxy. 193 // global proxy.
193 void InstallGlobalThisBinding(); 194 void InstallGlobalThisBinding();
194 void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts); 195 void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts);
195 // New context initialization. Used for creating a context from scratch. 196 // New context initialization. Used for creating a context from scratch.
196 void InitializeGlobal(Handle<GlobalObject> global_object, 197 void InitializeGlobal(Handle<GlobalObject> global_object,
197 Handle<JSFunction> empty_function, 198 Handle<JSFunction> empty_function,
198 ContextType context_type); 199 ContextType context_type);
199 void InitializeExperimentalGlobal(); 200 void InitializeExperimentalGlobal();
200 // Typed arrays are not serializable and have to initialized afterwards. 201 // Typed arrays are not serializable and have to initialized afterwards.
201 void InitializeBuiltinTypedArrays(); 202 void InitializeBuiltinTypedArrays();
203 // Depending on the situation, expose and/or get rid of the utils object.
204 void ConfigureUtilsObject(ContextType context_type);
202 205
203 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ 206 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \
204 void InitializeGlobal_##id(); 207 void InitializeGlobal_##id();
205 208
206 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) 209 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION)
207 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) 210 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION)
208 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) 211 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
209 #undef DECLARE_FEATURE_INITIALIZATION 212 #undef DECLARE_FEATURE_INITIALIZATION
210 213
211 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, 214 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 void Genesis::CreateStrongModeFunctionMaps(Handle<JSFunction> empty) { 789 void Genesis::CreateStrongModeFunctionMaps(Handle<JSFunction> empty) {
787 // Allocate map for strong mode instances, which never have prototypes. 790 // Allocate map for strong mode instances, which never have prototypes.
788 Handle<Map> strong_function_map = CreateStrongFunctionMap(empty, false); 791 Handle<Map> strong_function_map = CreateStrongFunctionMap(empty, false);
789 native_context()->set_strong_function_map(*strong_function_map); 792 native_context()->set_strong_function_map(*strong_function_map);
790 // Constructors do, though. 793 // Constructors do, though.
791 Handle<Map> strong_constructor_map = CreateStrongFunctionMap(empty, true); 794 Handle<Map> strong_constructor_map = CreateStrongFunctionMap(empty, true);
792 native_context()->set_strong_constructor_map(*strong_constructor_map); 795 native_context()->set_strong_constructor_map(*strong_constructor_map);
793 } 796 }
794 797
795 798
799 void Genesis::CreateIteratorMaps() {
800 // Create iterator-related meta-objects.
801 Handle<JSObject> iterator_prototype =
802 factory()->NewJSObject(isolate()->object_function(), TENURED);
803 Handle<JSObject> generator_object_prototype =
804 factory()->NewJSObject(isolate()->object_function(), TENURED);
805 Handle<JSObject> generator_function_prototype =
806 factory()->NewJSObject(isolate()->object_function(), TENURED);
807 SetObjectPrototype(generator_object_prototype, iterator_prototype);
808
809 JSObject::AddProperty(generator_function_prototype,
810 factory()->InternalizeUtf8String("prototype"),
811 generator_object_prototype,
812 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
813
814 // Create maps for generator functions and their prototypes. Store those
815 // maps in the native context. The "prototype" property descriptor is
816 // writable, non-enumerable, and non-configurable (as per ES6 draft
817 // 04-14-15, section 25.2.4.3).
818 Handle<Map> strict_function_map(strict_function_map_writable_prototype_);
819 // Generator functions do not have "caller" or "arguments" accessors.
820 Handle<Map> sloppy_generator_function_map =
821 Map::Copy(strict_function_map, "SloppyGeneratorFunction");
822 Map::SetPrototype(sloppy_generator_function_map,
823 generator_function_prototype);
824 native_context()->set_sloppy_generator_function_map(
825 *sloppy_generator_function_map);
826
827 Handle<Map> strict_generator_function_map =
828 Map::Copy(strict_function_map, "StrictGeneratorFunction");
829 Map::SetPrototype(strict_generator_function_map,
830 generator_function_prototype);
831 native_context()->set_strict_generator_function_map(
832 *strict_generator_function_map);
833
834 Handle<Map> strong_function_map(native_context()->strong_function_map());
835 Handle<Map> strong_generator_function_map =
836 Map::Copy(strong_function_map, "StrongGeneratorFunction");
837 Map::SetPrototype(strong_generator_function_map,
838 generator_function_prototype);
839 native_context()->set_strong_generator_function_map(
840 *strong_generator_function_map);
841
842 Handle<JSFunction> object_function(native_context()->object_function());
843 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
844 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype);
845 native_context()->set_generator_object_prototype_map(
846 *generator_object_prototype_map);
847 }
848
849
796 static void ReplaceAccessors(Handle<Map> map, 850 static void ReplaceAccessors(Handle<Map> map,
797 Handle<String> name, 851 Handle<String> name,
798 PropertyAttributes attributes, 852 PropertyAttributes attributes,
799 Handle<AccessorPair> accessor_pair) { 853 Handle<AccessorPair> accessor_pair) {
800 DescriptorArray* descriptors = map->instance_descriptors(); 854 DescriptorArray* descriptors = map->instance_descriptors();
801 int idx = descriptors->SearchWithCache(*name, *map); 855 int idx = descriptors->SearchWithCache(*name, *map);
802 AccessorConstantDescriptor descriptor(name, accessor_pair, attributes); 856 AccessorConstantDescriptor descriptor(name, accessor_pair, attributes);
803 descriptors->Replace(idx, &descriptor); 857 descriptors->Replace(idx, &descriptor);
804 } 858 }
805 859
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 { // Initialize a result array for rempio2 calculation 1841 { // Initialize a result array for rempio2 calculation
1788 const size_t num_elements = 2; 1842 const size_t num_elements = 2;
1789 double* data = 1843 double* data =
1790 SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array, 1844 SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array,
1791 NULL, num_elements, "rempio2result"); 1845 NULL, num_elements, "rempio2result");
1792 for (size_t i = 0; i < num_elements; i++) data[i] = 0; 1846 for (size_t i = 0; i < num_elements; i++) data[i] = 0;
1793 } 1847 }
1794 } 1848 }
1795 1849
1796 1850
1851 void Genesis::ConfigureUtilsObject(ContextType context_type) {
1852 switch (context_type) {
1853 // We still need the utils object to find debug functions.
1854 case DEBUG_CONTEXT:
1855 return;
1856 // Expose the natives in global if a valid name for it is specified.
1857 case FULL_CONTEXT: {
1858 // We still need the utils object after deserialization.
1859 if (isolate()->serializer_enabled()) return;
1860 if (FLAG_expose_natives_as == NULL) break;
1861 if (strlen(FLAG_expose_natives_as) == 0) break;
1862 HandleScope scope(isolate());
1863 Handle<String> natives_key =
1864 factory()->InternalizeUtf8String(FLAG_expose_natives_as);
1865 uint32_t dummy_index;
1866 if (natives_key->AsArrayIndex(&dummy_index)) break;
1867 Handle<Object> utils = isolate()->natives_utils_object();
1868 Handle<JSObject> global = isolate()->global_object();
1869 JSObject::AddProperty(global, natives_key, utils, DONT_ENUM);
1870 break;
1871 }
1872 case THIN_CONTEXT:
1873 break;
1874 }
1875
1876 // The utils object can be removed for cases that reach this point.
1877 native_context()->set_natives_utils_object(heap()->undefined_value());
1878 }
1879
1880
1797 void Bootstrapper::ExportFromRuntime(Isolate* isolate, 1881 void Bootstrapper::ExportFromRuntime(Isolate* isolate,
1798 Handle<JSObject> container) { 1882 Handle<JSObject> container) {
1799 HandleScope scope(isolate); 1883 HandleScope scope(isolate);
1800 #define EXPORT_PRIVATE_SYMBOL(NAME) \ 1884 #define EXPORT_PRIVATE_SYMBOL(NAME) \
1801 Handle<String> NAME##_name = \ 1885 Handle<String> NAME##_name = \
1802 isolate->factory()->NewStringFromAsciiChecked(#NAME); \ 1886 isolate->factory()->NewStringFromAsciiChecked(#NAME); \
1803 JSObject::AddProperty(container, NAME##_name, isolate->factory()->NAME(), \ 1887 JSObject::AddProperty(container, NAME##_name, isolate->factory()->NAME(), \
1804 NONE); 1888 NONE);
1805 PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL) 1889 PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL)
1806 #undef EXPORT_PRIVATE_SYMBOL 1890 #undef EXPORT_PRIVATE_SYMBOL
(...skipping 23 matching lines...) Expand all
1830 Handle<JSFunction> construct = InstallFunction( 1914 Handle<JSFunction> construct = InstallFunction(
1831 container, "reflect_construct", JS_OBJECT_TYPE, JSObject::kHeaderSize, 1915 container, "reflect_construct", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1832 MaybeHandle<JSObject>(), Builtins::kReflectConstruct); 1916 MaybeHandle<JSObject>(), Builtins::kReflectConstruct);
1833 construct->shared()->set_internal_formal_parameter_count(3); 1917 construct->shared()->set_internal_formal_parameter_count(3);
1834 construct->shared()->set_length(2); 1918 construct->shared()->set_length(2);
1835 Handle<TypeFeedbackVector> feedback_vector = 1919 Handle<TypeFeedbackVector> feedback_vector =
1836 TypeFeedbackVector::CreatePushAppliedArgumentsVector(isolate); 1920 TypeFeedbackVector::CreatePushAppliedArgumentsVector(isolate);
1837 construct->shared()->set_feedback_vector(*feedback_vector); 1921 construct->shared()->set_feedback_vector(*feedback_vector);
1838 isolate->native_context()->set_reflect_construct(*construct); 1922 isolate->native_context()->set_reflect_construct(*construct);
1839 } 1923 }
1924
1925 Handle<JSObject> iterator_prototype;
1926
1927 {
1928 PrototypeIterator iter(
1929 isolate->native_context()->generator_object_prototype_map());
1930 iter.Advance(); // Advance to the prototype of generator_object_prototype.
1931 iterator_prototype = Handle<JSObject>(iter.GetCurrent<JSObject>());
1932
1933 JSObject::AddProperty(container, isolate->factory()->InternalizeUtf8String(
1934 "IteratorPrototype"),
1935 iterator_prototype, NONE);
1936 }
1937
1938 {
1939 PrototypeIterator iter(
1940 isolate->native_context()->sloppy_generator_function_map());
1941 Handle<JSObject> generator_function_prototype(iter.GetCurrent<JSObject>());
1942
1943 JSObject::AddProperty(container, isolate->factory()->InternalizeUtf8String(
1944 "GeneratorFunctionPrototype"),
1945 generator_function_prototype, NONE);
1946
1947 static const bool kUseStrictFunctionMap = true;
1948 Handle<JSFunction> generator_function_function =
1949 InstallFunction(container, "GeneratorFunction", JS_FUNCTION_TYPE,
1950 JSFunction::kSize, generator_function_prototype,
1951 Builtins::kIllegal, kUseStrictFunctionMap);
1952 generator_function_function->initial_map()->set_is_callable();
1953 }
1954
1955 { // -- S e t I t e r a t o r
1956 Handle<JSObject> set_iterator_prototype =
1957 isolate->factory()->NewJSObject(isolate->object_function(), TENURED);
1958 SetObjectPrototype(set_iterator_prototype, iterator_prototype);
1959 Handle<JSFunction> set_iterator_function = InstallFunction(
1960 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize,
1961 set_iterator_prototype, Builtins::kIllegal);
1962 isolate->native_context()->set_set_iterator_map(
1963 set_iterator_function->initial_map());
1964 }
1965
1966 { // -- M a p I t e r a t o r
1967 Handle<JSObject> map_iterator_prototype =
1968 isolate->factory()->NewJSObject(isolate->object_function(), TENURED);
1969 SetObjectPrototype(map_iterator_prototype, iterator_prototype);
1970 Handle<JSFunction> map_iterator_function = InstallFunction(
1971 container, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize,
1972 map_iterator_prototype, Builtins::kIllegal);
1973 isolate->native_context()->set_map_iterator_map(
1974 map_iterator_function->initial_map());
1975 }
1840 } 1976 }
1841 1977
1842 1978
1843 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, 1979 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
1844 Handle<JSObject> container) { 1980 Handle<JSObject> container) {
1845 HandleScope scope(isolate); 1981 HandleScope scope(isolate);
1846 1982
1847 #define INITIALIZE_FLAG(FLAG) \ 1983 #define INITIALIZE_FLAG(FLAG) \
1848 { \ 1984 { \
1849 Handle<String> name = \ 1985 Handle<String> name = \
1850 isolate->factory()->NewStringFromAsciiChecked(#FLAG); \ 1986 isolate->factory()->NewStringFromAsciiChecked(#FLAG); \
1851 JSObject::AddProperty(container, name, \ 1987 JSObject::AddProperty(container, name, \
1852 isolate->factory()->ToBoolean(FLAG), NONE); \ 1988 isolate->factory()->ToBoolean(FLAG), NONE); \
1853 } 1989 }
1854 1990
1855 INITIALIZE_FLAG(FLAG_harmony_regexps) 1991 INITIALIZE_FLAG(FLAG_harmony_regexps)
1856 INITIALIZE_FLAG(FLAG_harmony_unicode_regexps) 1992 INITIALIZE_FLAG(FLAG_harmony_unicode_regexps)
1857 INITIALIZE_FLAG(FLAG_harmony_tostring) 1993 INITIALIZE_FLAG(FLAG_harmony_tostring)
1994 INITIALIZE_FLAG(FLAG_harmony_tolength)
1858 1995
1859 #undef INITIALIZE_FLAG 1996 #undef INITIALIZE_FLAG
1860 } 1997 }
1861 1998
1862 1999
1863 #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \ 2000 #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
1864 void Genesis::InitializeGlobal_##id() {} 2001 void Genesis::InitializeGlobal_##id() {}
1865 2002
1866 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules) 2003 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules)
1867 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes) 2004 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes)
1868 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies) 2005 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies)
1869 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy) 2006 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy)
1870 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function) 2007 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function)
1871 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let) 2008 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let)
1872 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters) 2009 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters)
1873 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters) 2010 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters)
1874 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_calls) 2011 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_calls)
1875 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring) 2012 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring)
1876 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe) 2013 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe)
1877 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_arrays) 2014 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_arrays)
1878 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_new_target) 2015 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_new_target)
1879 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_concat_spreadable) 2016 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_concat_spreadable)
1880 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps) 2017 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps)
1881 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps) 2018 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps)
1882 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tostring) 2019 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tostring)
1883 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_completion) 2020 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_completion)
1884 2021 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tolength)
1885
1886 void Genesis::InitializeGlobal_harmony_tolength() {
1887 Handle<JSObject> builtins(native_context()->builtins());
1888 Handle<Object> flag(factory()->ToBoolean(FLAG_harmony_tolength));
1889 Runtime::SetObjectProperty(isolate(), builtins,
1890 factory()->harmony_tolength_string(), flag,
1891 STRICT).Assert();
1892 }
1893 2022
1894 2023
1895 static void SimpleInstallFunction(Handle<JSObject>& base, const char* name, 2024 static void SimpleInstallFunction(Handle<JSObject>& base, const char* name,
1896 Builtins::Name call, int len, bool adapt) { 2025 Builtins::Name call, int len, bool adapt) {
1897 Handle<JSFunction> fun = 2026 Handle<JSFunction> fun =
1898 InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, 2027 InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize,
1899 MaybeHandle<JSObject>(), call); 2028 MaybeHandle<JSObject>(), call);
1900 if (adapt) { 2029 if (adapt) {
1901 fun->shared()->set_internal_formal_parameter_count(len); 2030 fun->shared()->set_internal_formal_parameter_count(len);
1902 } else { 2031 } else {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 int builtin_index = Natives::GetDebuggerCount(); 2202 int builtin_index = Natives::GetDebuggerCount();
2074 // Only run prologue.js and runtime.js at this point. 2203 // Only run prologue.js and runtime.js at this point.
2075 DCHECK_EQ(builtin_index, Natives::GetIndex("prologue")); 2204 DCHECK_EQ(builtin_index, Natives::GetIndex("prologue"));
2076 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; 2205 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
2077 DCHECK_EQ(builtin_index, Natives::GetIndex("runtime")); 2206 DCHECK_EQ(builtin_index, Natives::GetIndex("runtime"));
2078 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; 2207 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
2079 2208
2080 // A thin context is ready at this point. 2209 // A thin context is ready at this point.
2081 if (context_type == THIN_CONTEXT) return true; 2210 if (context_type == THIN_CONTEXT) return true;
2082 2211
2083 if (FLAG_expose_natives_as != NULL) {
2084 Handle<String> utils_key = factory()->NewStringFromAsciiChecked("utils");
2085 JSObject::AddProperty(builtins, utils_key, utils, NONE);
2086 }
2087
2088 { // -- S c r i p t 2212 { // -- S c r i p t
2089 // Builtin functions for Script. 2213 // Builtin functions for Script.
2090 Handle<JSFunction> script_fun = InstallFunction( 2214 Handle<JSFunction> script_fun = InstallFunction(
2091 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, 2215 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
2092 isolate()->initial_object_prototype(), Builtins::kIllegal); 2216 isolate()->initial_object_prototype(), Builtins::kIllegal);
2093 Handle<JSObject> prototype = 2217 Handle<JSObject> prototype =
2094 factory()->NewJSObject(isolate()->object_function(), TENURED); 2218 factory()->NewJSObject(isolate()->object_function(), TENURED);
2095 Accessors::FunctionSetPrototype(script_fun, prototype).Assert(); 2219 Accessors::FunctionSetPrototype(script_fun, prototype).Assert();
2096 native_context()->set_script_function(*script_fun); 2220 native_context()->set_script_function(*script_fun);
2097 2221
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 { 2378 {
2255 HandleScope scope(isolate()); 2379 HandleScope scope(isolate());
2256 Handle<JSObject> utils = 2380 Handle<JSObject> utils =
2257 Handle<JSObject>::cast(isolate()->natives_utils_object()); 2381 Handle<JSObject>::cast(isolate()->natives_utils_object());
2258 Handle<JSFunction> array_function = 2382 Handle<JSFunction> array_function =
2259 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS); 2383 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS);
2260 native_context()->set_internal_array_function(*array_function); 2384 native_context()->set_internal_array_function(*array_function);
2261 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); 2385 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS);
2262 } 2386 }
2263 2387
2264 { // -- S e t I t e r a t o r
2265 Handle<JSFunction> set_iterator_function = InstallFunction(
2266 builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize,
2267 isolate()->initial_object_prototype(), Builtins::kIllegal);
2268 native_context()->set_set_iterator_map(
2269 set_iterator_function->initial_map());
2270 }
2271
2272 { // -- M a p I t e r a t o r
2273 Handle<JSFunction> map_iterator_function = InstallFunction(
2274 builtins, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize,
2275 isolate()->initial_object_prototype(), Builtins::kIllegal);
2276 native_context()->set_map_iterator_map(
2277 map_iterator_function->initial_map());
2278 }
2279
2280 {
2281 // Create generator meta-objects and install them on the builtins object.
2282 Handle<JSObject> builtins(native_context()->builtins());
2283 Handle<JSObject> iterator_prototype =
2284 factory()->NewJSObject(isolate()->object_function(), TENURED);
2285 Handle<JSObject> generator_object_prototype =
2286 factory()->NewJSObject(isolate()->object_function(), TENURED);
2287 Handle<JSObject> generator_function_prototype =
2288 factory()->NewJSObject(isolate()->object_function(), TENURED);
2289 SetObjectPrototype(generator_object_prototype, iterator_prototype);
2290 JSObject::AddProperty(
2291 builtins, factory()->InternalizeUtf8String("$iteratorPrototype"),
2292 iterator_prototype,
2293 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY));
2294 JSObject::AddProperty(
2295 builtins,
2296 factory()->InternalizeUtf8String("GeneratorFunctionPrototype"),
2297 generator_function_prototype,
2298 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY));
2299
2300 JSObject::AddProperty(
2301 generator_function_prototype,
2302 factory()->InternalizeUtf8String("prototype"),
2303 generator_object_prototype,
2304 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2305
2306 static const bool kUseStrictFunctionMap = true;
2307 Handle<JSFunction> generator_function_function =
2308 InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE,
2309 JSFunction::kSize, generator_function_prototype,
2310 Builtins::kIllegal, kUseStrictFunctionMap);
2311 generator_function_function->initial_map()->set_is_callable();
2312
2313 // Create maps for generator functions and their prototypes. Store those
2314 // maps in the native context. The "prototype" property descriptor is
2315 // writable, non-enumerable, and non-configurable (as per ES6 draft
2316 // 04-14-15, section 25.2.4.3).
2317 Handle<Map> strict_function_map(strict_function_map_writable_prototype_);
2318 // Generator functions do not have "caller" or "arguments" accessors.
2319 Handle<Map> sloppy_generator_function_map =
2320 Map::Copy(strict_function_map, "SloppyGeneratorFunction");
2321 Map::SetPrototype(sloppy_generator_function_map,
2322 generator_function_prototype);
2323 native_context()->set_sloppy_generator_function_map(
2324 *sloppy_generator_function_map);
2325
2326 Handle<Map> strict_generator_function_map =
2327 Map::Copy(strict_function_map, "StrictGeneratorFunction");
2328 Map::SetPrototype(strict_generator_function_map,
2329 generator_function_prototype);
2330 native_context()->set_strict_generator_function_map(
2331 *strict_generator_function_map);
2332
2333 Handle<Map> strong_function_map(native_context()->strong_function_map());
2334 Handle<Map> strong_generator_function_map =
2335 Map::Copy(strong_function_map, "StrongGeneratorFunction");
2336 Map::SetPrototype(strong_generator_function_map,
2337 generator_function_prototype);
2338 native_context()->set_strong_generator_function_map(
2339 *strong_generator_function_map);
2340
2341 Handle<JSFunction> object_function(native_context()->object_function());
2342 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
2343 Map::SetPrototype(generator_object_prototype_map,
2344 generator_object_prototype);
2345 native_context()->set_generator_object_prototype_map(
2346 *generator_object_prototype_map);
2347 }
2348
2349 if (FLAG_disable_native_files) {
2350 PrintF("Warning: Running without installed natives!\n");
2351 return true;
2352 }
2353
2354 // Run the rest of the native scripts. 2388 // Run the rest of the native scripts.
2355 while (builtin_index < Natives::GetBuiltinsCount()) { 2389 while (builtin_index < Natives::GetBuiltinsCount()) {
2356 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; 2390 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
2357 } 2391 }
2358 2392
2359 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; 2393 if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
2360 2394
2361 auto function_cache = 2395 auto function_cache =
2362 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize, 2396 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize,
2363 USE_CUSTOM_MINIMUM_CAPACITY); 2397 USE_CUSTOM_MINIMUM_CAPACITY);
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
2761 Handle<JSGlobalObject> global(JSGlobalObject::cast( 2795 Handle<JSGlobalObject> global(JSGlobalObject::cast(
2762 native_context->global_object())); 2796 native_context->global_object()));
2763 2797
2764 Handle<JSObject> Error = Handle<JSObject>::cast( 2798 Handle<JSObject> Error = Handle<JSObject>::cast(
2765 Object::GetProperty(isolate, global, "Error").ToHandleChecked()); 2799 Object::GetProperty(isolate, global, "Error").ToHandleChecked());
2766 Handle<String> name = 2800 Handle<String> name =
2767 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit")); 2801 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit"));
2768 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate); 2802 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate);
2769 JSObject::AddProperty(Error, name, stack_trace_limit, NONE); 2803 JSObject::AddProperty(Error, name, stack_trace_limit, NONE);
2770 2804
2771 // Expose the natives in global if a name for it is specified.
2772 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
2773 Handle<String> natives_key =
2774 factory->InternalizeUtf8String(FLAG_expose_natives_as);
2775 uint32_t dummy_index;
2776 if (natives_key->AsArrayIndex(&dummy_index)) return true;
2777 Handle<JSBuiltinsObject> natives(global->builtins());
2778 JSObject::AddProperty(global, natives_key, natives, DONT_ENUM);
2779 }
2780
2781 // Expose the debug global object in global if a name for it is specified. 2805 // Expose the debug global object in global if a name for it is specified.
2782 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { 2806 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) {
2783 // If loading fails we just bail out without installing the 2807 // If loading fails we just bail out without installing the
2784 // debugger but without tanking the whole context. 2808 // debugger but without tanking the whole context.
2785 Debug* debug = isolate->debug(); 2809 Debug* debug = isolate->debug();
2786 if (!debug->Load()) return true; 2810 if (!debug->Load()) return true;
2787 Handle<Context> debug_context = debug->debug_context(); 2811 Handle<Context> debug_context = debug->debug_context();
2788 // Set the security token for the debugger context to the same as 2812 // Set the security token for the debugger context to the same as
2789 // the shell native context to allow calling between these (otherwise 2813 // the shell native context to allow calling between these (otherwise
2790 // exposing debug global object doesn't make much sense). 2814 // exposing debug global object doesn't make much sense).
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
3214 native_context()->global_proxy()); 3238 native_context()->global_proxy());
3215 HookUpGlobalThisBinding(outdated_contexts); 3239 HookUpGlobalThisBinding(outdated_contexts);
3216 3240
3217 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3241 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3218 } else { 3242 } else {
3219 // We get here if there was no context snapshot. 3243 // We get here if there was no context snapshot.
3220 CreateRoots(); 3244 CreateRoots();
3221 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3245 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3222 CreateStrictModeFunctionMaps(empty_function); 3246 CreateStrictModeFunctionMaps(empty_function);
3223 CreateStrongModeFunctionMaps(empty_function); 3247 CreateStrongModeFunctionMaps(empty_function);
3248 CreateIteratorMaps();
3224 Handle<GlobalObject> global_object = 3249 Handle<GlobalObject> global_object =
3225 CreateNewGlobals(global_proxy_template, global_proxy); 3250 CreateNewGlobals(global_proxy_template, global_proxy);
3226 HookUpGlobalProxy(global_object, global_proxy); 3251 HookUpGlobalProxy(global_object, global_proxy);
3227 InitializeGlobal(global_object, empty_function, context_type); 3252 InitializeGlobal(global_object, empty_function, context_type);
3228 InitializeNormalizedMapCaches(); 3253 InitializeNormalizedMapCaches();
3229 3254
3230 if (!InstallNatives(context_type)) return; 3255 if (!InstallNatives(context_type)) return;
3231 3256
3232 MakeFunctionInstancePrototypeWritable(); 3257 MakeFunctionInstancePrototypeWritable();
3233 3258
3234 if (context_type != THIN_CONTEXT) { 3259 if (context_type != THIN_CONTEXT) {
3235 if (!InstallExtraNatives()) return; 3260 if (!InstallExtraNatives()) return;
3236 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3261 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3237 } 3262 }
3238 isolate->counters()->contexts_created_from_scratch()->Increment(); 3263 isolate->counters()->contexts_created_from_scratch()->Increment();
3239 } 3264 }
3240 3265
3241 // Install experimental natives. Do not include them into the 3266 // Install experimental natives. Do not include them into the
3242 // snapshot as we should be able to turn them off at runtime. Re-installing 3267 // snapshot as we should be able to turn them off at runtime. Re-installing
3243 // them after they have already been deserialized would also fail. 3268 // them after they have already been deserialized would also fail.
3244 if (context_type == FULL_CONTEXT) { 3269 if (context_type == FULL_CONTEXT) {
3245 if (!isolate->serializer_enabled()) { 3270 if (!isolate->serializer_enabled()) {
3246 InitializeExperimentalGlobal(); 3271 InitializeExperimentalGlobal();
3247 if (!InstallExperimentalNatives()) return; 3272 if (!InstallExperimentalNatives()) return;
3248 3273
3249 if (FLAG_experimental_extras) { 3274 if (FLAG_experimental_extras) {
3250 if (!InstallExperimentalExtraNatives()) return; 3275 if (!InstallExperimentalExtraNatives()) return;
3251 } 3276 }
3252
3253 // By now the utils object is useless and can be removed.
3254 native_context()->set_natives_utils_object(
3255 isolate->heap()->undefined_value());
3256 } 3277 }
3257 // The serializer cannot serialize typed arrays. Reset those typed arrays 3278 // The serializer cannot serialize typed arrays. Reset those typed arrays
3258 // for each new context. 3279 // for each new context.
3259 InitializeBuiltinTypedArrays(); 3280 InitializeBuiltinTypedArrays();
3260 } else if (context_type == DEBUG_CONTEXT) { 3281 } else if (context_type == DEBUG_CONTEXT) {
3261 DCHECK(!isolate->serializer_enabled()); 3282 DCHECK(!isolate->serializer_enabled());
3262 InitializeExperimentalGlobal(); 3283 InitializeExperimentalGlobal();
3263 if (!InstallDebuggerNatives()) return; 3284 if (!InstallDebuggerNatives()) return;
3264 } 3285 }
3265 3286
3287 ConfigureUtilsObject(context_type);
3288
3266 // Check that the script context table is empty except for the 'this' binding. 3289 // Check that the script context table is empty except for the 'this' binding.
3267 // We do not need script contexts for native scripts. 3290 // We do not need script contexts for native scripts.
3268 if (!FLAG_global_var_shortcuts) { 3291 if (!FLAG_global_var_shortcuts) {
3269 DCHECK_EQ(1, native_context()->script_context_table()->used()); 3292 DCHECK_EQ(1, native_context()->script_context_table()->used());
3270 } 3293 }
3271 3294
3272 result_ = native_context(); 3295 result_ = native_context();
3273 } 3296 }
3274 3297
3275 3298
(...skipping 20 matching lines...) Expand all
3296 } 3319 }
3297 3320
3298 3321
3299 // Called when the top-level V8 mutex is destroyed. 3322 // Called when the top-level V8 mutex is destroyed.
3300 void Bootstrapper::FreeThreadResources() { 3323 void Bootstrapper::FreeThreadResources() {
3301 DCHECK(!IsActive()); 3324 DCHECK(!IsActive());
3302 } 3325 }
3303 3326
3304 } // namespace internal 3327 } // namespace internal
3305 } // namespace v8 3328 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698