MCPcopy Create free account
hub / github.com/NativeScript/android / RunScript

Method RunScript

test-app/runtime/src/main/cpp/Runtime.cpp:306–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306jobject Runtime::RunScript(JNIEnv* _env, jobject obj, jstring scriptFile) {
307 JEnv env(_env);
308 jobject res = nullptr;
309
310 auto isolate = m_isolate;
311 auto context = this->GetContext();
312
313 auto filename = ArgConverter::jstringToString(scriptFile);
314 auto src = ReadFileText(filename);
315
316 auto source = ArgConverter::ConvertToV8String(isolate, src);
317
318 TryCatch tc(isolate);
319
320 Local<Script> script;
321 ScriptOrigin origin(isolate,
322 ArgConverter::ConvertToV8String(isolate, filename));
323 auto maybeScript = Script::Compile(context, source, &origin).ToLocal(&script);
324
325 if (tc.HasCaught()) {
326 throw NativeScriptException(
327 tc, "Script " + filename + " contains compilation errors!");
328 }
329
330 if (!script.IsEmpty()) {
331 Local<Value> result;
332 auto maybeResult = script->Run(context).ToLocal(&result);
333
334 if (tc.HasCaught()) {
335 throw NativeScriptException(tc, "Error running script " + filename);
336 }
337 if (!result.IsEmpty()) {
338 res =
339 ConvertJsValueToJavaObject(env, result, static_cast<int>(Type::Null));
340 } else {
341 DEBUG_WRITE(">>runScript maybeResult is empty");
342 }
343 } else {
344 DEBUG_WRITE(">>runScript maybeScript is empty");
345 }
346
347 return res;
348}
349
350jobject Runtime::CallJSMethodNative(JNIEnv* _env, jobject obj,
351 jint javaObjectID, jstring methodName,

Callers 1

Calls 4

GetContextMethod · 0.95
ToLocalMethod · 0.80
IsEmptyMethod · 0.45

Tested by

no test coverage detected