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

Unified Diff: src/api.cc

Issue 366153002: Add script streaming API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: added tests + fixed compilation flags (!) Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 667f9afcbceb3471ea1e77c17673002910b1a096..0032eb359e638d85007dc6af0fc5eb21620e076b 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -13,6 +13,7 @@
#include "include/v8-profiler.h"
#include "include/v8-testing.h"
#include "src/assert-scope.h"
+#include "src/background-parsing-task.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "src/base/utils/random-number-generator.h"
@@ -1600,6 +1601,13 @@ ScriptCompiler::CachedData::~CachedData() {
}
+ScriptCompiler::StreamedSource::~StreamedSource() {
+ delete source_stream;
+ delete cached_data;
+ delete info;
+}
+
+
Local<Script> UnboundScript::BindToCurrentContext() {
i::Handle<i::HeapObject> obj =
i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this));
@@ -1800,6 +1808,82 @@ Local<UnboundScript> ScriptCompiler::CompileUnbound(
}
+ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript(
+ Isolate* v8_isolate, StreamedSource* source, CompileOptions options) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
+ if (!isolate->global_context().is_null() &&
+ !isolate->global_context()->IsNativeContext()) {
+ // The context chain is non-trivial, and constructing the corresponding
+ // non-trivial Scope chain outside the V8 heap is not implemented. Don't
+ // stream the script. This will only occur if Harmony scoping is enabled and
+ // a previous script has introduced "let" or "const" variables. TODO(marja):
+ // Implement externalizing ScopeInfos and constructing non-trivial Scope
+ // chains independent of the V8 heap so that we can stream also in this
+ // case.
+ return NULL;
+ }
+
+ source->info = new i::CompilationInfoWithZone(source->source_stream, isolate);
+ source->info->MarkAsGlobal();
+ DCHECK(options == kProduceParserCache || options == kProduceCodeCache ||
+ options == kNoCompileOptions);
+ bool allow_lazy = !i::Compiler::DebuggerWantsEagerCompilation(source->info);
+ i::BackgroundParsingTask* task =
+ new i::BackgroundParsingTask(source, allow_lazy, isolate);
+ if (options == kProduceParserCache || options == kProduceCodeCache) {
+ source->info->SetCachedData(&(task->script_data_), options);
+ }
+ // We don't set the context to the CompilationInfo yet, because the background
+ // thread cannot do anything with it anyway. We set it just before compilation
+ // on the foreground thread.
+ return task;
+}
+
+
+Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate,
+ StreamedSource* source,
+ Handle<String> full_source_string,
+ const ScriptOrigin& origin) {
+ if (source->info->function() == NULL) {
+ // Parsing has failed.
+ return Local<Script>();
+ }
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
+ source->info->ast_value_factory()->Internalize(isolate);
+
+ i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string));
+ i::Handle<i::Script> script = isolate->factory()->NewScript(str);
+ if (!origin.ResourceName().IsEmpty()) {
+ script->set_name(*Utils::OpenHandle(*(origin.ResourceName())));
+ }
+ if (!origin.ResourceLineOffset().IsEmpty()) {
+ script->set_line_offset(i::Smi::FromInt(
+ static_cast<int>(origin.ResourceLineOffset()->Value())));
+ }
+ if (!origin.ResourceColumnOffset().IsEmpty()) {
+ script->set_column_offset(i::Smi::FromInt(
+ static_cast<int>(origin.ResourceColumnOffset()->Value())));
+ }
+ if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) {
+ script->set_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin() ==
+ v8::True(v8_isolate));
+ }
+ source->info->set_script(script);
+ source->info->SetContext(isolate->global_context());
+
+ ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>());
+ LOG_API(isolate, "ScriptCompiler::Compile()");
+ ENTER_V8(isolate);
+ EXCEPTION_PREAMBLE(isolate);
+ i::Handle<i::SharedFunctionInfo> result =
+ i::Compiler::CompileStreamedScript(source->info, str->length());
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
+ Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result);
+ if (generic.IsEmpty()) return Local<Script>();
+ return generic->BindToCurrentContext();
+}
+
+
Local<Script> ScriptCompiler::Compile(
Isolate* v8_isolate,
Source* source,

Powered by Google App Engine
This is Rietveld 408576698