| 113 | } |
| 114 | |
| 115 | bool JsArgConverter::ConvertArg(const Local<Value> &arg, int index) { |
| 116 | bool success = false; |
| 117 | |
| 118 | char buff[1024]; |
| 119 | |
| 120 | const auto &typeSignature = m_tokens.at(index); |
| 121 | |
| 122 | if (arg.IsEmpty()) { |
| 123 | SetConvertedObject(index, nullptr); |
| 124 | success = false; |
| 125 | } else if (arg->IsArray()) { |
| 126 | success = typeSignature[0] == '['; |
| 127 | |
| 128 | if (success) { |
| 129 | auto jsArr = Local<Array>::Cast(arg); |
| 130 | success = ConvertJavaScriptArray(jsArr, index); |
| 131 | } |
| 132 | |
| 133 | if (!success) { |
| 134 | sprintf(buff, "Cannot convert array to %s at index %d", typeSignature.c_str(), index); |
| 135 | } |
| 136 | } else if (arg->IsNumber() || arg->IsNumberObject()) { |
| 137 | success = ConvertJavaScriptNumber(arg, index); |
| 138 | |
| 139 | if (!success) { |
| 140 | sprintf(buff, "Cannot convert number to %s at index %d", typeSignature.c_str(), index); |
| 141 | } |
| 142 | } else if (arg->IsBoolean() || arg->IsBooleanObject()) { |
| 143 | success = ConvertJavaScriptBoolean(arg, index); |
| 144 | |
| 145 | if (!success) { |
| 146 | sprintf(buff, "Cannot convert boolean to %s at index %d", typeSignature.c_str(), index); |
| 147 | } |
| 148 | } else if (arg->IsString() || arg->IsStringObject()) { |
| 149 | success = ConvertJavaScriptString(arg, index); |
| 150 | |
| 151 | if (!success) { |
| 152 | sprintf(buff, "Cannot convert string to %s at index %d", typeSignature.c_str(), index); |
| 153 | } |
| 154 | } else if (arg->IsObject()) { |
| 155 | auto context = m_isolate->GetCurrentContext(); |
| 156 | auto jsObject = arg->ToObject(context).ToLocalChecked(); |
| 157 | |
| 158 | auto castType = NumericCasts::GetCastType(m_isolate, jsObject); |
| 159 | |
| 160 | Local<Value> castValue; |
| 161 | JniLocalRef obj; |
| 162 | |
| 163 | auto runtime = Runtime::GetRuntime(m_isolate); |
| 164 | auto objectManager = runtime->GetObjectManager(); |
| 165 | |
| 166 | JEnv env; |
| 167 | |
| 168 | switch (castType) { |
| 169 | case CastType::Char: |
| 170 | castValue = NumericCasts::GetCastValue(jsObject); |
| 171 | if (castValue->IsString()) { |
| 172 | string value = ArgConverter::ConvertToString( |
nothing calls this directly
no test coverage detected