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

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: cleanup & better comments 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
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;
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, isolate);
1847 }
1848
1849
1850 Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate,
1851 StreamedSource* v8_source,
1852 Handle<String> full_source_string,
1853 const ScriptOrigin& origin) {
1854 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1855 i::StreamedSource* source = v8_source->impl();
1856 ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>());
1857 LOG_API(isolate, "ScriptCompiler::Compile()");
1858 ENTER_V8(isolate);
1859 i::SharedFunctionInfo* raw_result = NULL;
1860
1861 {
1862 i::HandleScope scope(isolate);
1863 i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string));
1864 i::Handle<i::Script> script = isolate->factory()->NewScript(str);
1865 if (!origin.ResourceName().IsEmpty()) {
1866 script->set_name(*Utils::OpenHandle(*(origin.ResourceName())));
1867 }
1868 if (!origin.ResourceLineOffset().IsEmpty()) {
1869 script->set_line_offset(i::Smi::FromInt(
1870 static_cast<int>(origin.ResourceLineOffset()->Value())));
1871 }
1872 if (!origin.ResourceColumnOffset().IsEmpty()) {
1873 script->set_column_offset(i::Smi::FromInt(
1874 static_cast<int>(origin.ResourceColumnOffset()->Value())));
1875 }
1876 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) {
1877 script->set_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin() ==
1878 v8::True(v8_isolate));
1879 }
1880 source->info->set_script(script);
1881 source->info->SetContext(isolate->global_context());
1882
1883 EXCEPTION_PREAMBLE(isolate);
1884
1885 // Do the parsing tasks which need to be done on the main thread. This will
1886 // also handle parse errors.
1887 source->parser->Internalize();
1888
1889 i::Handle<i::SharedFunctionInfo> result =
1890 i::Handle<i::SharedFunctionInfo>::null();
1891 if (source->info->function() != NULL) {
1892 // Parsing has succeeded.
1893 result = i::Compiler::CompileStreamedScript(source->info, str->length());
1894 }
1895 has_pending_exception = result.is_null();
1896 if (has_pending_exception) isolate->ReportPendingMessages();
1897 EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
1898
1899 raw_result = *result;
1900 // The Handle<Script> will go out of scope soon; make sure CompilationInfo
1901 // doesn't point to it.
1902 source->info->set_script(i::Handle<i::Script>());
1903 } // HandleScope goes out of scope.
1904 i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1905 Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result);
1906 if (generic.IsEmpty()) {
1907 return Local<Script>();
1908 }
1909 return generic->BindToCurrentContext();
1910 }
1911
1912
1817 Local<Script> Script::Compile(v8::Handle<String> source, 1913 Local<Script> Script::Compile(v8::Handle<String> source,
1818 v8::ScriptOrigin* origin) { 1914 v8::ScriptOrigin* origin) {
1819 i::Handle<i::String> str = Utils::OpenHandle(*source); 1915 i::Handle<i::String> str = Utils::OpenHandle(*source);
1820 if (origin) { 1916 if (origin) {
1821 ScriptCompiler::Source script_source(source, *origin); 1917 ScriptCompiler::Source script_source(source, *origin);
1822 return ScriptCompiler::Compile( 1918 return ScriptCompiler::Compile(
1823 reinterpret_cast<v8::Isolate*>(str->GetIsolate()), 1919 reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1824 &script_source); 1920 &script_source);
1825 } 1921 }
1826 ScriptCompiler::Source script_source(source); 1922 ScriptCompiler::Source script_source(source);
(...skipping 5799 matching lines...) Expand 10 before | Expand all | Expand 10 after
7626 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7722 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7627 Address callback_address = 7723 Address callback_address =
7628 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7724 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7629 VMState<EXTERNAL> state(isolate); 7725 VMState<EXTERNAL> state(isolate);
7630 ExternalCallbackScope call_scope(isolate, callback_address); 7726 ExternalCallbackScope call_scope(isolate, callback_address);
7631 callback(info); 7727 callback(info);
7632 } 7728 }
7633 7729
7634 7730
7635 } } // namespace v8::internal 7731 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698