Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v8): add log for call function cpp buffer fail #4010

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions android/sdk/src/main/jni/src/bridge/java2js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ extern std::shared_ptr<V8InspectorClientImpl> global_inspector;

const char kHippyBridgeName[] = "hippyBridge";

static std::string binaryBufferToHexString(const std::string& buffer) {
std::ostringstream oss;
for (const auto& byte : buffer) {
// 将每个字节转换为两位十六进制数
oss << "0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte) << ",";
}
return oss.str();
}


void CallFunction(JNIEnv* j_env,
__unused jobject j_obj,
jstring j_action,
Expand Down Expand Up @@ -140,6 +150,7 @@ void CallFunction(JNIEnv* j_env,
isolate, reinterpret_cast<const uint8_t*>(buffer_data_.c_str()),
buffer_data_.length());
TDF_BASE_CHECK(deserializer.ReadHeader(ctx).FromMaybe(false));

v8::MaybeLocal<v8::Value> ret = deserializer.ReadValue(ctx);
if (!ret.IsEmpty()) {
params = std::make_shared<hippy::napi::V8CtxValue>(
Expand All @@ -149,6 +160,11 @@ void CallFunction(JNIEnv* j_env,
if (try_catch.HasCaught()) {
unicode_string_view msg = try_catch.GetExceptionMsg();
j_msg = JniUtils::StrViewToJString(j_env, msg);

TDF_BASE_DLOG(ERROR) << "cpp CallFunction, error, msg: " << msg;
auto logBufferString = binaryBufferToHexString(buffer_data_);
TDF_BASE_DLOG(ERROR) << "cpp CallFunction, error, buffer len:" << buffer_data_.length() << ", buffer: = " << logBufferString << ", end.";

} else {
j_msg = JniUtils::StrViewToJString(j_env, u"deserializer error");
}
Expand Down
Loading