| 892 | } |
| 893 | |
| 894 | Local<Value> CallbackHandlers::CallJSMethod(Isolate *isolate, JNIEnv *_env, |
| 895 | const Local<Object> &jsObject, const string &methodName, |
| 896 | jobjectArray args) { |
| 897 | SET_PROFILER_FRAME(); |
| 898 | |
| 899 | JEnv env(_env); |
| 900 | Local<Value> result; |
| 901 | |
| 902 | auto context = Runtime::GetRuntime(isolate)->GetContext(); |
| 903 | auto method = jsObject->Get(context, ArgConverter::ConvertToV8String(isolate, |
| 904 | methodName)).ToLocalChecked(); |
| 905 | |
| 906 | if (method.IsEmpty() || method->IsUndefined()) { |
| 907 | stringstream ss; |
| 908 | ss << "Cannot find method '" << methodName << "' implementation"; |
| 909 | throw NativeScriptException(ss.str()); |
| 910 | } else if (!method->IsFunction()) { |
| 911 | stringstream ss; |
| 912 | ss << "Property '" << methodName << "' is not a function"; |
| 913 | throw NativeScriptException(ss.str()); |
| 914 | } else { |
| 915 | EscapableHandleScope handleScope(isolate); |
| 916 | |
| 917 | auto jsMethod = method.As<Function>(); |
| 918 | auto jsArgs = ArgConverter::ConvertJavaArgsToJsArgs(context, args); |
| 919 | int argc = jsArgs->Length(); |
| 920 | |
| 921 | std::vector<Local<Value>> arguments(argc); |
| 922 | for (int i = 0; i < argc; i++) { |
| 923 | arguments[i] = jsArgs->Get(context, i).ToLocalChecked(); |
| 924 | } |
| 925 | |
| 926 | TryCatch tc(isolate); |
| 927 | Local<Value> jsResult; |
| 928 | { |
| 929 | SET_PROFILER_FRAME(); |
| 930 | jsMethod->Call(context, jsObject, argc, argc == 0 ? nullptr : arguments.data()).ToLocal( |
| 931 | &jsResult); |
| 932 | } |
| 933 | |
| 934 | //TODO: if javaResult is a pure js object create a java object that represents this object in java land |
| 935 | |
| 936 | if (tc.HasCaught()) { |
| 937 | stringstream ss; |
| 938 | ss << "Calling js method " << methodName << " failed"; |
| 939 | throw NativeScriptException(tc, ss.str()); |
| 940 | } |
| 941 | |
| 942 | result = handleScope.Escape(jsResult); |
| 943 | } |
| 944 | |
| 945 | return result; |
| 946 | } |
| 947 | |
| 948 | Local<Object> CallbackHandlers::FindClass(Isolate *isolate, const string &className) { |
| 949 | Local<Object> clazz; |
nothing calls this directly
no test coverage detected