Skip to content

Commit db12fa8

Browse files
committed
Merge pull request #433 from NativeScript/jasssonpet/snapshot
Cross-compile snapshot generation
2 parents 0c56f4a + 4493393 commit db12fa8

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/jni/Runtime.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "JType.h"
2222
#include "Module.h"
2323
#include "NativeScriptException.h"
24+
#include "V8NativeScriptExtension.h"
2425
#include "Runtime.h"
2526
#include "ArrayHelper.h"
2627
#include <sstream>
@@ -345,14 +346,16 @@ void Runtime::ClearStartupData(JNIEnv *env, jobject obj) {
345346
}
346347
}
347348

348-
Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, jobject jsDebugger, jstring profilerOutputDir)
349-
{
349+
static void InitializeV8() {
350350
auto platform = v8::platform::CreateDefaultPlatform();
351351
V8::InitializePlatform(platform);
352352
V8::Initialize();
353+
}
353354

355+
Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, jobject jsDebugger, jstring profilerOutputDir)
356+
{
354357
Isolate::CreateParams create_params;
355-
string customScript;
358+
bool didInitializeV8 = false;
356359

357360
create_params.array_buffer_allocator = &g_allocator;
358361
// prepare the snapshot blob
@@ -385,6 +388,13 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
385388
}
386389
else if(saveSnapshot)
387390
{
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+
388398
// check for custom script to include in the snapshot
389399
if(Constants::V8_HEAP_SNAPSHOT_SCRIPT.size() > 0 && File::Exists(Constants::V8_HEAP_SNAPSHOT_SCRIPT))
390400
{
@@ -412,6 +422,9 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
412422
create_params.snapshot_blob = m_startupData;
413423
}
414424

425+
if (!didInitializeV8) {
426+
InitializeV8();
427+
}
415428
auto isolate = Isolate::New(create_params);
416429
Isolate::Scope isolate_scope(isolate);
417430
HandleScope handleScope(isolate);

0 commit comments

Comments
 (0)