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/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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 is can be removed for cases that reach this point. | |
Camillo Bruni
2015/10/16 08:34:00
"... is can ..." => "... can ..."
| |
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 Loading... | |
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 { | |
1926 PrototypeIterator iter( | |
1927 isolate->native_context()->generator_object_prototype_map()); | |
1928 iter.Advance(); // Advance to the prototype of generator_object_prototype. | |
1929 Handle<JSObject> iterator_prototype(iter.GetCurrent<JSObject>()); | |
1930 | |
1931 JSObject::AddProperty(container, isolate->factory()->InternalizeUtf8String( | |
1932 "IteratorPrototype"), | |
1933 iterator_prototype, NONE); | |
1934 } | |
1935 | |
1936 { | |
1937 PrototypeIterator iter( | |
1938 isolate->native_context()->sloppy_generator_function_map()); | |
1939 Handle<JSObject> generator_function_prototype(iter.GetCurrent<JSObject>()); | |
1940 | |
1941 JSObject::AddProperty(container, isolate->factory()->InternalizeUtf8String( | |
1942 "GeneratorFunctionPrototype"), | |
1943 generator_function_prototype, NONE); | |
1944 | |
1945 static const bool kUseStrictFunctionMap = true; | |
1946 Handle<JSFunction> generator_function_function = | |
1947 InstallFunction(container, "GeneratorFunction", JS_FUNCTION_TYPE, | |
1948 JSFunction::kSize, generator_function_prototype, | |
1949 Builtins::kIllegal, kUseStrictFunctionMap); | |
1950 generator_function_function->initial_map()->set_is_callable(); | |
1951 } | |
1952 | |
1953 { // -- S e t I t e r a t o r | |
1954 Handle<JSFunction> set_iterator_function = InstallFunction( | |
1955 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, | |
1956 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1957 isolate->native_context()->set_set_iterator_map( | |
1958 set_iterator_function->initial_map()); | |
1959 } | |
1960 | |
1961 { // -- M a p I t e r a t o r | |
1962 Handle<JSFunction> map_iterator_function = InstallFunction( | |
1963 container, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize, | |
1964 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1965 isolate->native_context()->set_map_iterator_map( | |
1966 map_iterator_function->initial_map()); | |
1967 } | |
1840 } | 1968 } |
1841 | 1969 |
1842 | 1970 |
1843 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, | 1971 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, |
1844 Handle<JSObject> container) { | 1972 Handle<JSObject> container) { |
1845 HandleScope scope(isolate); | 1973 HandleScope scope(isolate); |
1846 | 1974 |
1847 #define INITIALIZE_FLAG(FLAG) \ | 1975 #define INITIALIZE_FLAG(FLAG) \ |
1848 { \ | 1976 { \ |
1849 Handle<String> name = \ | 1977 Handle<String> name = \ |
1850 isolate->factory()->NewStringFromAsciiChecked(#FLAG); \ | 1978 isolate->factory()->NewStringFromAsciiChecked(#FLAG); \ |
1851 JSObject::AddProperty(container, name, \ | 1979 JSObject::AddProperty(container, name, \ |
1852 isolate->factory()->ToBoolean(FLAG), NONE); \ | 1980 isolate->factory()->ToBoolean(FLAG), NONE); \ |
1853 } | 1981 } |
1854 | 1982 |
1855 INITIALIZE_FLAG(FLAG_harmony_regexps) | 1983 INITIALIZE_FLAG(FLAG_harmony_regexps) |
1856 INITIALIZE_FLAG(FLAG_harmony_unicode_regexps) | 1984 INITIALIZE_FLAG(FLAG_harmony_unicode_regexps) |
1857 INITIALIZE_FLAG(FLAG_harmony_tostring) | 1985 INITIALIZE_FLAG(FLAG_harmony_tostring) |
1986 INITIALIZE_FLAG(FLAG_harmony_tolength) | |
1858 | 1987 |
1859 #undef INITIALIZE_FLAG | 1988 #undef INITIALIZE_FLAG |
1860 } | 1989 } |
1861 | 1990 |
1862 | 1991 |
1863 #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \ | 1992 #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \ |
1864 void Genesis::InitializeGlobal_##id() {} | 1993 void Genesis::InitializeGlobal_##id() {} |
1865 | 1994 |
1866 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules) | 1995 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules) |
1867 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes) | 1996 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes) |
1868 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies) | 1997 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies) |
1869 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy) | 1998 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy) |
1870 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function) | 1999 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function) |
1871 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let) | 2000 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let) |
1872 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters) | 2001 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters) |
1873 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters) | 2002 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters) |
1874 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_calls) | 2003 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_calls) |
1875 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring) | 2004 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring) |
1876 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe) | 2005 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe) |
1877 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_arrays) | 2006 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_arrays) |
1878 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_new_target) | 2007 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_new_target) |
1879 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_concat_spreadable) | 2008 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_concat_spreadable) |
1880 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps) | 2009 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps) |
1881 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps) | 2010 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps) |
1882 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tostring) | 2011 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tostring) |
1883 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_completion) | 2012 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_completion) |
1884 | 2013 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 | 2014 |
1894 | 2015 |
1895 static void SimpleInstallFunction(Handle<JSObject>& base, const char* name, | 2016 static void SimpleInstallFunction(Handle<JSObject>& base, const char* name, |
1896 Builtins::Name call, int len, bool adapt) { | 2017 Builtins::Name call, int len, bool adapt) { |
1897 Handle<JSFunction> fun = | 2018 Handle<JSFunction> fun = |
1898 InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, | 2019 InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, |
1899 MaybeHandle<JSObject>(), call); | 2020 MaybeHandle<JSObject>(), call); |
1900 if (adapt) { | 2021 if (adapt) { |
1901 fun->shared()->set_internal_formal_parameter_count(len); | 2022 fun->shared()->set_internal_formal_parameter_count(len); |
1902 } else { | 2023 } else { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2073 int builtin_index = Natives::GetDebuggerCount(); | 2194 int builtin_index = Natives::GetDebuggerCount(); |
2074 // Only run prologue.js and runtime.js at this point. | 2195 // Only run prologue.js and runtime.js at this point. |
2075 DCHECK_EQ(builtin_index, Natives::GetIndex("prologue")); | 2196 DCHECK_EQ(builtin_index, Natives::GetIndex("prologue")); |
2076 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; | 2197 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
2077 DCHECK_EQ(builtin_index, Natives::GetIndex("runtime")); | 2198 DCHECK_EQ(builtin_index, Natives::GetIndex("runtime")); |
2078 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; | 2199 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
2079 | 2200 |
2080 // A thin context is ready at this point. | 2201 // A thin context is ready at this point. |
2081 if (context_type == THIN_CONTEXT) return true; | 2202 if (context_type == THIN_CONTEXT) return true; |
2082 | 2203 |
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 | 2204 { // -- S c r i p t |
2089 // Builtin functions for Script. | 2205 // Builtin functions for Script. |
2090 Handle<JSFunction> script_fun = InstallFunction( | 2206 Handle<JSFunction> script_fun = InstallFunction( |
2091 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, | 2207 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, |
2092 isolate()->initial_object_prototype(), Builtins::kIllegal); | 2208 isolate()->initial_object_prototype(), Builtins::kIllegal); |
2093 Handle<JSObject> prototype = | 2209 Handle<JSObject> prototype = |
2094 factory()->NewJSObject(isolate()->object_function(), TENURED); | 2210 factory()->NewJSObject(isolate()->object_function(), TENURED); |
2095 Accessors::FunctionSetPrototype(script_fun, prototype).Assert(); | 2211 Accessors::FunctionSetPrototype(script_fun, prototype).Assert(); |
2096 native_context()->set_script_function(*script_fun); | 2212 native_context()->set_script_function(*script_fun); |
2097 | 2213 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2254 { | 2370 { |
2255 HandleScope scope(isolate()); | 2371 HandleScope scope(isolate()); |
2256 Handle<JSObject> utils = | 2372 Handle<JSObject> utils = |
2257 Handle<JSObject>::cast(isolate()->natives_utils_object()); | 2373 Handle<JSObject>::cast(isolate()->natives_utils_object()); |
2258 Handle<JSFunction> array_function = | 2374 Handle<JSFunction> array_function = |
2259 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS); | 2375 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS); |
2260 native_context()->set_internal_array_function(*array_function); | 2376 native_context()->set_internal_array_function(*array_function); |
2261 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); | 2377 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); |
2262 } | 2378 } |
2263 | 2379 |
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. | 2380 // Run the rest of the native scripts. |
2355 while (builtin_index < Natives::GetBuiltinsCount()) { | 2381 while (builtin_index < Natives::GetBuiltinsCount()) { |
2356 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; | 2382 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
2357 } | 2383 } |
2358 | 2384 |
2359 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; | 2385 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; |
2360 | 2386 |
2361 auto function_cache = | 2387 auto function_cache = |
2362 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize, | 2388 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize, |
2363 USE_CUSTOM_MINIMUM_CAPACITY); | 2389 USE_CUSTOM_MINIMUM_CAPACITY); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2761 Handle<JSGlobalObject> global(JSGlobalObject::cast( | 2787 Handle<JSGlobalObject> global(JSGlobalObject::cast( |
2762 native_context->global_object())); | 2788 native_context->global_object())); |
2763 | 2789 |
2764 Handle<JSObject> Error = Handle<JSObject>::cast( | 2790 Handle<JSObject> Error = Handle<JSObject>::cast( |
2765 Object::GetProperty(isolate, global, "Error").ToHandleChecked()); | 2791 Object::GetProperty(isolate, global, "Error").ToHandleChecked()); |
2766 Handle<String> name = | 2792 Handle<String> name = |
2767 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit")); | 2793 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit")); |
2768 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate); | 2794 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate); |
2769 JSObject::AddProperty(Error, name, stack_trace_limit, NONE); | 2795 JSObject::AddProperty(Error, name, stack_trace_limit, NONE); |
2770 | 2796 |
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. | 2797 // 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) { | 2798 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { |
2783 // If loading fails we just bail out without installing the | 2799 // If loading fails we just bail out without installing the |
2784 // debugger but without tanking the whole context. | 2800 // debugger but without tanking the whole context. |
2785 Debug* debug = isolate->debug(); | 2801 Debug* debug = isolate->debug(); |
2786 if (!debug->Load()) return true; | 2802 if (!debug->Load()) return true; |
2787 Handle<Context> debug_context = debug->debug_context(); | 2803 Handle<Context> debug_context = debug->debug_context(); |
2788 // Set the security token for the debugger context to the same as | 2804 // Set the security token for the debugger context to the same as |
2789 // the shell native context to allow calling between these (otherwise | 2805 // the shell native context to allow calling between these (otherwise |
2790 // exposing debug global object doesn't make much sense). | 2806 // exposing debug global object doesn't make much sense). |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3214 native_context()->global_proxy()); | 3230 native_context()->global_proxy()); |
3215 HookUpGlobalThisBinding(outdated_contexts); | 3231 HookUpGlobalThisBinding(outdated_contexts); |
3216 | 3232 |
3217 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3233 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
3218 } else { | 3234 } else { |
3219 // We get here if there was no context snapshot. | 3235 // We get here if there was no context snapshot. |
3220 CreateRoots(); | 3236 CreateRoots(); |
3221 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 3237 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
3222 CreateStrictModeFunctionMaps(empty_function); | 3238 CreateStrictModeFunctionMaps(empty_function); |
3223 CreateStrongModeFunctionMaps(empty_function); | 3239 CreateStrongModeFunctionMaps(empty_function); |
3240 CreateIteratorMaps(); | |
3224 Handle<GlobalObject> global_object = | 3241 Handle<GlobalObject> global_object = |
3225 CreateNewGlobals(global_proxy_template, global_proxy); | 3242 CreateNewGlobals(global_proxy_template, global_proxy); |
3226 HookUpGlobalProxy(global_object, global_proxy); | 3243 HookUpGlobalProxy(global_object, global_proxy); |
3227 InitializeGlobal(global_object, empty_function, context_type); | 3244 InitializeGlobal(global_object, empty_function, context_type); |
3228 InitializeNormalizedMapCaches(); | 3245 InitializeNormalizedMapCaches(); |
3229 | 3246 |
3230 if (!InstallNatives(context_type)) return; | 3247 if (!InstallNatives(context_type)) return; |
3231 | 3248 |
3232 MakeFunctionInstancePrototypeWritable(); | 3249 MakeFunctionInstancePrototypeWritable(); |
3233 | 3250 |
3234 if (context_type != THIN_CONTEXT) { | 3251 if (context_type != THIN_CONTEXT) { |
3235 if (!InstallExtraNatives()) return; | 3252 if (!InstallExtraNatives()) return; |
3236 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3253 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
3237 } | 3254 } |
3238 isolate->counters()->contexts_created_from_scratch()->Increment(); | 3255 isolate->counters()->contexts_created_from_scratch()->Increment(); |
3239 } | 3256 } |
3240 | 3257 |
3241 // Install experimental natives. Do not include them into the | 3258 // Install experimental natives. Do not include them into the |
3242 // snapshot as we should be able to turn them off at runtime. Re-installing | 3259 // 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. | 3260 // them after they have already been deserialized would also fail. |
3244 if (context_type == FULL_CONTEXT) { | 3261 if (context_type == FULL_CONTEXT) { |
3245 if (!isolate->serializer_enabled()) { | 3262 if (!isolate->serializer_enabled()) { |
3246 InitializeExperimentalGlobal(); | 3263 InitializeExperimentalGlobal(); |
3247 if (!InstallExperimentalNatives()) return; | 3264 if (!InstallExperimentalNatives()) return; |
3248 | 3265 |
3249 if (FLAG_experimental_extras) { | 3266 if (FLAG_experimental_extras) { |
3250 if (!InstallExperimentalExtraNatives()) return; | 3267 if (!InstallExperimentalExtraNatives()) return; |
3251 } | 3268 } |
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 } | 3269 } |
3257 // The serializer cannot serialize typed arrays. Reset those typed arrays | 3270 // The serializer cannot serialize typed arrays. Reset those typed arrays |
3258 // for each new context. | 3271 // for each new context. |
3259 InitializeBuiltinTypedArrays(); | 3272 InitializeBuiltinTypedArrays(); |
3260 } else if (context_type == DEBUG_CONTEXT) { | 3273 } else if (context_type == DEBUG_CONTEXT) { |
3261 DCHECK(!isolate->serializer_enabled()); | 3274 DCHECK(!isolate->serializer_enabled()); |
3262 InitializeExperimentalGlobal(); | 3275 InitializeExperimentalGlobal(); |
3263 if (!InstallDebuggerNatives()) return; | 3276 if (!InstallDebuggerNatives()) return; |
3264 } | 3277 } |
3265 | 3278 |
3279 ConfigureUtilsObject(context_type); | |
3280 | |
3266 // Check that the script context table is empty except for the 'this' binding. | 3281 // Check that the script context table is empty except for the 'this' binding. |
3267 // We do not need script contexts for native scripts. | 3282 // We do not need script contexts for native scripts. |
3268 if (!FLAG_global_var_shortcuts) { | 3283 if (!FLAG_global_var_shortcuts) { |
3269 DCHECK_EQ(1, native_context()->script_context_table()->used()); | 3284 DCHECK_EQ(1, native_context()->script_context_table()->used()); |
3270 } | 3285 } |
3271 | 3286 |
3272 result_ = native_context(); | 3287 result_ = native_context(); |
3273 } | 3288 } |
3274 | 3289 |
3275 | 3290 |
(...skipping 20 matching lines...) Expand all Loading... | |
3296 } | 3311 } |
3297 | 3312 |
3298 | 3313 |
3299 // Called when the top-level V8 mutex is destroyed. | 3314 // Called when the top-level V8 mutex is destroyed. |
3300 void Bootstrapper::FreeThreadResources() { | 3315 void Bootstrapper::FreeThreadResources() { |
3301 DCHECK(!IsActive()); | 3316 DCHECK(!IsActive()); |
3302 } | 3317 } |
3303 | 3318 |
3304 } // namespace internal | 3319 } // namespace internal |
3305 } // namespace v8 | 3320 } // namespace v8 |
OLD | NEW |