• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Autorelease values
2
3## JERRYX_AR_VALUE_T
4
5**Summary**
6
7Macro for `const jerry_value_t` for which jerry_release_value() is
8automatically called when the variable goes out of scope.
9
10*Note*: The macro depends on compiler support. For GCC and LLVM/clang, the macro is implemented
11using the `__cleanup__` variable attribute. For other compilers, no support has been added yet.
12
13**Example**
14
15[doctest]: # (test="compile", name="11.EXT-REFERENCE-AUTORELEASE.c")
16
17```c
18#include "jerryscript.h"
19#include "jerryscript-ext/autorelease.h"
20
21static void
22foo (bool enable)
23{
24  JERRYX_AR_VALUE_T bar = jerry_create_string ((const jerry_char_t *) "...");
25
26  if (enable)
27  {
28    JERRYX_AR_VALUE_T baz = jerry_get_global_object ();
29
30    /* bar and baz can now be used. */
31
32    /*
33     * jerry_release_value (baz) and jerry_release_value (bar) is called automatically before
34     * returning, because `baz` and `bar` go out of scope.
35     */
36    return;
37  }
38
39  /*
40   * jerry_release_value (bar) is called automatically when the function returns,
41   * because `bar` goes out of scope.
42   */
43}
44```
45
46**See also**
47
48- [jerry_value_t](../docs/02.API-REFERENCE.md#jerry_value_t)
49- [jerry_acquire_value](../docs/02.API-REFERENCE.md#jerry_acquire_value)
50- [jerry_release_value](../docs/02.API-REFERENCE.md#jerry_release_value)
51