disable API calls for 'object free callback'
Closed this issue · 6 comments
Object free callback needs to disable API calls while in execution.
Simple flag, in global, will do.
ruben-ayrapetyan:
bool jerry_api_is_enabled = true;
JERRY_ASSERT (jerry_api_is_enabled);
if (!jerry_api_is_enabled)
{
return ...;
}
or
if (!jerry_api_is_enabled)
{
JERRY_UNREACHABLE ();
}
and two internal interfaces: jerry_disable_api () and jerry_restore_api ()
added "api_availability" branch and initial code 6646a34 committed.
development branch has moved to seanshpark/api_availability_dev
Review comments:
+#define CHECK_API_AVAILABILITY(RETVAL) \
+ do { \
+ JERRY_ASSERT(jerry_api_availability); \
+ if (!jerry_api_availability) \
+ return RETVAL; \
+ } while (false);
As calling unavailable API is incorrect anyway, maybe it is better to implement CHECK_API_AVAILABILITY as following:
/**
* Assert that it is correct to call API in current state.
*
* Note:
* By convention, there can be some states when API could not be invoked.
*
* While, API can be invoked jerry_api_available flag is set,
* and while it is incorrect to invoke API - it is not set.
*
* The procedure checks that it is correct to invoke API in current state.
* If it is correct, procedure just returns; otherwise - engine is stopped.
*
* Note:
* TODO: Add states when API could not be invoked, when they would appear.
* // "API could not be invoked in the following cases:"
* // - ... .
*/
static void
jerry_assert_api_available (void)
{
if (!jerry_api_available)
{
JERRY_UNREACHABLE ();
}
} /* jerry_assert_api_available */
/**
* Turn on API availability
*/
static void
jerry_make_api_available (void)
{
jerry_api_available = true;
} /* jerry_make_api_available */
/**
* Turn off API availability
*/
static void
jerry_make_api_unavailable (void)
{
jerry_api_available = false;
} /* jerry_make_api_unavailable */
thank you for the code. it's applied to brach seanshpark/jerryscript
precommit test (actually after commit) done.
make precommit -s -j8
I'll merge this code to objfreecb_dev when it's ok.
#10 done