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

Side by Side Diff: src/bootstrapper.cc

Issue 1318043002: Native context: do not put public symbols and flags on the js builtins object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix and rebase Created 5 years, 3 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 | « src/bootstrapper.h ('k') | src/collection.js » ('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 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 { // Initialize a result array for rempio2 calculation 1749 { // Initialize a result array for rempio2 calculation
1750 const size_t num_elements = 2; 1750 const size_t num_elements = 2;
1751 double* data = 1751 double* data =
1752 SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array, 1752 SetBuiltinTypedArray<double>(isolate(), builtins, kExternalFloat64Array,
1753 NULL, num_elements, "rempio2result"); 1753 NULL, num_elements, "rempio2result");
1754 for (size_t i = 0; i < num_elements; i++) data[i] = 0; 1754 for (size_t i = 0; i < num_elements; i++) data[i] = 0;
1755 } 1755 }
1756 } 1756 }
1757 1757
1758 1758
1759 void Bootstrapper::ExportPrivateSymbols(Isolate* isolate, 1759 void Bootstrapper::ExportFromRuntime(Isolate* isolate,
1760 Handle<JSObject> container) { 1760 Handle<JSObject> container) {
1761 HandleScope scope(isolate); 1761 HandleScope scope(isolate);
1762 #define EXPORT_PRIVATE_SYMBOL(NAME) \ 1762 #define EXPORT_PRIVATE_SYMBOL(NAME) \
1763 Handle<String> NAME##_name = \ 1763 Handle<String> NAME##_name = \
1764 isolate->factory()->NewStringFromAsciiChecked(#NAME); \ 1764 isolate->factory()->NewStringFromAsciiChecked(#NAME); \
1765 JSObject::AddProperty(container, NAME##_name, isolate->factory()->NAME(), \ 1765 JSObject::AddProperty(container, NAME##_name, isolate->factory()->NAME(), \
1766 NONE); 1766 NONE);
1767 PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL)
1768 #undef EXPORT_PRIVATE_SYMBOL
1767 1769
1768 PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL) 1770 #define EXPORT_PUBLIC_SYMBOL(NAME, DESCRIPTION) \
1771 Handle<String> NAME##_name = \
1772 isolate->factory()->NewStringFromAsciiChecked(#NAME); \
1773 JSObject::AddProperty(container, NAME##_name, isolate->factory()->NAME(), \
1774 NONE);
1775 PUBLIC_SYMBOL_LIST(EXPORT_PUBLIC_SYMBOL)
1776 #undef EXPORT_PUBLIC_SYMBOL
1769 1777
1770 #undef EXPORT_PRIVATE_SYMBOL 1778 Handle<JSFunction> apply = InstallFunction(
1779 container, "reflect_apply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1780 MaybeHandle<JSObject>(), Builtins::kReflectApply);
1781 apply->shared()->set_internal_formal_parameter_count(3);
1782 apply->shared()->set_length(3);
1783 isolate->native_context()->set_reflect_apply(*apply);
1784
1785 Handle<JSFunction> construct = InstallFunction(
1786 container, "reflect_construct", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1787 MaybeHandle<JSObject>(), Builtins::kReflectConstruct);
1788 construct->shared()->set_internal_formal_parameter_count(3);
1789 construct->shared()->set_length(2);
1790 isolate->native_context()->set_reflect_construct(*construct);
1771 } 1791 }
1772 1792
1773 1793
1794 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
1795 Handle<JSObject> container) {
1796 HandleScope scope(isolate);
1797
1798 #define INITIALIZE_FLAG(FLAG) \
1799 { \
1800 Handle<String> name = \
1801 isolate->factory()->NewStringFromAsciiChecked(#FLAG); \
1802 JSObject::AddProperty(container, name, \
1803 isolate->factory()->ToBoolean(FLAG), NONE); \
1804 }
1805
1806 INITIALIZE_FLAG(FLAG_harmony_regexps)
1807 INITIALIZE_FLAG(FLAG_harmony_unicode_regexps)
1808 INITIALIZE_FLAG(FLAG_harmony_tostring)
1809
1810 #undef INITIALIZE_FLAG
1811 }
1812
1813
1774 #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \ 1814 #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
1775 void Genesis::InitializeGlobal_##id() {} 1815 void Genesis::InitializeGlobal_##id() {}
1776 1816
1777 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules) 1817 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules)
1778 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes) 1818 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes)
1779 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_arrow_functions) 1819 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_arrow_functions)
1780 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies) 1820 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies)
1781 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy) 1821 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy)
1782 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function) 1822 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function)
1783 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let) 1823 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let)
1784 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters) 1824 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters)
1785 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters) 1825 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_default_parameters)
1786 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spreadcalls) 1826 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spreadcalls)
1787 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring) 1827 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_destructuring)
1788 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object) 1828 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object)
1789 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe) 1829 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_object_observe)
1790 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_arrays) 1830 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_spread_arrays)
1791 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_atomics) 1831 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_atomics)
1792 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_new_target) 1832 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_new_target)
1793 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_concat_spreadable) 1833 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_concat_spreadable)
1794 1834 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexps)
1795 void Genesis::InitializeGlobal_harmony_regexps() { 1835 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps)
1796 Handle<JSObject> builtins(native_context()->builtins()); 1836 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_tostring)
1797
1798 Handle<HeapObject> flag(FLAG_harmony_regexps ? heap()->true_value()
1799 : heap()->false_value());
1800 Runtime::SetObjectProperty(isolate(), builtins,
1801 factory()->harmony_regexps_string(), flag,
1802 STRICT).Assert();
1803 }
1804
1805
1806 void Genesis::InitializeGlobal_harmony_unicode_regexps() {
1807 Handle<JSObject> builtins(native_context()->builtins());
1808
1809 Handle<HeapObject> flag(FLAG_harmony_unicode_regexps ? heap()->true_value()
1810 : heap()->false_value());
1811 Runtime::SetObjectProperty(isolate(), builtins,
1812 factory()->harmony_unicode_regexps_string(), flag,
1813 STRICT).Assert();
1814 }
1815 1837
1816 1838
1817 void Genesis::InitializeGlobal_harmony_reflect() { 1839 void Genesis::InitializeGlobal_harmony_reflect() {
1818 Handle<JSObject> builtins(native_context()->builtins());
1819
1820 Handle<JSFunction> apply = InstallFunction(
1821 builtins, "$reflectApply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1822 MaybeHandle<JSObject>(), Builtins::kReflectApply);
1823 apply->shared()->set_internal_formal_parameter_count(3);
1824 apply->shared()->set_length(3);
1825
1826 native_context()->set_reflect_apply(*apply);
1827
1828 Handle<JSFunction> construct = InstallFunction(
1829 builtins, "$reflectConstruct", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1830 MaybeHandle<JSObject>(), Builtins::kReflectConstruct);
1831 construct->shared()->set_internal_formal_parameter_count(3);
1832 construct->shared()->set_length(2);
1833
1834 native_context()->set_reflect_construct(*construct);
1835
1836 if (!FLAG_harmony_reflect) return; 1840 if (!FLAG_harmony_reflect) return;
1837 1841
1838 Handle<JSGlobalObject> global(JSGlobalObject::cast( 1842 Handle<JSGlobalObject> global(JSGlobalObject::cast(
1839 native_context()->global_object())); 1843 native_context()->global_object()));
1840 Handle<String> reflect_string = 1844 Handle<String> reflect_string =
1841 factory()->NewStringFromStaticChars("Reflect"); 1845 factory()->NewStringFromStaticChars("Reflect");
1842 Handle<Object> reflect = 1846 Handle<Object> reflect =
1843 factory()->NewJSObject(isolate()->object_function(), TENURED); 1847 factory()->NewJSObject(isolate()->object_function(), TENURED);
1844 JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM); 1848 JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM);
1845 } 1849 }
1846 1850
1847 1851
1848 void Genesis::InitializeGlobal_harmony_tostring() {
1849 Handle<JSObject> builtins(native_context()->builtins());
1850
1851 Handle<HeapObject> flag(FLAG_harmony_tostring ? heap()->true_value()
1852 : heap()->false_value());
1853 Runtime::SetObjectProperty(isolate(), builtins,
1854 factory()->harmony_tostring_string(), flag,
1855 STRICT).Assert();
1856 }
1857
1858 1852
1859 void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { 1853 void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
1860 if (!FLAG_harmony_sharedarraybuffer) return; 1854 if (!FLAG_harmony_sharedarraybuffer) return;
1861 1855
1862 Handle<JSGlobalObject> global( 1856 Handle<JSGlobalObject> global(
1863 JSGlobalObject::cast(native_context()->global_object())); 1857 JSGlobalObject::cast(native_context()->global_object()));
1864 1858
1865 Handle<JSFunction> shared_array_buffer_fun = InstallFunction( 1859 Handle<JSFunction> shared_array_buffer_fun = InstallFunction(
1866 global, "SharedArrayBuffer", JS_ARRAY_BUFFER_TYPE, 1860 global, "SharedArrayBuffer", JS_ARRAY_BUFFER_TYPE,
1867 JSArrayBuffer::kSizeWithInternalFields, 1861 JSArrayBuffer::kSizeWithInternalFields,
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
2270 generator_object_prototype); 2264 generator_object_prototype);
2271 native_context()->set_generator_object_prototype_map( 2265 native_context()->set_generator_object_prototype_map(
2272 *generator_object_prototype_map); 2266 *generator_object_prototype_map);
2273 } 2267 }
2274 2268
2275 if (FLAG_disable_native_files) { 2269 if (FLAG_disable_native_files) {
2276 PrintF("Warning: Running without installed natives!\n"); 2270 PrintF("Warning: Running without installed natives!\n");
2277 return true; 2271 return true;
2278 } 2272 }
2279 2273
2280 // Install public symbols.
2281 {
2282 static const PropertyAttributes attributes =
2283 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
2284 #define INSTALL_PUBLIC_SYMBOL(name, varname, description) \
2285 Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \
2286 JSObject::AddProperty(builtins, varname, factory()->name(), attributes);
2287 PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL)
2288 #undef INSTALL_PUBLIC_SYMBOL
2289 }
2290
2291 // Run the rest of the native scripts. 2274 // Run the rest of the native scripts.
2292 while (builtin_index < Natives::GetBuiltinsCount()) { 2275 while (builtin_index < Natives::GetBuiltinsCount()) {
2293 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; 2276 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
2294 } 2277 }
2295 2278
2296 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; 2279 if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
2297 2280
2298 auto function_cache = 2281 auto function_cache =
2299 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize, 2282 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize,
2300 USE_CUSTOM_MINIMUM_CAPACITY); 2283 USE_CUSTOM_MINIMUM_CAPACITY);
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
3168 } 3151 }
3169 3152
3170 3153
3171 // Called when the top-level V8 mutex is destroyed. 3154 // Called when the top-level V8 mutex is destroyed.
3172 void Bootstrapper::FreeThreadResources() { 3155 void Bootstrapper::FreeThreadResources() {
3173 DCHECK(!IsActive()); 3156 DCHECK(!IsActive());
3174 } 3157 }
3175 3158
3176 } // namespace internal 3159 } // namespace internal
3177 } // namespace v8 3160 } // namespace v8
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/collection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698