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/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
(...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1814 isolate->bootstrapper()->SourceLookup<Natives>(index); | 1814 isolate->bootstrapper()->SourceLookup<Natives>(index); |
1815 | 1815 |
1816 // We pass in extras_utils so that builtin code can set it up for later use | 1816 // We pass in extras_utils so that builtin code can set it up for later use |
1817 // by actual extras code, compiled with CompileExtraBuiltin. | 1817 // by actual extras code, compiled with CompileExtraBuiltin. |
1818 Handle<Object> global = isolate->global_object(); | 1818 Handle<Object> global = isolate->global_object(); |
1819 Handle<Object> utils = isolate->natives_utils_object(); | 1819 Handle<Object> utils = isolate->natives_utils_object(); |
1820 Handle<Object> extras_utils = isolate->extras_utils_object(); | 1820 Handle<Object> extras_utils = isolate->extras_utils_object(); |
1821 Handle<Object> args[] = {global, utils, extras_utils}; | 1821 Handle<Object> args[] = {global, utils, extras_utils}; |
1822 | 1822 |
1823 return Bootstrapper::CompileNative(isolate, name, source_code, | 1823 return Bootstrapper::CompileNative(isolate, name, source_code, |
1824 arraysize(args), args); | 1824 arraysize(args), args, NATIVES_CODE); |
1825 } | 1825 } |
1826 | 1826 |
1827 | 1827 |
1828 bool Bootstrapper::CompileExperimentalBuiltin(Isolate* isolate, int index) { | 1828 bool Bootstrapper::CompileExperimentalBuiltin(Isolate* isolate, int index) { |
1829 HandleScope scope(isolate); | 1829 HandleScope scope(isolate); |
1830 Vector<const char> name = ExperimentalNatives::GetScriptName(index); | 1830 Vector<const char> name = ExperimentalNatives::GetScriptName(index); |
1831 Handle<String> source_code = | 1831 Handle<String> source_code = |
1832 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); | 1832 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); |
1833 Handle<Object> global = isolate->global_object(); | 1833 Handle<Object> global = isolate->global_object(); |
1834 Handle<Object> utils = isolate->natives_utils_object(); | 1834 Handle<Object> utils = isolate->natives_utils_object(); |
1835 Handle<Object> args[] = {global, utils}; | 1835 Handle<Object> args[] = {global, utils}; |
1836 return Bootstrapper::CompileNative(isolate, name, source_code, | 1836 return Bootstrapper::CompileNative(isolate, name, source_code, |
1837 arraysize(args), args); | 1837 arraysize(args), args, NATIVES_CODE); |
1838 } | 1838 } |
1839 | 1839 |
1840 | 1840 |
1841 bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) { | 1841 bool Bootstrapper::CompileExtraBuiltin(Isolate* isolate, int index) { |
1842 HandleScope scope(isolate); | 1842 HandleScope scope(isolate); |
1843 Vector<const char> name = ExtraNatives::GetScriptName(index); | 1843 Vector<const char> name = ExtraNatives::GetScriptName(index); |
1844 Handle<String> source_code = | 1844 Handle<String> source_code = |
1845 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); | 1845 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); |
1846 Handle<Object> global = isolate->global_object(); | 1846 Handle<Object> global = isolate->global_object(); |
1847 Handle<Object> binding = isolate->extras_binding_object(); | 1847 Handle<Object> binding = isolate->extras_binding_object(); |
1848 Handle<Object> extras_utils = isolate->extras_utils_object(); | 1848 Handle<Object> extras_utils = isolate->extras_utils_object(); |
1849 Handle<Object> args[] = {global, binding, extras_utils}; | 1849 Handle<Object> args[] = {global, binding, extras_utils}; |
1850 return Bootstrapper::CompileNative(isolate, name, source_code, | 1850 return Bootstrapper::CompileNative(isolate, name, source_code, |
1851 arraysize(args), args); | 1851 arraysize(args), args, EXTENSION_CODE); |
1852 } | 1852 } |
1853 | 1853 |
1854 | 1854 |
1855 bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate, | 1855 bool Bootstrapper::CompileExperimentalExtraBuiltin(Isolate* isolate, |
1856 int index) { | 1856 int index) { |
1857 HandleScope scope(isolate); | 1857 HandleScope scope(isolate); |
1858 Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index); | 1858 Vector<const char> name = ExperimentalExtraNatives::GetScriptName(index); |
1859 Handle<String> source_code = | 1859 Handle<String> source_code = |
1860 isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index); | 1860 isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index); |
1861 Handle<Object> global = isolate->global_object(); | 1861 Handle<Object> global = isolate->global_object(); |
1862 Handle<Object> binding = isolate->extras_binding_object(); | 1862 Handle<Object> binding = isolate->extras_binding_object(); |
1863 Handle<Object> extras_utils = isolate->extras_utils_object(); | 1863 Handle<Object> extras_utils = isolate->extras_utils_object(); |
1864 Handle<Object> args[] = {global, binding, extras_utils}; | 1864 Handle<Object> args[] = {global, binding, extras_utils}; |
1865 return Bootstrapper::CompileNative(isolate, name, source_code, | 1865 return Bootstrapper::CompileNative(isolate, name, source_code, |
1866 arraysize(args), args); | 1866 arraysize(args), args, EXTENSION_CODE); |
1867 } | 1867 } |
1868 | 1868 |
1869 | |
1870 bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, | 1869 bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, |
1871 Handle<String> source, int argc, | 1870 Handle<String> source, int argc, |
1872 Handle<Object> argv[]) { | 1871 Handle<Object> argv[], |
| 1872 NativesFlag natives_flag) { |
1873 SuppressDebug compiling_natives(isolate->debug()); | 1873 SuppressDebug compiling_natives(isolate->debug()); |
1874 // During genesis, the boilerplate for stack overflow won't work until the | 1874 // During genesis, the boilerplate for stack overflow won't work until the |
1875 // environment has been at least partially initialized. Add a stack check | 1875 // environment has been at least partially initialized. Add a stack check |
1876 // before entering JS code to catch overflow early. | 1876 // before entering JS code to catch overflow early. |
1877 StackLimitCheck check(isolate); | 1877 StackLimitCheck check(isolate); |
1878 if (check.JsHasOverflowed(1 * KB)) { | 1878 if (check.JsHasOverflowed(1 * KB)) { |
1879 isolate->StackOverflow(); | 1879 isolate->StackOverflow(); |
1880 return false; | 1880 return false; |
1881 } | 1881 } |
1882 | 1882 |
1883 Handle<Context> context(isolate->context()); | 1883 Handle<Context> context(isolate->context()); |
1884 | 1884 |
1885 Handle<String> script_name = | 1885 Handle<String> script_name = |
1886 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked(); | 1886 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked(); |
1887 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript( | 1887 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript( |
1888 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), | 1888 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), |
1889 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, | 1889 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, natives_flag, |
1890 false); | 1890 false); |
1891 if (function_info.is_null()) return false; | 1891 if (function_info.is_null()) return false; |
1892 | 1892 |
1893 DCHECK(context->IsNativeContext()); | 1893 DCHECK(context->IsNativeContext()); |
1894 | 1894 |
1895 Handle<JSFunction> fun = | 1895 Handle<JSFunction> fun = |
1896 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info, | 1896 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info, |
1897 context); | 1897 context); |
1898 Handle<Object> receiver = isolate->factory()->undefined_value(); | 1898 Handle<Object> receiver = isolate->factory()->undefined_value(); |
1899 | 1899 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache(); | 1937 SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache(); |
1938 Handle<Context> context(isolate->context()); | 1938 Handle<Context> context(isolate->context()); |
1939 DCHECK(context->IsNativeContext()); | 1939 DCHECK(context->IsNativeContext()); |
1940 | 1940 |
1941 if (!cache->Lookup(name, &function_info)) { | 1941 if (!cache->Lookup(name, &function_info)) { |
1942 Handle<String> script_name = | 1942 Handle<String> script_name = |
1943 factory->NewStringFromUtf8(name).ToHandleChecked(); | 1943 factory->NewStringFromUtf8(name).ToHandleChecked(); |
1944 function_info = Compiler::CompileScript( | 1944 function_info = Compiler::CompileScript( |
1945 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), | 1945 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), |
1946 context, extension, NULL, ScriptCompiler::kNoCompileOptions, | 1946 context, extension, NULL, ScriptCompiler::kNoCompileOptions, |
1947 NOT_NATIVES_CODE, false); | 1947 EXTENSION_CODE, false); |
1948 if (function_info.is_null()) return false; | 1948 if (function_info.is_null()) return false; |
1949 cache->Add(name, function_info); | 1949 cache->Add(name, function_info); |
1950 } | 1950 } |
1951 | 1951 |
1952 // Set up the function context. Conceptually, we should clone the | 1952 // Set up the function context. Conceptually, we should clone the |
1953 // function before overwriting the context but since we're in a | 1953 // function before overwriting the context but since we're in a |
1954 // single-threaded environment it is not strictly necessary. | 1954 // single-threaded environment it is not strictly necessary. |
1955 Handle<JSFunction> fun = | 1955 Handle<JSFunction> fun = |
1956 factory->NewFunctionFromSharedFunctionInfo(function_info, context); | 1956 factory->NewFunctionFromSharedFunctionInfo(function_info, context); |
1957 | 1957 |
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3630 } | 3630 } |
3631 | 3631 |
3632 | 3632 |
3633 // Called when the top-level V8 mutex is destroyed. | 3633 // Called when the top-level V8 mutex is destroyed. |
3634 void Bootstrapper::FreeThreadResources() { | 3634 void Bootstrapper::FreeThreadResources() { |
3635 DCHECK(!IsActive()); | 3635 DCHECK(!IsActive()); |
3636 } | 3636 } |
3637 | 3637 |
3638 } // namespace internal | 3638 } // namespace internal |
3639 } // namespace v8 | 3639 } // namespace v8 |
OLD | NEW |