|
21 | 21 | #include "JType.h" |
22 | 22 | #include "Module.h" |
23 | 23 | #include "NativeScriptException.h" |
| 24 | +#include "V8NativeScriptExtension.h" |
24 | 25 | #include "Runtime.h" |
25 | 26 | #include "ArrayHelper.h" |
26 | 27 | #include <sstream> |
@@ -345,14 +346,16 @@ void Runtime::ClearStartupData(JNIEnv *env, jobject obj) { |
345 | 346 | } |
346 | 347 | } |
347 | 348 |
|
348 | | -Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, jobject jsDebugger, jstring profilerOutputDir) |
349 | | -{ |
| 349 | +static void InitializeV8() { |
350 | 350 | auto platform = v8::platform::CreateDefaultPlatform(); |
351 | 351 | V8::InitializePlatform(platform); |
352 | 352 | V8::Initialize(); |
| 353 | +} |
353 | 354 |
|
| 355 | +Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, jobject jsDebugger, jstring profilerOutputDir) |
| 356 | +{ |
354 | 357 | Isolate::CreateParams create_params; |
355 | | - string customScript; |
| 358 | + bool didInitializeV8 = false; |
356 | 359 |
|
357 | 360 | create_params.array_buffer_allocator = &g_allocator; |
358 | 361 | // prepare the snapshot blob |
@@ -385,6 +388,13 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, |
385 | 388 | } |
386 | 389 | else if(saveSnapshot) |
387 | 390 | { |
| 391 | + // This should be executed before V8::Initialize, which calls it with false. |
| 392 | + NativeScriptExtension::Probe(true); |
| 393 | + InitializeV8(); |
| 394 | + didInitializeV8 = true; |
| 395 | + |
| 396 | + string customScript; |
| 397 | + |
388 | 398 | // check for custom script to include in the snapshot |
389 | 399 | if(Constants::V8_HEAP_SNAPSHOT_SCRIPT.size() > 0 && File::Exists(Constants::V8_HEAP_SNAPSHOT_SCRIPT)) |
390 | 400 | { |
@@ -412,6 +422,9 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, |
412 | 422 | create_params.snapshot_blob = m_startupData; |
413 | 423 | } |
414 | 424 |
|
| 425 | + if (!didInitializeV8) { |
| 426 | + InitializeV8(); |
| 427 | + } |
415 | 428 | auto isolate = Isolate::New(create_params); |
416 | 429 | Isolate::Scope isolate_scope(isolate); |
417 | 430 | HandleScope handleScope(isolate); |
|
0 commit comments