mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Disable 02.API-REFERENCE-create-context.c, because it is based on pthread, and there is no pthread on Windows. Disable 11.EXT-REFERENCE-AUTORELEASE.c and test-ext-autorelease.c if compiler is MSVC, because MSVC doesn't support cleanup attribute. JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu
1.3 KiB
1.3 KiB
Autorelease values
JERRYX_AR_VALUE_T
Summary
Macro for const jerry_value_t for which jerry_release_value() is
automatically called when the variable goes out of scope.
Note: The macro depends on compiler support. For GCC and LLVM/clang, the macro is implemented
using the __cleanup__ variable attribute. For other compilers, no support has been added yet.
Example
#include "jerryscript.h"
#include "jerryscript-ext/autorelease.h"
static void
foo (bool enable)
{
JERRYX_AR_VALUE_T bar = jerry_create_string ((const jerry_char_t *) "...");
if (enable)
{
JERRYX_AR_VALUE_T baz = jerry_get_global_object ();
/* bar and baz can now be used. */
/*
* jerry_release_value (baz) and jerry_release_value (bar) is called automatically before
* returning, because `baz` and `bar` go out of scope.
*/
return;
}
/*
* jerry_release_value (bar) is called automatically when the function returns,
* because `bar` goes out of scope.
*/
}
See also