@@ -74,7 +74,9 @@ Isolate* NativePlatform::InitNativeScript(JNIEnv *_env, jobject obj, jstring fil
7474 JniLocalRef cacheCode (env.GetObjectArrayElement (args, 1 ));
7575 Constants::V8_CACHE_COMPILED_CODE = (bool ) cacheCode;
7676 JniLocalRef snapshot (env.GetObjectArrayElement (args, 2 ));
77- Constants::V8_HEAP_SNAPSHOT = (bool ) snapshot;
77+ Constants::V8_HEAP_SNAPSHOT = (bool )snapshot;
78+ JniLocalRef snapshotScript (env.GetObjectArrayElement (args, 3 ));
79+ Constants::V8_HEAP_SNAPSHOT_SCRIPT = ArgConverter::jstringToString (snapshotScript);
7880
7981 DEBUG_WRITE (" Initializing Telerik NativeScript: app instance id:%d" , appJavaObjectId);
8082
@@ -329,22 +331,29 @@ Isolate* NativePlatform::PrepareV8Runtime(JEnv& env, const string& filesPath, js
329331 V8::Initialize ();
330332
331333 Isolate::CreateParams create_params;
332- create_params.array_buffer_allocator = &g_allocator;
334+ StartupData startup_data;
335+ string customScript;
333336
337+ create_params.array_buffer_allocator = &g_allocator;
334338 // prepare the snapshot blob
335339 if (Constants::V8_HEAP_SNAPSHOT)
336340 {
337- auto snapshotPath = filesPath + " /internal/snapshot.dat" ;
338- StartupData startup_data;
339- if (File::Exists (snapshotPath))
341+ auto snapshotPath = filesPath + " /internal/snapshot.blob" ;
342+ if ( File::Exists (snapshotPath))
340343 {
341344 int length;
342345 startup_data.data = reinterpret_cast <char *>(File::ReadBinary (snapshotPath, length));
343346 startup_data.raw_size = length;
344347 }
345348 else
346349 {
347- startup_data = V8::CreateSnapshotDataBlob ();
350+ // check for custom script to include in the snapshot
351+ if (Constants::V8_HEAP_SNAPSHOT_SCRIPT.size () > 0 && File::Exists (Constants::V8_HEAP_SNAPSHOT_SCRIPT))
352+ {
353+ customScript = File::ReadText (Constants::V8_HEAP_SNAPSHOT_SCRIPT);
354+ }
355+
356+ startup_data = V8::CreateSnapshotDataBlob (customScript.c_str ());
348357 File::WriteBinary (snapshotPath, startup_data.data , startup_data.raw_size );
349358 }
350359
@@ -375,6 +384,7 @@ Isolate* NativePlatform::PrepareV8Runtime(JEnv& env, const string& filesPath, js
375384 globalTemplate->Set (ConvertToV8String (" __enableVerboseLogging" ), FunctionTemplate::New (isolate, NativeScriptRuntime::EnableVerboseLoggingMethodCallback));
376385 globalTemplate->Set (ConvertToV8String (" __disableVerboseLogging" ), FunctionTemplate::New (isolate, NativeScriptRuntime::DisableVerboseLoggingMethodCallback));
377386 globalTemplate->Set (ConvertToV8String (" __exit" ), FunctionTemplate::New (isolate, NativeScriptRuntime::ExitMethodCallback));
387+ globalTemplate->Set (ConvertToV8String (" __nativeRequire" ), FunctionTemplate::New (isolate, Module::RequireCallback));
378388
379389 WeakRef::Init (isolate, globalTemplate, g_objectManager);
380390
@@ -388,7 +398,7 @@ Isolate* NativePlatform::PrepareV8Runtime(JEnv& env, const string& filesPath, js
388398 if (Constants::V8_HEAP_SNAPSHOT)
389399 {
390400 // we own the snapshot buffer, delete it
391- delete[] create_params. snapshot_blob -> data ;
401+ delete[] startup_data. data ;
392402 }
393403
394404 context_scope = new Context::Scope (context);
0 commit comments