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

Side by Side Diff: src/api.cc

Issue 366153002: Add script streaming API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased again? Created 6 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 | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/background-parsing-task.h » ('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 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
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(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
1603 Local<Script> UnboundScript::BindToCurrentContext() { 1618 Local<Script> UnboundScript::BindToCurrentContext() {
1604 i::Handle<i::HeapObject> obj = 1619 i::Handle<i::HeapObject> obj =
1605 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); 1620 i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
1606 i::Handle<i::SharedFunctionInfo> 1621 i::Handle<i::SharedFunctionInfo>
1607 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate()); 1622 function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate());
1608 i::Handle<i::JSFunction> function = 1623 i::Handle<i::JSFunction> function =
1609 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo( 1624 obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo(
1610 function_info, obj->GetIsolate()->global_context()); 1625 function_info, obj->GetIsolate()->global_context());
1611 return ToApiHandle<Script>(function); 1626 return ToApiHandle<Script>(function);
1612 } 1627 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 1822 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1808 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>()); 1823 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>());
1809 LOG_API(isolate, "ScriptCompiler::CompiletBound()"); 1824 LOG_API(isolate, "ScriptCompiler::CompiletBound()");
1810 ENTER_V8(isolate); 1825 ENTER_V8(isolate);
1811 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options); 1826 Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options);
1812 if (generic.IsEmpty()) return Local<Script>(); 1827 if (generic.IsEmpty()) return Local<Script>();
1813 return generic->BindToCurrentContext(); 1828 return generic->BindToCurrentContext();
1814 } 1829 }
1815 1830
1816 1831
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
1817 Local<Script> Script::Compile(v8::Handle<String> source, 1915 Local<Script> Script::Compile(v8::Handle<String> source,
1818 v8::ScriptOrigin* origin) { 1916 v8::ScriptOrigin* origin) {
1819 i::Handle<i::String> str = Utils::OpenHandle(*source); 1917 i::Handle<i::String> str = Utils::OpenHandle(*source);
1820 if (origin) { 1918 if (origin) {
1821 ScriptCompiler::Source script_source(source, *origin); 1919 ScriptCompiler::Source script_source(source, *origin);
1822 return ScriptCompiler::Compile( 1920 return ScriptCompiler::Compile(
1823 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), 1921 reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1824 &script_source); 1922 &script_source);
1825 } 1923 }
1826 ScriptCompiler::Source script_source(source); 1924 ScriptCompiler::Source script_source(source);
(...skipping 5793 matching lines...) Expand 10 before | Expand all | Expand 10 after
7620 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7718 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7621 Address callback_address = 7719 Address callback_address =
7622 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7720 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7623 VMState<EXTERNAL> state(isolate); 7721 VMState<EXTERNAL> state(isolate);
7624 ExternalCallbackScope call_scope(isolate, callback_address); 7722 ExternalCallbackScope call_scope(isolate, callback_address);
7625 callback(info); 7723 callback(info);
7626 } 7724 }
7627 7725
7628 7726
7629 } } // namespace v8::internal 7727 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/background-parsing-task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698