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

Unified Diff: src/api.cc

Issue 845973003: Embed custom script into the snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « include/v8.h ('k') | src/execution.cc » ('j') | tools/gyp/v8.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index fc528b679166b625cdba24f5fade1559e8ea93ce..b45e3cb3533fe342ab59c03c5dfe107b5f306505 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -206,7 +206,21 @@ void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
}
-StartupData V8::CreateSnapshotDataBlob() {
+bool RunExtraCode(Isolate* isolate, char* utf8_source) {
+ // Run custom script if provided.
+ TryCatch try_catch;
+ Local<String> source_string = String::NewFromUtf8(isolate, utf8_source);
+ if (try_catch.HasCaught()) return false;
+ ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>"));
+ ScriptCompiler::Source source(source_string, origin);
+ Local<Script> script = ScriptCompiler::Compile(isolate, &source);
+ if (try_catch.HasCaught()) return false;
+ script->Run();
+ return !try_catch.HasCaught();
+}
+
+
+StartupData V8::CreateSnapshotDataBlob(char* custom_source) {
Isolate::CreateParams params;
params.enable_serializer = true;
Isolate* isolate = v8::Isolate::New(params);
@@ -217,7 +231,12 @@ StartupData V8::CreateSnapshotDataBlob() {
Persistent<Context> context;
{
HandleScope handle_scope(isolate);
- context.Reset(isolate, Context::New(isolate));
+ Handle<Context> new_context = Context::New(isolate);
+ context.Reset(isolate, new_context);
+ if (custom_source != NULL) {
+ Context::Scope context_scope(new_context);
+ if (!RunExtraCode(isolate, custom_source)) context.Reset();
+ }
}
if (!context.IsEmpty()) {
// Make sure all builtin scripts are cached.
« no previous file with comments | « include/v8.h ('k') | src/execution.cc » ('j') | tools/gyp/v8.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698