Merge pull request #15807 from mogemimi/add-switch-default-case

Add missing default cases within switch block for JS and Lua JavaBridge
This commit is contained in:
minggo 2016-06-12 10:37:05 +08:00 committed by GitHub
commit 109f572bf6
2 changed files with 32 additions and 0 deletions

View File

@ -83,11 +83,18 @@ bool JavascriptJavaBridge::CallInfo::execute(void)
break; break;
case TypeString: case TypeString:
{
m_retjstring = (jstring)m_env->CallStaticObjectMethod(m_classID, m_methodID); m_retjstring = (jstring)m_env->CallStaticObjectMethod(m_classID, m_methodID);
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjstring); std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjstring);
m_ret.stringValue = new string(strValue); m_ret.stringValue = new string(strValue);
break; break;
}
default:
m_error = JSJ_ERR_TYPE_NOT_SUPPORT;
LOGD("Return type '%d' is not supported", static_cast<int>(m_returnType));
return false;
} }
if (m_env->ExceptionCheck() == JNI_TRUE) if (m_env->ExceptionCheck() == JNI_TRUE)
@ -123,10 +130,17 @@ bool JavascriptJavaBridge::CallInfo::executeWithArgs(jvalue *args)
break; break;
case TypeString: case TypeString:
{
m_retjstring = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args); m_retjstring = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args);
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjstring); std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjstring);
m_ret.stringValue = new string(strValue); m_ret.stringValue = new string(strValue);
break; break;
}
default:
m_error = JSJ_ERR_TYPE_NOT_SUPPORT;
LOGD("Return type '%d' is not supported", static_cast<int>(m_returnType));
return false;
} }
if (m_env->ExceptionCheck() == JNI_TRUE) if (m_env->ExceptionCheck() == JNI_TRUE)
@ -279,6 +293,8 @@ JS::Value JavascriptJavaBridge::convertReturnValue(JSContext *cx, ReturnValue re
return BOOLEAN_TO_JSVAL(retValue.boolValue); return BOOLEAN_TO_JSVAL(retValue.boolValue);
case TypeString: case TypeString:
return c_string_to_jsval(cx, retValue.stringValue->c_str(),retValue.stringValue->size()); return c_string_to_jsval(cx, retValue.stringValue->c_str(),retValue.stringValue->size());
default:
break;
} }
return ret; return ret;

View File

@ -40,10 +40,17 @@ bool LuaJavaBridge::CallInfo::execute(void)
break; break;
case TypeString: case TypeString:
{
m_retjs = (jstring)m_env->CallStaticObjectMethod(m_classID, m_methodID); m_retjs = (jstring)m_env->CallStaticObjectMethod(m_classID, m_methodID);
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs); std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs);
m_ret.stringValue = new string(strValue); m_ret.stringValue = new string(strValue);
break; break;
}
default:
m_error = LUAJ_ERR_TYPE_NOT_SUPPORT;
LOGD("Return type '%d' is not supported", static_cast<int>(m_returnType));
return false;
} }
if (m_env->ExceptionCheck() == JNI_TRUE) if (m_env->ExceptionCheck() == JNI_TRUE)
@ -79,10 +86,17 @@ bool LuaJavaBridge::CallInfo::executeWithArgs(jvalue *args)
break; break;
case TypeString: case TypeString:
{
m_retjs = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args); m_retjs = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args);
std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs); std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(m_env, m_retjs);
m_ret.stringValue = new string(strValue); m_ret.stringValue = new string(strValue);
break; break;
}
default:
m_error = LUAJ_ERR_TYPE_NOT_SUPPORT;
LOGD("Return type '%d' is not supported", static_cast<int>(m_returnType));
return false;
} }
if (m_env->ExceptionCheck() == JNI_TRUE) if (m_env->ExceptionCheck() == JNI_TRUE)
@ -118,6 +132,8 @@ int LuaJavaBridge::CallInfo::pushReturnValue(lua_State *L)
case TypeString: case TypeString:
lua_pushstring(L, m_ret.stringValue->c_str()); lua_pushstring(L, m_ret.stringValue->c_str());
return 1; return 1;
default:
break;
} }
return 0; return 0;