Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ DECLARE_JS_WRAPPER_REGISTRATION (base) {
REGISTER_GLOBAL_FUNCTION(gc);
REGISTER_GLOBAL_FUNCTION(setInterval);
REGISTER_GLOBAL_FUNCTION(setTimeout);
REGISTER_GLOBAL_FUNCTION(clearInterval);
REGISTER_GLOBAL_FUNCTION(clearTimeout);
REGISTER_CLASS_CONSTRUCTOR(DigitalOut);
REGISTER_CLASS_CONSTRUCTOR(I2C);
REGISTER_CLASS_CONSTRUCTOR(InterruptIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
#include "jerryscript-mbed-library-registry/wrap_tools.h"

DECLARE_GLOBAL_FUNCTION(setInterval);
DECLARE_GLOBAL_FUNCTION(clearInterval);

#endif // _JERRYSCRIPT_MBED_DRIVERS_SET_INTERVAL_H
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
#include "jerryscript-mbed-library-registry/wrap_tools.h"

DECLARE_GLOBAL_FUNCTION(setTimeout);
DECLARE_GLOBAL_FUNCTION(clearTimeout);

#endif // _JERRYSCRIPT_MBED_DRIVERS_SET_TIMEOUT_H
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ DECLARE_GLOBAL_FUNCTION(setInterval) {
jerry_acquire_value(args[0]);
int interval = int(jerry_get_number_value(args[1]));

mbed::js::EventLoop::getInstance().getQueue().call_every(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0);
int id = mbed::js::EventLoop::getInstance().getQueue().call_every(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0);

return jerry_create_number(id);
}

/**
* clearInterval (native JavaScript function)
*
* Cancel an event that was previously scheduled via setInterval.
*
* @param id ID of the timeout event, returned by setInterval.
*/
DECLARE_GLOBAL_FUNCTION(clearInterval) {
CHECK_ARGUMENT_COUNT(global, clearInterval, (args_count == 1));
CHECK_ARGUMENT_TYPE_ALWAYS(global, clearInterval, 0, number);

int id = int(jerry_get_number_value(args[0]));

mbed::js::EventLoop::getInstance().getQueue().cancel(id);

return jerry_create_undefined();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,25 @@ DECLARE_GLOBAL_FUNCTION(setTimeout) {
jerry_acquire_value(args[0]);
int interval = int(jerry_get_number_value(args[1]));

mbed::js::EventLoop::getInstance().getQueue().call_in(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0);
int id = mbed::js::EventLoop::getInstance().getQueue().call_in(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0);

return jerry_create_number(id);
}

/**
* clearTimeout (native JavaScript function)
*
* Cancel an event that was previously scheduled via setTimeout.
*
* @param id ID of the timeout event, returned by setTimeout.
*/
DECLARE_GLOBAL_FUNCTION(clearTimeout) {
CHECK_ARGUMENT_COUNT(global, clearTimeout, (args_count == 1));
CHECK_ARGUMENT_TYPE_ALWAYS(global, clearTimeout, 0, number);

int id = int(jerry_get_number_value(args[0]));

mbed::js::EventLoop::getInstance().getQueue().cancel(id);

return jerry_create_undefined();
}