• Autorelease values
    • JERRYX_AR_VALUE_T

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
1. #include "jerryscript.h"
2. #include "jerryscript-ext/autorelease.h"
3. 4. static void
5. foo (bool enable)
6. {
7. JERRYX_AR_VALUE_T bar = jerry_create_string ((const jerry_char_t ) "...");
8. 9. if (enable)
10. {
11. JERRYX_AR_VALUE_T baz = jerry_get_global_object ();
12. 13. /
bar and baz can now be used. /
14. 15. /

16. * jerry_release_value (baz) and jerry_release_value (bar) is called automatically before
17. * returning, because baz and bar go out of scope.
18. /
19. return;
20. }
21. 22. /

23. * jerry_release_value (bar) is called automatically when the function returns,
24. * because bar goes out of scope.
25. */
26. }

See also
* jerry_value_t
* jerry_acquire_value
* jerry_release_value