Skip to content

Macros to automatically call jerry_release_value? #1836

@martijnthe

Description

@martijnthe

Zephyr.js has a nice macro to declare const jerry_value_ts. It leverages the __attribute__ ((__cleanup__(...))) feature to automatically call jerry_release_value() on the value when the variable goes out of scope:

https://github.com/01org/zephyr.js/blob/ecf2fba29de4dafbd1c8e5b6b3ece636ac237213/src/zjs_util.h#L185

Example use:

... {
  ZVAL global = jerry_get_global_object();
  ...
  // no need to call jerry_release_value(global);
  // it will be released automatically by the cleanup function.
}

The advantages are quite obvious I think. The disadvantage is that it needs to be supported by the compiler. FWIW, GCC and clang support it.

Does it make sense to add a similar utility to jerry-ext?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions