From cfa4fdd1ef79e523bf64901c981c16511bc646af Mon Sep 17 00:00:00 2001 From: fbmrk Date: Wed, 5 Jul 2017 23:09:10 +0200 Subject: [PATCH] target: mbedos5: unnecessary acquire and argument check bug (#1892) When you cleanup the engine you got an `ECMA_STRING_IS_REF_EQUALS_TO_ONE (string_p)` error. There is an unnecessary call of jerry_acquire_value which causes the problem. Also in the InterruptIn-js.cpp file there is a wrong check of an argument. JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu --- .../jerryscript-mbed-drivers/source/InterruptIn-js.cpp | 6 ++++-- .../jerryscript-mbed-event-loop/EventLoop.h | 5 ----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp index ff9388419..d4b6d65d3 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-drivers/source/InterruptIn-js.cpp @@ -29,7 +29,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) { CHECK_ARGUMENT_COUNT(InterruptIn, rise, (args_count == 1)); // Detach the rise callback when InterruptIn::rise(null) is called - if (jerry_value_is_null(args[1])) { + if (jerry_value_is_null(args[0])) { uintptr_t native_handle; jerry_get_object_native_handle(this_obj, &native_handle); @@ -44,6 +44,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) { // Ensure that the EventLoop frees memory used by the callback. mbed::js::EventLoop::getInstance().dropCallback(cb_func); } + jerry_release_value(cb_func); this_interruptin->rise(0); @@ -82,7 +83,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) { CHECK_ARGUMENT_COUNT(InterruptIn, fall, (args_count == 1)); // Detach the fall callback when InterruptIn::fall(null) is called - if (jerry_value_is_null(args[1])) { + if (jerry_value_is_null(args[0])) { uintptr_t native_handle; jerry_get_object_native_handle(this_obj, &native_handle); @@ -97,6 +98,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) { // Ensure that the EventLoop frees memory used by the callback. mbed::js::EventLoop::getInstance().dropCallback(cb_func); } + jerry_release_value(cb_func); this_interruptin->fall(0); diff --git a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h index 6f28b8af3..99d855226 100644 --- a/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h +++ b/targets/mbedos5/jerryscript-mbed/jerryscript-mbed-event-loop/EventLoop.h @@ -52,9 +52,6 @@ class EventLoop { Callback wrapFunction(jerry_value_t f) { MBED_ASSERT(jerry_value_is_function(f)); - // not sure if this is necessary? - jerry_acquire_value(f); - // we need to return a callback that'll schedule this Callback cb_raw(this, &EventLoop::callback); BoundCallback *cb = new BoundCallback(cb_raw, f); @@ -65,8 +62,6 @@ class EventLoop { } void dropCallback(jerry_value_t f) { - jerry_release_value(f); - for (std::vector*> >::iterator it = bound_callbacks.begin(); it != bound_callbacks.end(); it++) { std::pair*> element = *it;