Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
[gpio] Fix to allow JerryScript to release onchange callback (#755)
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Jones <[email protected]>
  • Loading branch information
brianjjones authored and grgustaf committed Feb 22, 2017
1 parent 7c5ff3c commit 2e8c582
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/zjs_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ typedef struct gpio_handle {
uint32_t value; // Value of the pin
zjs_callback_id callbackId; // ID for the C callback
jerry_value_t pin_obj; // Pin object returned from open()
jerry_value_t onchange_func; // Function registered to onChange
jerry_value_t open_rval;
uint32_t last;
uint8_t edge_both;
Expand Down Expand Up @@ -119,14 +118,8 @@ static void gpio_c_callback(void *h, void *args)
// Put the boolean GPIO trigger value in the object
zjs_obj_add_boolean(event, val, "value");

// Only acquire once, once we have it just keep using it.
// It will be released in close()
if (!handle->onchange_func) {
handle->onchange_func = jerry_acquire_value(onchange_func);
}

// Call the JS callback
jerry_call_function(handle->onchange_func, ZJS_UNDEFINED, &event, 1);
jerry_call_function(onchange_func, ZJS_UNDEFINED, &event, 1);

jerry_release_value(event);
} else {
Expand Down Expand Up @@ -239,9 +232,6 @@ static jerry_value_t zjs_gpio_pin_write(const jerry_value_t function_obj,
static void zjs_gpio_close(gpio_handle_t *handle)
{
zjs_remove_callback(handle->callbackId);
if (handle->onchange_func) {
jerry_release_value(handle->onchange_func);
}
gpio_remove_callback(handle->port, &handle->callback);
handle->closed = true;
}
Expand Down

0 comments on commit 2e8c582

Please sign in to comment.