@@ -216,9 +216,6 @@ JNIEXPORT jobjectArray JNICALL Java_com_caoccao_javet_interop_V8Native_functionG
216
216
auto v8InternalIsolate = reinterpret_cast <V8InternalIsolate*>(v8Context->GetIsolate ());
217
217
#ifdef ENABLE_NODE
218
218
auto v8InternalScript = V8InternalScript::cast (v8InternalShared->script ());
219
- #else
220
- auto v8InternalScript = v8::internal::Cast<V8InternalScript>(v8InternalShared->script ());
221
- #endif
222
219
auto wrappedArguments = *v8InternalScript->wrapped_arguments ();
223
220
auto length = wrappedArguments.length ();
224
221
if (length > 0 ) {
@@ -231,6 +228,21 @@ JNIEXPORT jobjectArray JNICALL Java_com_caoccao_javet_interop_V8Native_functionG
231
228
}
232
229
return arguments;
233
230
}
231
+ #else
232
+ auto v8InternalScript = v8::internal::Cast<V8InternalScript>(v8InternalShared->script ());
233
+ auto wrappedArguments = v8InternalScript->wrapped_arguments ();
234
+ auto length = wrappedArguments->length ();
235
+ if (length > 0 ) {
236
+ jobjectArray arguments = jniEnv->NewObjectArray (length, Javet::Converter::jclassString, nullptr );
237
+ for (int i = 0 ; i < length; ++i) {
238
+ auto v8InternalObjectHandle = v8::internal::handle (wrappedArguments->get (i), v8InternalIsolate);
239
+ auto v8LocalString = v8::Utils::ToLocal (v8InternalObjectHandle).As <v8::String>();
240
+ jstring argument = Javet::Converter::ToJavaString (jniEnv, v8Context, v8LocalString);
241
+ jniEnv->SetObjectArrayElement (arguments, i, argument);
242
+ }
243
+ return arguments;
244
+ }
245
+ #endif
234
246
}
235
247
}
236
248
return nullptr ;
@@ -383,9 +395,13 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_functionGetScr
383
395
const int startPosition = v8InternalShared->StartPosition ();
384
396
const int endPosition = v8InternalShared->EndPosition ();
385
397
const int sourceLength = v8InternalSource->length ();
398
+ #ifdef ENABLE_NODE
386
399
auto sourceCode = v8InternalSource->ToCString (
387
400
V8InternalAllowNullsFlag::DISALLOW_NULLS, V8InternalRobustnessFlag::ROBUST_STRING_TRAVERSAL,
388
401
0 , sourceLength);
402
+ #else
403
+ auto sourceCode = v8InternalSource->ToCString (0 , sourceLength);
404
+ #endif
389
405
return jniEnv->NewObject (
390
406
Javet::Converter::jclassIV8ValueFunctionScriptSource,
391
407
Javet::Converter::jmethodIDIV8ValueFunctionScriptSourceConstructor,
@@ -413,9 +429,13 @@ JNIEXPORT jstring JNICALL Java_com_caoccao_javet_interop_V8Native_functionGetSou
413
429
#endif
414
430
const int startPosition = v8InternalShared->StartPosition ();
415
431
const int endPosition = v8InternalShared->EndPosition ();
432
+ #ifdef ENABLE_NODE
416
433
auto sourceCode = v8InternalSource->ToCString (
417
434
V8InternalAllowNullsFlag::DISALLOW_NULLS, V8InternalRobustnessFlag::ROBUST_STRING_TRAVERSAL,
418
435
startPosition, endPosition - startPosition);
436
+ #else
437
+ auto sourceCode = v8InternalSource->ToCString (startPosition, endPosition - startPosition);
438
+ #endif
419
439
return Javet::Converter::ToJavaString (jniEnv, sourceCode.get ());
420
440
}
421
441
}
@@ -542,10 +562,15 @@ JNIEXPORT jboolean JNICALL Java_com_caoccao_javet_interop_V8Native_functionSetSo
542
562
543
563
V8LocalString newSourceCode;
544
564
if (startPosition > 0 ) {
565
+ #ifdef ENABLE_NODE
545
566
int utf8Length = 0 ;
546
567
auto stdStringHeader (v8InternalSource->ToCString (
547
568
V8InternalAllowNullsFlag::DISALLOW_NULLS, V8InternalRobustnessFlag::ROBUST_STRING_TRAVERSAL,
548
569
0 , startPosition, &utf8Length));
570
+ #else
571
+ uint32_t utf8Length = 0 ;
572
+ auto stdStringHeader (v8InternalSource->ToCString (0 , startPosition, &utf8Length));
573
+ #endif
549
574
auto v8MaybeLocalStringHeader = v8::String::NewFromUtf8 (
550
575
v8Context->GetIsolate (), stdStringHeader.get (), v8::NewStringType::kNormal , utf8Length);
551
576
if (v8MaybeLocalStringHeader.IsEmpty ()) {
@@ -562,10 +587,15 @@ JNIEXPORT jboolean JNICALL Java_com_caoccao_javet_interop_V8Native_functionSetSo
562
587
newSourceCode = v8::String::Concat (v8Context->GetIsolate (), newSourceCode, umSourceCode);
563
588
}
564
589
if (endPosition < sourceLength) {
590
+ #ifdef ENABLE_NODE
565
591
int utf8Length = 0 ;
566
592
auto stdStringFooter (v8InternalSource->ToCString (
567
593
V8InternalAllowNullsFlag::DISALLOW_NULLS, V8InternalRobustnessFlag::ROBUST_STRING_TRAVERSAL,
568
594
endPosition, sourceLength - endPosition, &utf8Length));
595
+ #else
596
+ uint32_t utf8Length = 0 ;
597
+ auto stdStringFooter (v8InternalSource->ToCString (endPosition, sourceLength - endPosition, &utf8Length));
598
+ #endif
569
599
auto v8MaybeLocalStringFooter = v8::String::NewFromUtf8 (
570
600
v8Context->GetIsolate (), stdStringFooter.get (), v8::NewStringType::kNormal , utf8Length);
571
601
if (v8MaybeLocalStringFooter.IsEmpty ()) {
0 commit comments