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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void V8::SetNativesDataBlob(StartupData* natives_blob) { | 200 void V8::SetNativesDataBlob(StartupData* natives_blob) { |
201 i::V8::SetNativesBlob(natives_blob); | 201 i::V8::SetNativesBlob(natives_blob); |
202 } | 202 } |
203 | 203 |
204 | 204 |
205 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { | 205 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { |
206 i::V8::SetSnapshotBlob(snapshot_blob); | 206 i::V8::SetSnapshotBlob(snapshot_blob); |
207 } | 207 } |
208 | 208 |
209 | 209 |
210 bool RunExtraCode(Isolate* isolate, char* utf8_source) { | 210 bool RunExtraCode(Isolate* isolate, const char* utf8_source) { |
211 // Run custom script if provided. | 211 // Run custom script if provided. |
212 TryCatch try_catch; | 212 TryCatch try_catch; |
213 Local<String> source_string = String::NewFromUtf8(isolate, utf8_source); | 213 Local<String> source_string = String::NewFromUtf8(isolate, utf8_source); |
214 if (try_catch.HasCaught()) return false; | 214 if (try_catch.HasCaught()) return false; |
215 ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>")); | 215 ScriptOrigin origin(String::NewFromUtf8(isolate, "<embedded script>")); |
216 ScriptCompiler::Source source(source_string, origin); | 216 ScriptCompiler::Source source(source_string, origin); |
217 Local<Script> script = ScriptCompiler::Compile(isolate, &source); | 217 Local<Script> script = ScriptCompiler::Compile(isolate, &source); |
218 if (try_catch.HasCaught()) return false; | 218 if (try_catch.HasCaught()) return false; |
219 script->Run(); | 219 script->Run(); |
220 return !try_catch.HasCaught(); | 220 return !try_catch.HasCaught(); |
221 } | 221 } |
222 | 222 |
223 | 223 |
224 StartupData V8::CreateSnapshotDataBlob(char* custom_source) { | 224 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { |
225 Isolate::CreateParams params; | 225 i::Isolate* internal_isolate = new i::Isolate(true); |
226 params.enable_serializer = true; | 226 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); |
227 Isolate* isolate = v8::Isolate::New(params); | |
228 StartupData result = {NULL, 0}; | 227 StartupData result = {NULL, 0}; |
229 { | 228 { |
230 Isolate::Scope isolate_scope(isolate); | 229 Isolate::Scope isolate_scope(isolate); |
231 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 230 internal_isolate->Init(NULL); |
232 Persistent<Context> context; | 231 Persistent<Context> context; |
233 i::Snapshot::Metadata metadata; | 232 i::Snapshot::Metadata metadata; |
234 { | 233 { |
235 HandleScope handle_scope(isolate); | 234 HandleScope handle_scope(isolate); |
236 Handle<Context> new_context = Context::New(isolate); | 235 Handle<Context> new_context = Context::New(isolate); |
237 context.Reset(isolate, new_context); | 236 context.Reset(isolate, new_context); |
238 if (custom_source != NULL) { | 237 if (custom_source != NULL) { |
239 metadata.set_embeds_script(true); | 238 metadata.set_embeds_script(true); |
240 Context::Scope context_scope(new_context); | 239 Context::Scope context_scope(new_context); |
241 if (!RunExtraCode(isolate, custom_source)) context.Reset(); | 240 if (!RunExtraCode(isolate, custom_source)) context.Reset(); |
(...skipping 6275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6517 } | 6516 } |
6518 | 6517 |
6519 | 6518 |
6520 Isolate* Isolate::GetCurrent() { | 6519 Isolate* Isolate::GetCurrent() { |
6521 i::Isolate* isolate = i::Isolate::Current(); | 6520 i::Isolate* isolate = i::Isolate::Current(); |
6522 return reinterpret_cast<Isolate*>(isolate); | 6521 return reinterpret_cast<Isolate*>(isolate); |
6523 } | 6522 } |
6524 | 6523 |
6525 | 6524 |
6526 Isolate* Isolate::New(const Isolate::CreateParams& params) { | 6525 Isolate* Isolate::New(const Isolate::CreateParams& params) { |
6527 i::Isolate* isolate = new i::Isolate(params.enable_serializer); | 6526 i::Isolate* isolate = new i::Isolate(false); |
6528 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); | 6527 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); |
| 6528 if (params.snapshot_blob != NULL) { |
| 6529 isolate->set_snapshot_blob(params.snapshot_blob); |
| 6530 } else { |
| 6531 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); |
| 6532 } |
6529 if (params.entry_hook) { | 6533 if (params.entry_hook) { |
6530 isolate->set_function_entry_hook(params.entry_hook); | 6534 isolate->set_function_entry_hook(params.entry_hook); |
6531 } | 6535 } |
6532 if (params.code_event_handler) { | 6536 if (params.code_event_handler) { |
6533 isolate->InitializeLoggingAndCounters(); | 6537 isolate->InitializeLoggingAndCounters(); |
6534 isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault, | 6538 isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault, |
6535 params.code_event_handler); | 6539 params.code_event_handler); |
6536 } | 6540 } |
6537 SetResourceConstraints(isolate, params.constraints); | 6541 SetResourceConstraints(isolate, params.constraints); |
6538 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. | 6542 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. |
6539 Isolate::Scope isolate_scope(v8_isolate); | 6543 Isolate::Scope isolate_scope(v8_isolate); |
6540 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { | 6544 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { |
6541 // If the isolate has a function entry hook, it needs to re-build all its | 6545 // If the isolate has a function entry hook, it needs to re-build all its |
6542 // code stubs with entry hooks embedded, so don't deserialize a snapshot. | 6546 // code stubs with entry hooks embedded, so don't deserialize a snapshot. |
| 6547 if (i::Snapshot::EmbedsScript(isolate)) { |
| 6548 // If the snapshot embeds a script, we cannot initialize the isolate |
| 6549 // without the snapshot as a fallback. This is unlikely to happen though. |
| 6550 V8_Fatal(__FILE__, __LINE__, |
| 6551 "Initializing isolate from custom startup snapshot failed"); |
| 6552 } |
6543 isolate->Init(NULL); | 6553 isolate->Init(NULL); |
6544 } | 6554 } |
6545 return v8_isolate; | 6555 return v8_isolate; |
6546 } | 6556 } |
6547 | 6557 |
6548 | 6558 |
6549 void Isolate::Dispose() { | 6559 void Isolate::Dispose() { |
6550 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 6560 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6551 if (!Utils::ApiCheck(!isolate->IsInUse(), | 6561 if (!Utils::ApiCheck(!isolate->IsInUse(), |
6552 "v8::Isolate::Dispose()", | 6562 "v8::Isolate::Dispose()", |
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7775 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7785 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7776 Address callback_address = | 7786 Address callback_address = |
7777 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7787 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7778 VMState<EXTERNAL> state(isolate); | 7788 VMState<EXTERNAL> state(isolate); |
7779 ExternalCallbackScope call_scope(isolate, callback_address); | 7789 ExternalCallbackScope call_scope(isolate, callback_address); |
7780 callback(info); | 7790 callback(info); |
7781 } | 7791 } |
7782 | 7792 |
7783 | 7793 |
7784 } } // namespace v8::internal | 7794 } } // namespace v8::internal |
OLD | NEW |