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" |
16 #include "src/base/platform/platform.h" | 17 #include "src/base/platform/platform.h" |
17 #include "src/base/platform/time.h" | 18 #include "src/base/platform/time.h" |
18 #include "src/base/utils/random-number-generator.h" | 19 #include "src/base/utils/random-number-generator.h" |
19 #include "src/bootstrapper.h" | 20 #include "src/bootstrapper.h" |
20 #include "src/code-stubs.h" | 21 #include "src/code-stubs.h" |
21 #include "src/compiler.h" | 22 #include "src/compiler.h" |
22 #include "src/conversions-inl.h" | 23 #include "src/conversions-inl.h" |
23 #include "src/counters.h" | 24 #include "src/counters.h" |
24 #include "src/cpu-profiler.h" | 25 #include "src/cpu-profiler.h" |
25 #include "src/debug.h" | 26 #include "src/debug.h" |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 : data(data_), length(length_), buffer_policy(buffer_policy_) {} | 1594 : data(data_), length(length_), buffer_policy(buffer_policy_) {} |
1594 | 1595 |
1595 | 1596 |
1596 ScriptCompiler::CachedData::~CachedData() { | 1597 ScriptCompiler::CachedData::~CachedData() { |
1597 if (buffer_policy == BufferOwned) { | 1598 if (buffer_policy == BufferOwned) { |
1598 delete[] data; | 1599 delete[] data; |
1599 } | 1600 } |
1600 } | 1601 } |
1601 | 1602 |
1602 | 1603 |
| 1604 ScriptCompiler::StreamedSource::~StreamedSource() { |
| 1605 delete source_stream; |
| 1606 delete cached_data; |
| 1607 delete info; |
| 1608 } |
| 1609 |
| 1610 |
1603 Local<Script> UnboundScript::BindToCurrentContext() { | 1611 Local<Script> UnboundScript::BindToCurrentContext() { |
1604 i::Handle<i::HeapObject> obj = | 1612 i::Handle<i::HeapObject> obj = |
1605 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); | 1613 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
1606 i::Handle<i::SharedFunctionInfo> | 1614 i::Handle<i::SharedFunctionInfo> |
1607 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); | 1615 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); |
1608 i::Handle<i::JSFunction> function = | 1616 i::Handle<i::JSFunction> function = |
1609 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( | 1617 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( |
1610 function_info, obj->GetIsolate()->global_context()); | 1618 function_info, obj->GetIsolate()->global_context()); |
1611 return ToApiHandle<Script>(function); | 1619 return ToApiHandle<Script>(function); |
1612 } | 1620 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1793 script_data->data(), script_data->length(), CachedData::BufferOwned); | 1801 script_data->data(), script_data->length(), CachedData::BufferOwned); |
1794 script_data->ReleaseDataOwnership(); | 1802 script_data->ReleaseDataOwnership(); |
1795 } | 1803 } |
1796 delete script_data; | 1804 delete script_data; |
1797 } | 1805 } |
1798 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); | 1806 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
1799 return ToApiHandle<UnboundScript>(result); | 1807 return ToApiHandle<UnboundScript>(result); |
1800 } | 1808 } |
1801 | 1809 |
1802 | 1810 |
| 1811 ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( |
| 1812 Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { |
| 1813 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 1814 if (!isolate->global_context().is_null() && |
| 1815 !isolate->global_context()->IsNativeContext()) { |
| 1816 // The context chain is non-trivial, and constructing the corresponding |
| 1817 // non-trivial Scope chain outside the V8 heap is not implemented. Don't |
| 1818 // stream the script. This will only occur if Harmony scoping is enabled and |
| 1819 // a previous script has introduced "let" or "const" variables. TODO(marja): |
| 1820 // Implement externalizing ScopeInfos and constructing non-trivial Scope |
| 1821 // chains independent of the V8 heap so that we can stream also in this |
| 1822 // case. |
| 1823 return NULL; |
| 1824 } |
| 1825 |
| 1826 source->info = new i::CompilationInfoWithZone(source->source_stream, isolate); |
| 1827 source->info->MarkAsGlobal(); |
| 1828 DCHECK(options == kProduceParserCache || options == kProduceCodeCache || |
| 1829 options == kNoCompileOptions); |
| 1830 bool allow_lazy = !i::Compiler::DebuggerWantsEagerCompilation(source->info); |
| 1831 i::BackgroundParsingTask* task = |
| 1832 new i::BackgroundParsingTask(source, allow_lazy, isolate); |
| 1833 if (options == kProduceParserCache || options == kProduceCodeCache) { |
| 1834 source->info->SetCachedData(&(task->script_data_), options); |
| 1835 } |
| 1836 // We don't set the context to the CompilationInfo yet, because the background |
| 1837 // thread cannot do anything with it anyway. We set it just before compilation |
| 1838 // on the foreground thread. |
| 1839 return task; |
| 1840 } |
| 1841 |
| 1842 |
| 1843 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate, |
| 1844 StreamedSource* source, |
| 1845 Handle<String> full_source_string, |
| 1846 const ScriptOrigin& origin) { |
| 1847 if (source->info->function() == NULL) { |
| 1848 // Parsing has failed. |
| 1849 return Local<Script>(); |
| 1850 } |
| 1851 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 1852 source->info->ast_value_factory()->Internalize(isolate); |
| 1853 |
| 1854 i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string)); |
| 1855 i::Handle<i::Script> script = isolate->factory()->NewScript(str); |
| 1856 if (!origin.ResourceName().IsEmpty()) { |
| 1857 script->set_name(*Utils::OpenHandle(*(origin.ResourceName()))); |
| 1858 } |
| 1859 if (!origin.ResourceLineOffset().IsEmpty()) { |
| 1860 script->set_line_offset(i::Smi::FromInt( |
| 1861 static_cast<int>(origin.ResourceLineOffset()->Value()))); |
| 1862 } |
| 1863 if (!origin.ResourceColumnOffset().IsEmpty()) { |
| 1864 script->set_column_offset(i::Smi::FromInt( |
| 1865 static_cast<int>(origin.ResourceColumnOffset()->Value()))); |
| 1866 } |
| 1867 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) { |
| 1868 script->set_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin() == |
| 1869 v8::True(v8_isolate)); |
| 1870 } |
| 1871 source->info->set_script(script); |
| 1872 source->info->SetContext(isolate->global_context()); |
| 1873 |
| 1874 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); |
| 1875 LOG_API(isolate, "ScriptCompiler::Compile()"); |
| 1876 ENTER_V8(isolate); |
| 1877 EXCEPTION_PREAMBLE(isolate); |
| 1878 i::Handle<i::SharedFunctionInfo> result = |
| 1879 i::Compiler::CompileStreamedScript(source->info, str->length()); |
| 1880 EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); |
| 1881 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result); |
| 1882 if (generic.IsEmpty()) return Local<Script>(); |
| 1883 return generic->BindToCurrentContext(); |
| 1884 } |
| 1885 |
| 1886 |
1803 Local<Script> ScriptCompiler::Compile( | 1887 Local<Script> ScriptCompiler::Compile( |
1804 Isolate* v8_isolate, | 1888 Isolate* v8_isolate, |
1805 Source* source, | 1889 Source* source, |
1806 CompileOptions options) { | 1890 CompileOptions options) { |
1807 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 1891 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
1808 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); | 1892 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); |
1809 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); | 1893 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); |
1810 ENTER_V8(isolate); | 1894 ENTER_V8(isolate); |
1811 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); | 1895 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); |
1812 if (generic.IsEmpty()) return Local<Script>(); | 1896 if (generic.IsEmpty()) return Local<Script>(); |
(...skipping 5865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7678 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7762 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7679 Address callback_address = | 7763 Address callback_address = |
7680 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7764 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7681 VMState<EXTERNAL> state(isolate); | 7765 VMState<EXTERNAL> state(isolate); |
7682 ExternalCallbackScope call_scope(isolate, callback_address); | 7766 ExternalCallbackScope call_scope(isolate, callback_address); |
7683 callback(info); | 7767 callback(info); |
7684 } | 7768 } |
7685 | 7769 |
7686 | 7770 |
7687 } } // namespace v8::internal | 7771 } } // namespace v8::internal |
OLD | NEW |