@@ -74,7 +74,9 @@ Isolate* NativePlatform::InitNativeScript(JNIEnv *_env, jobject obj, jstring fil
74
74
JniLocalRef cacheCode (env.GetObjectArrayElement (args, 1 ));
75
75
Constants::V8_CACHE_COMPILED_CODE = (bool ) cacheCode;
76
76
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);
78
80
79
81
DEBUG_WRITE (" Initializing Telerik NativeScript: app instance id:%d" , appJavaObjectId);
80
82
@@ -329,22 +331,29 @@ Isolate* NativePlatform::PrepareV8Runtime(JEnv& env, const string& filesPath, js
329
331
V8::Initialize ();
330
332
331
333
Isolate::CreateParams create_params;
332
- create_params.array_buffer_allocator = &g_allocator;
334
+ StartupData startup_data;
335
+ string customScript;
333
336
337
+ create_params.array_buffer_allocator = &g_allocator;
334
338
// prepare the snapshot blob
335
339
if (Constants::V8_HEAP_SNAPSHOT)
336
340
{
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))
340
343
{
341
344
int length;
342
345
startup_data.data = reinterpret_cast <char *>(File::ReadBinary (snapshotPath, length));
343
346
startup_data.raw_size = length;
344
347
}
345
348
else
346
349
{
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 ());
348
357
File::WriteBinary (snapshotPath, startup_data.data , startup_data.raw_size );
349
358
}
350
359
@@ -375,6 +384,7 @@ Isolate* NativePlatform::PrepareV8Runtime(JEnv& env, const string& filesPath, js
375
384
globalTemplate->Set (ConvertToV8String (" __enableVerboseLogging" ), FunctionTemplate::New (isolate, NativeScriptRuntime::EnableVerboseLoggingMethodCallback));
376
385
globalTemplate->Set (ConvertToV8String (" __disableVerboseLogging" ), FunctionTemplate::New (isolate, NativeScriptRuntime::DisableVerboseLoggingMethodCallback));
377
386
globalTemplate->Set (ConvertToV8String (" __exit" ), FunctionTemplate::New (isolate, NativeScriptRuntime::ExitMethodCallback));
387
+ globalTemplate->Set (ConvertToV8String (" __nativeRequire" ), FunctionTemplate::New (isolate, Module::RequireCallback));
378
388
379
389
WeakRef::Init (isolate, globalTemplate, g_objectManager);
380
390
@@ -388,7 +398,7 @@ Isolate* NativePlatform::PrepareV8Runtime(JEnv& env, const string& filesPath, js
388
398
if (Constants::V8_HEAP_SNAPSHOT)
389
399
{
390
400
// we own the snapshot buffer, delete it
391
- delete[] create_params. snapshot_blob -> data ;
401
+ delete[] startup_data. data ;
392
402
}
393
403
394
404
context_scope = new Context::Scope (context);
0 commit comments