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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | src/execution.cc » ('j') | tools/gyp/v8.gyp » ('J')
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
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void V8::SetNativesDataBlob(StartupData* natives_blob) { 199 void V8::SetNativesDataBlob(StartupData* natives_blob) {
200 i::V8::SetNativesBlob(natives_blob); 200 i::V8::SetNativesBlob(natives_blob);
201 } 201 }
202 202
203 203
204 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { 204 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
205 i::V8::SetSnapshotBlob(snapshot_blob); 205 i::V8::SetSnapshotBlob(snapshot_blob);
206 } 206 }
207 207
208 208
209 StartupData V8::CreateSnapshotDataBlob() { 209 bool RunExtraCode(Isolate* isolate, char* utf8_source) {
210 // Run custom script if provided.
211 TryCatch try_catch;
212 Local<String> source_string = String::NewFromUtf8(isolate, utf8_source);
213 if (try_catch.HasCaught()) return false;
214 ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>"));
215 ScriptCompiler::Source source(source_string, origin);
216 Local<Script> script = ScriptCompiler::Compile(isolate, &source);
217 if (try_catch.HasCaught()) return false;
218 script->Run();
219 return !try_catch.HasCaught();
220 }
221
222
223 StartupData V8::CreateSnapshotDataBlob(char* custom_source) {
210 Isolate::CreateParams params; 224 Isolate::CreateParams params;
211 params.enable_serializer = true; 225 params.enable_serializer = true;
212 Isolate* isolate = v8::Isolate::New(params); 226 Isolate* isolate = v8::Isolate::New(params);
213 StartupData result = {NULL, 0}; 227 StartupData result = {NULL, 0};
214 { 228 {
215 Isolate::Scope isolate_scope(isolate); 229 Isolate::Scope isolate_scope(isolate);
216 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 230 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
217 Persistent<Context> context; 231 Persistent<Context> context;
218 { 232 {
219 HandleScope handle_scope(isolate); 233 HandleScope handle_scope(isolate);
220 context.Reset(isolate, Context::New(isolate)); 234 Handle<Context> new_context = Context::New(isolate);
235 context.Reset(isolate, new_context);
236 if (custom_source != NULL) {
237 Context::Scope context_scope(new_context);
238 if (!RunExtraCode(isolate, custom_source)) context.Reset();
239 }
221 } 240 }
222 if (!context.IsEmpty()) { 241 if (!context.IsEmpty()) {
223 // Make sure all builtin scripts are cached. 242 // Make sure all builtin scripts are cached.
224 { 243 {
225 HandleScope scope(isolate); 244 HandleScope scope(isolate);
226 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { 245 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
227 internal_isolate->bootstrapper()->NativesSourceLookup(i); 246 internal_isolate->bootstrapper()->NativesSourceLookup(i);
228 } 247 }
229 } 248 }
230 // If we don't do this then we end up with a stray root pointing at the 249 // If we don't do this then we end up with a stray root pointing at the
(...skipping 7377 matching lines...) Expand 10 before | Expand all | Expand 10 after
7608 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7627 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7609 Address callback_address = 7628 Address callback_address =
7610 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7629 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7611 VMState<EXTERNAL> state(isolate); 7630 VMState<EXTERNAL> state(isolate);
7612 ExternalCallbackScope call_scope(isolate, callback_address); 7631 ExternalCallbackScope call_scope(isolate, callback_address);
7613 callback(info); 7632 callback(info);
7614 } 7633 }
7615 7634
7616 7635
7617 } } // namespace v8::internal 7636 } } // namespace v8::internal
OLDNEW
« 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