Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 if (try_catch.HasCaught()) return false; | 315 if (try_catch.HasCaught()) return false; |
| 316 ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>")); | 316 ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>")); |
| 317 ScriptCompiler::Source source(source_string, origin); | 317 ScriptCompiler::Source source(source_string, origin); |
| 318 Local<Script> script = ScriptCompiler::Compile(isolate, &source); | 318 Local<Script> script = ScriptCompiler::Compile(isolate, &source); |
| 319 if (try_catch.HasCaught()) return false; | 319 if (try_catch.HasCaught()) return false; |
| 320 script->Run(); | 320 script->Run(); |
| 321 return !try_catch.HasCaught(); | 321 return !try_catch.HasCaught(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 | 324 |
| 325 StartupData CreateSnapshotWithinIsolate(Isolate* isolate, | |
| 326 const char* custom_source) { | |
| 327 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | |
| 328 Isolate::Scope isolate_scope(isolate); | |
| 329 i_isolate->Init(NULL); | |
| 330 Persistent<Context> context; | |
| 331 i::Snapshot::Metadata metadata; | |
| 332 { | |
| 333 HandleScope handle_scope(isolate); | |
| 334 Handle<Context> new_context = Context::New(isolate); | |
| 335 context.Reset(isolate, new_context); | |
| 336 if (custom_source != NULL) { | |
| 337 metadata.set_embeds_script(true); | |
| 338 Context::Scope context_scope(new_context); | |
| 339 if (!RunExtraCode(isolate, custom_source)) context.Reset(); | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 if (context.IsEmpty()) return {NULL, 0}; | |
| 344 | |
| 345 // Make sure all builtin scripts are cached. | |
| 346 { | |
| 347 HandleScope scope(isolate); | |
| 348 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { | |
| 349 i_isolate->bootstrapper()->NativesSourceLookup(i); | |
| 350 } | |
| 351 } | |
| 352 // If we don't do this then we end up with a stray root pointing at the | |
| 353 // context even after we have disposed of the context. | |
| 354 i_isolate->heap()->CollectAllAvailableGarbage("CreateSnapshotDataBlob"); | |
| 355 i::Object* raw_context = *v8::Utils::OpenPersistent(context); | |
| 356 context.Reset(); | |
| 357 | |
| 358 i::SnapshotByteSink snapshot_sink; | |
| 359 i::StartupSerializer ser(i_isolate, &snapshot_sink); | |
| 360 ser.SerializeStrongReferences(); | |
| 361 | |
| 362 i::SnapshotByteSink context_sink; | |
| 363 i::PartialSerializer context_ser(i_isolate, &ser, &context_sink); | |
| 364 context_ser.Serialize(&raw_context); | |
| 365 ser.SerializeWeakReferences(); | |
| 366 | |
| 367 return i::Snapshot::CreateSnapshotBlob(ser, context_ser, metadata); | |
| 368 } | |
| 369 | |
| 370 | |
| 325 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { | 371 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { |
| 326 i::Isolate* internal_isolate = new i::Isolate(true); | 372 Isolate* isolate = reinterpret_cast<Isolate*>(new i::Isolate(true)); |
| 327 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); | |
| 328 StartupData result = {NULL, 0}; | 373 StartupData result = {NULL, 0}; |
| 329 { | 374 if (Locker::IsActive()) { |
| 330 Isolate::Scope isolate_scope(isolate); | 375 Locker lock(isolate); |
| 331 internal_isolate->Init(NULL); | 376 result = CreateSnapshotWithinIsolate(isolate, custom_source); |
| 332 Persistent<Context> context; | 377 } else { |
| 333 i::Snapshot::Metadata metadata; | 378 result = CreateSnapshotWithinIsolate(isolate, custom_source); |
|
vogelheim
2015/03/03 13:18:29
I'm confused by this. Admittedly I don't understan
| |
| 334 { | |
| 335 HandleScope handle_scope(isolate); | |
| 336 Handle<Context> new_context = Context::New(isolate); | |
| 337 context.Reset(isolate, new_context); | |
| 338 if (custom_source != NULL) { | |
| 339 metadata.set_embeds_script(true); | |
| 340 Context::Scope context_scope(new_context); | |
| 341 if (!RunExtraCode(isolate, custom_source)) context.Reset(); | |
| 342 } | |
| 343 } | |
| 344 if (!context.IsEmpty()) { | |
| 345 // Make sure all builtin scripts are cached. | |
| 346 { | |
| 347 HandleScope scope(isolate); | |
| 348 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { | |
| 349 internal_isolate->bootstrapper()->NativesSourceLookup(i); | |
| 350 } | |
| 351 } | |
| 352 // If we don't do this then we end up with a stray root pointing at the | |
| 353 // context even after we have disposed of the context. | |
| 354 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot"); | |
| 355 i::Object* raw_context = *v8::Utils::OpenPersistent(context); | |
| 356 context.Reset(); | |
| 357 | |
| 358 i::SnapshotByteSink snapshot_sink; | |
| 359 i::StartupSerializer ser(internal_isolate, &snapshot_sink); | |
| 360 ser.SerializeStrongReferences(); | |
| 361 | |
| 362 i::SnapshotByteSink context_sink; | |
| 363 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink); | |
| 364 context_ser.Serialize(&raw_context); | |
| 365 ser.SerializeWeakReferences(); | |
| 366 | |
| 367 result = i::Snapshot::CreateSnapshotBlob(ser, context_ser, metadata); | |
| 368 } | |
| 369 } | 379 } |
| 370 isolate->Dispose(); | 380 isolate->Dispose(); |
| 371 return result; | 381 return result; |
| 372 } | 382 } |
| 373 | 383 |
| 374 | 384 |
| 375 void V8::SetFlagsFromString(const char* str, int length) { | 385 void V8::SetFlagsFromString(const char* str, int length) { |
| 376 i::FlagList::SetFlagsFromString(str, length); | 386 i::FlagList::SetFlagsFromString(str, length); |
| 377 } | 387 } |
| 378 | 388 |
| (...skipping 7597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7976 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7986 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7977 Address callback_address = | 7987 Address callback_address = |
| 7978 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7988 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7979 VMState<EXTERNAL> state(isolate); | 7989 VMState<EXTERNAL> state(isolate); |
| 7980 ExternalCallbackScope call_scope(isolate, callback_address); | 7990 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7981 callback(info); | 7991 callback(info); |
| 7982 } | 7992 } |
| 7983 | 7993 |
| 7984 | 7994 |
| 7985 } } // namespace v8::internal | 7995 } } // namespace v8::internal |
| OLD | NEW |