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);
} /* 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.
*

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_number (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_string (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
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");
else jerry_value_free(eval);
if (jerry_value_is_exception(eval)) return jerry_undefined();
jerry_value_free(eval);
return jerry_object_get_sz(global, "$bm_rt");
}

View file

@ -40,7 +40,6 @@ public:
template<typename Property, typename NumType>
bool result(float frameNo, NumType& out, LottieExpression* exp)
{
auto success = true;
auto bm_rt = evaluate(frameNo, exp);
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);
} else {
TVGERR("LOTTIE", "Failed dispatching a Value!");
success = false;
return false;
}
jerry_value_free(bm_rt);
return success;
return true;
}
template<typename Property>
bool result(float frameNo, Point& out, LottieExpression* exp)
{
auto success = true;
auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_object(bm_rt)) {
@ -74,58 +72,55 @@ public:
}
} else {
TVGERR("LOTTIE", "Failed dispatching Point!");
success = false;
return false;
}
jerry_value_free(bm_rt);
return success;
return true;
}
template<typename Property>
bool result(float frameNo, RGB24& out, LottieExpression* exp)
{
auto success = true;
auto bm_rt = evaluate(frameNo, exp);
if (auto color = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
out = (*color)(frameNo);
} else {
TVGERR("LOTTIE", "Failed dispatching Color!");
success = false;
return false;
}
jerry_value_free(bm_rt);
return success;
return true;
}
template<typename Property>
bool result(float frameNo, Fill* fill, LottieExpression* exp)
{
auto success = true;
auto bm_rt = evaluate(frameNo, exp);
if (auto colorStop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
(*colorStop)(frameNo, fill, this);
} else {
TVGERR("LOTTIE", "Failed dispatching ColorStop!");
success = false;
return false;
}
jerry_value_free(bm_rt);
return success;
return true;
}
template<typename Property>
bool result(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, LottieExpression* exp)
{
auto success = true;
auto bm_rt = evaluate(frameNo, exp);
if (auto pathset = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
(*pathset)(frameNo, cmds, pts, transform);
} else {
TVGERR("LOTTIE", "Failed dispatching PathSet!");
success = false;
return false;
}
jerry_value_free(bm_rt);
return success;
return true;
}
void update(float curTime);