OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
11 #include <cmath> // For isnan. | 11 #include <cmath> // For isnan. |
12 #include "include/v8-debug.h" | 12 #include "include/v8-debug.h" |
13 #include "include/v8-profiler.h" | 13 #include "include/v8-profiler.h" |
14 #include "include/v8-testing.h" | 14 #include "include/v8-testing.h" |
15 #include "src/assert-scope.h" | 15 #include "src/assert-scope.h" |
16 #include "src/background-parsing-task.h" | |
17 #include "src/base/platform/platform.h" | 16 #include "src/base/platform/platform.h" |
18 #include "src/base/platform/time.h" | 17 #include "src/base/platform/time.h" |
19 #include "src/base/utils/random-number-generator.h" | 18 #include "src/base/utils/random-number-generator.h" |
20 #include "src/bootstrapper.h" | 19 #include "src/bootstrapper.h" |
21 #include "src/code-stubs.h" | 20 #include "src/code-stubs.h" |
22 #include "src/compiler.h" | 21 #include "src/compiler.h" |
23 #include "src/conversions-inl.h" | 22 #include "src/conversions-inl.h" |
24 #include "src/counters.h" | 23 #include "src/counters.h" |
25 #include "src/cpu-profiler.h" | 24 #include "src/cpu-profiler.h" |
26 #include "src/debug.h" | 25 #include "src/debug.h" |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 : data(data_), length(length_), buffer_policy(buffer_policy_) {} | 1593 : data(data_), length(length_), buffer_policy(buffer_policy_) {} |
1595 | 1594 |
1596 | 1595 |
1597 ScriptCompiler::CachedData::~CachedData() { | 1596 ScriptCompiler::CachedData::~CachedData() { |
1598 if (buffer_policy == BufferOwned) { | 1597 if (buffer_policy == BufferOwned) { |
1599 delete[] data; | 1598 delete[] data; |
1600 } | 1599 } |
1601 } | 1600 } |
1602 | 1601 |
1603 | 1602 |
1604 ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream, | |
1605 Encoding encoding) | |
1606 : impl_(new i::StreamedSource(stream, encoding)) {} | |
1607 | |
1608 | |
1609 ScriptCompiler::StreamedSource::~StreamedSource() { delete impl_; } | |
1610 | |
1611 | |
1612 const ScriptCompiler::CachedData* | |
1613 ScriptCompiler::StreamedSource::GetCachedData() const { | |
1614 return impl_->cached_data.get(); | |
1615 } | |
1616 | |
1617 | |
1618 Local<Script> UnboundScript::BindToCurrentContext() { | 1603 Local<Script> UnboundScript::BindToCurrentContext() { |
1619 i::Handle<i::HeapObject> obj = | 1604 i::Handle<i::HeapObject> obj = |
1620 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1605 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
1621 i::Handle<i::SharedFunctionInfo> | 1606 i::Handle<i::SharedFunctionInfo> |
1622 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); | 1607 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); |
1623 i::Handle<i::JSFunction> function = | 1608 i::Handle<i::JSFunction> function = |
1624 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( | 1609 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( |
1625 function_info, obj->GetIsolate()->global_context()); | 1610 function_info, obj->GetIsolate()->global_context()); |
1626 return ToApiHandle<Script>(function); | 1611 return ToApiHandle<Script>(function); |
1627 } | 1612 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1807 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1823 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); | 1808 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); |
1824 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); | 1809 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); |
1825 ENTER_V8(isolate); | 1810 ENTER_V8(isolate); |
1826 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); | 1811 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); |
1827 if (generic.IsEmpty()) return Local<Script>(); | 1812 if (generic.IsEmpty()) return Local<Script>(); |
1828 return generic->BindToCurrentContext(); | 1813 return generic->BindToCurrentContext(); |
1829 } | 1814 } |
1830 | 1815 |
1831 | 1816 |
1832 ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( | |
1833 Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { | |
1834 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | |
1835 if (!isolate->global_context().is_null() && | |
1836 !isolate->global_context()->IsNativeContext()) { | |
1837 // The context chain is non-trivial, and constructing the corresponding | |
1838 // non-trivial Scope chain outside the V8 heap is not implemented. Don't | |
1839 // stream the script. This will only occur if Harmony scoping is enabled and | |
1840 // a previous script has introduced "let" or "const" variables. TODO(marja): | |
1841 // Implement externalizing ScopeInfos and constructing non-trivial Scope | |
1842 // chains independent of the V8 heap so that we can stream also in this | |
1843 // case. | |
1844 return NULL; | |
1845 } | |
1846 return new i::BackgroundParsingTask(source->impl(), options, | |
1847 i::FLAG_stack_size, isolate); | |
1848 } | |
1849 | |
1850 | |
1851 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, | |
1852 StreamedSource* v8_source, | |
1853 Handle<String> full_source_string, | |
1854 const ScriptOrigin& origin) { | |
1855 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | |
1856 i::StreamedSource* source = v8_source->impl(); | |
1857 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); | |
1858 LOG_API(isolate, "ScriptCompiler::Compile()"); | |
1859 ENTER_V8(isolate); | |
1860 i::SharedFunctionInfo* raw_result = NULL; | |
1861 | |
1862 { | |
1863 i::HandleScope scope(isolate); | |
1864 i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string)); | |
1865 i::Handle<i::Script> script = isolate->factory()->NewScript(str); | |
1866 if (!origin.ResourceName().IsEmpty()) { | |
1867 script->set_name(*Utils::OpenHandle(*(origin.ResourceName()))); | |
1868 } | |
1869 if (!origin.ResourceLineOffset().IsEmpty()) { | |
1870 script->set_line_offset(i::Smi::FromInt( | |
1871 static_cast<int>(origin.ResourceLineOffset()->Value()))); | |
1872 } | |
1873 if (!origin.ResourceColumnOffset().IsEmpty()) { | |
1874 script->set_column_offset(i::Smi::FromInt( | |
1875 static_cast<int>(origin.ResourceColumnOffset()->Value()))); | |
1876 } | |
1877 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) { | |
1878 script->set_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin() == | |
1879 v8::True(v8_isolate)); | |
1880 } | |
1881 source->info->set_script(script); | |
1882 source->info->SetContext(isolate->global_context()); | |
1883 | |
1884 EXCEPTION_PREAMBLE(isolate); | |
1885 | |
1886 // Do the parsing tasks which need to be done on the main thread. This will | |
1887 // also handle parse errors. | |
1888 source->parser->Internalize(); | |
1889 | |
1890 i::Handle<i::SharedFunctionInfo> result = | |
1891 i::Handle<i::SharedFunctionInfo>::null(); | |
1892 if (source->info->function() != NULL) { | |
1893 // Parsing has succeeded. | |
1894 result = | |
1895 i::Compiler::CompileStreamedScript(source->info.get(), str->length()); | |
1896 } | |
1897 has_pending_exception = result.is_null(); | |
1898 if (has_pending_exception) isolate->ReportPendingMessages(); | |
1899 EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); | |
1900 | |
1901 raw_result = *result; | |
1902 // The Handle<Script> will go out of scope soon; make sure CompilationInfo | |
1903 // doesn't point to it. | |
1904 source->info->set_script(i::Handle<i::Script>()); | |
1905 } // HandleScope goes out of scope. | |
1906 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); | |
1907 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result); | |
1908 if (generic.IsEmpty()) { | |
1909 return Local<Script>(); | |
1910 } | |
1911 return generic->BindToCurrentContext(); | |
1912 } | |
1913 | |
1914 | |
1915 Local<Script> Script::Compile(v8::Handle<String> source, | 1817 Local<Script> Script::Compile(v8::Handle<String> source, |
1916 v8::ScriptOrigin* origin) { | 1818 v8::ScriptOrigin* origin) { |
1917 i::Handle<i::String> str = Utils::OpenHandle(*source); | 1819 i::Handle<i::String> str = Utils::OpenHandle(*source); |
1918 if (origin) { | 1820 if (origin) { |
1919 ScriptCompiler::Source script_source(source, *origin); | 1821 ScriptCompiler::Source script_source(source, *origin); |
1920 return ScriptCompiler::Compile( | 1822 return ScriptCompiler::Compile( |
1921 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), | 1823 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), |
1922 &script_source); | 1824 &script_source); |
1923 } | 1825 } |
1924 ScriptCompiler::Source script_source(source); | 1826 ScriptCompiler::Source script_source(source); |
(...skipping 5793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7718 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7620 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7719 Address callback_address = | 7621 Address callback_address = |
7720 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7622 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7721 VMState<EXTERNAL> state(isolate); | 7623 VMState<EXTERNAL> state(isolate); |
7722 ExternalCallbackScope call_scope(isolate, callback_address); | 7624 ExternalCallbackScope call_scope(isolate, callback_address); |
7723 callback(info); | 7625 callback(info); |
7724 } | 7626 } |
7725 | 7627 |
7726 | 7628 |
7727 } } // namespace v8::internal | 7629 } } // namespace v8::internal |
OLD | NEW |