lottie/expressions: ++exceptional handling.

Add an exceptional handling if interpreting code is failed.
This commit is contained in:
Hermet Park 2024-05-04 15:54:59 +09:00 committed by Hermet Park
parent ac477d6896
commit fca4ef3109
4 changed files with 28 additions and 19 deletions

View file

@ -180,6 +180,18 @@ jerry_current_realm (void)
return ecma_make_object_value (global_obj_p); return ecma_make_object_value (global_obj_p);
} /* jerry_current_realm */ } /* jerry_current_realm */
/**
* Check if the specified value is an error or abort value.
*
* @return true - if the specified value is an error value,
* false - otherwise
*/
bool
jerry_value_is_exception (const jerry_value_t value) /**< api value */
{
return ecma_is_value_exception (value);
} /* jerry_value_is_exception */
/** /**
* Check if the specified value is number. * Check if the specified value is number.
* *

View file

@ -29,6 +29,7 @@ jerry_value_t jerry_run (const jerry_value_t script);
bool jerry_value_is_undefined (const jerry_value_t value); bool jerry_value_is_undefined (const jerry_value_t value);
bool jerry_value_is_number (const jerry_value_t value); bool jerry_value_is_number (const jerry_value_t value);
bool jerry_value_is_object (const jerry_value_t value); bool jerry_value_is_object (const jerry_value_t value);
bool jerry_value_is_exception (const jerry_value_t value);
jerry_value_t jerry_value_to_object (const jerry_value_t value); jerry_value_t jerry_value_to_object (const jerry_value_t value);
jerry_value_t jerry_value_to_string (const jerry_value_t value); jerry_value_t jerry_value_to_string (const jerry_value_t value);
double jerry_value_as_number (const jerry_value_t value); double jerry_value_as_number (const jerry_value_t value);

View file

@ -1219,8 +1219,9 @@ jerry_value_t LottieExpressions::evaluate(float frameNo, LottieExpression* exp)
//evaluate the code //evaluate the code
auto eval = jerry_eval((jerry_char_t *) exp->code, strlen(exp->code), JERRY_PARSE_NO_OPTS); auto eval = jerry_eval((jerry_char_t *) exp->code, strlen(exp->code), JERRY_PARSE_NO_OPTS);
if (jerry_value_is_undefined(eval)) TVGERR("LOTTIE", "Expression error"); if (jerry_value_is_exception(eval)) return jerry_undefined();
else jerry_value_free(eval);
jerry_value_free(eval);
return jerry_object_get_sz(global, "$bm_rt"); return jerry_object_get_sz(global, "$bm_rt");
} }
@ -1283,4 +1284,4 @@ void LottieExpressions::retrieve(LottieExpressions* instance)
} }
#endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT #endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT

View file

@ -40,7 +40,6 @@ public:
template<typename Property, typename NumType> template<typename Property, typename NumType>
bool result(float frameNo, NumType& out, LottieExpression* exp) bool result(float frameNo, NumType& out, LottieExpression* exp)
{ {
auto success = true;
auto bm_rt = evaluate(frameNo, exp); auto bm_rt = evaluate(frameNo, exp);
if (auto prop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) { if (auto prop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
@ -49,16 +48,15 @@ public:
out = (NumType) jerry_value_as_number(bm_rt); out = (NumType) jerry_value_as_number(bm_rt);
} else { } else {
TVGERR("LOTTIE", "Failed dispatching a Value!"); TVGERR("LOTTIE", "Failed dispatching a Value!");
success = false; return false;
} }
jerry_value_free(bm_rt); jerry_value_free(bm_rt);
return success; return true;
} }
template<typename Property> template<typename Property>
bool result(float frameNo, Point& out, LottieExpression* exp) bool result(float frameNo, Point& out, LottieExpression* exp)
{ {
auto success = true;
auto bm_rt = evaluate(frameNo, exp); auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_object(bm_rt)) { if (jerry_value_is_object(bm_rt)) {
@ -74,58 +72,55 @@ public:
} }
} else { } else {
TVGERR("LOTTIE", "Failed dispatching Point!"); TVGERR("LOTTIE", "Failed dispatching Point!");
success = false; return false;
} }
jerry_value_free(bm_rt); jerry_value_free(bm_rt);
return success; return true;
} }
template<typename Property> template<typename Property>
bool result(float frameNo, RGB24& out, LottieExpression* exp) bool result(float frameNo, RGB24& out, LottieExpression* exp)
{ {
auto success = true;
auto bm_rt = evaluate(frameNo, exp); auto bm_rt = evaluate(frameNo, exp);
if (auto color = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) { if (auto color = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
out = (*color)(frameNo); out = (*color)(frameNo);
} else { } else {
TVGERR("LOTTIE", "Failed dispatching Color!"); TVGERR("LOTTIE", "Failed dispatching Color!");
success = false; return false;
} }
jerry_value_free(bm_rt); jerry_value_free(bm_rt);
return success; return true;
} }
template<typename Property> template<typename Property>
bool result(float frameNo, Fill* fill, LottieExpression* exp) bool result(float frameNo, Fill* fill, LottieExpression* exp)
{ {
auto success = true;
auto bm_rt = evaluate(frameNo, exp); auto bm_rt = evaluate(frameNo, exp);
if (auto colorStop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) { if (auto colorStop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
(*colorStop)(frameNo, fill, this); (*colorStop)(frameNo, fill, this);
} else { } else {
TVGERR("LOTTIE", "Failed dispatching ColorStop!"); TVGERR("LOTTIE", "Failed dispatching ColorStop!");
success = false; return false;
} }
jerry_value_free(bm_rt); jerry_value_free(bm_rt);
return success; return true;
} }
template<typename Property> template<typename Property>
bool result(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, LottieExpression* exp) bool result(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, LottieExpression* exp)
{ {
auto success = true;
auto bm_rt = evaluate(frameNo, exp); auto bm_rt = evaluate(frameNo, exp);
if (auto pathset = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) { if (auto pathset = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
(*pathset)(frameNo, cmds, pts, transform); (*pathset)(frameNo, cmds, pts, transform);
} else { } else {
TVGERR("LOTTIE", "Failed dispatching PathSet!"); TVGERR("LOTTIE", "Failed dispatching PathSet!");
success = false; return false;
} }
jerry_value_free(bm_rt); jerry_value_free(bm_rt);
return success; return true;
} }
void update(float curTime); void update(float curTime);
@ -167,4 +162,4 @@ struct LottieExpressions
#endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT #endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT
#endif //_TVG_LOTTIE_EXPRESSIONS_H_ #endif //_TVG_LOTTIE_EXPRESSIONS_H_