-
|
Even with code like the following in a browser or Node.js, no error will occur.
Timer.clear documentationsays this, but is it necessary to set a cleared ID to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Are you suggesting that To try that, update the start of void xs_timer_clear(xsMachine *the)
{
modTimerScript ts;
if (0 == xsmcArgc)
return;
modTimer timer = xsGetHostDataIf(xsArg(0));
if ((C_NULL == timer) || (xsGetHostHooksIf(xsArg(0)) != &modTimerHooks))
return;
ts = (modTimerScript)modTimerGetRefcon(timer);The unit test at /*---
description:
flags: [async, module]
---*/
import Timer from "timer";
Timer.clear(Timer.set(() => {}, 1));
Timer.clear(); // "no argument"
Timer.clear(new $TESTMC.HostObject); // "clear arbitrary host object"
Timer.clear(undefined);
Timer.clear(null);
const t = Timer.set(() => {}, 1);
Timer.clear(t);
Timer.clear(t); // "double clear")
let t1, t2, t3, t4;
t1 = Timer.set(() => {
Timer.clear(t2);
}, 2);
t2 = Timer.set(() => {
$DONE("t2 should not be called");
}, 4);
t3 = Timer.set(() => {
$DONE("t3 should not be called");
}, 3);
Timer.clear(t3);
// crash prior to commit c317ea0
t4 = Timer.set(() => {
Timer.set(() => {
try {
Timer.clear(t4);
}
catch (e) {
$DONE(e);
}
}, 1);
}, 1);
Timer.set(() => $DONE(), 8); |
Beta Was this translation helpful? Give feedback.
-
I hadn’t thought that far, but I wanted to know the intended behavior of |
Beta Was this translation helpful? Give feedback.
Timer.clear()is notclearInterval(). The documentation accurately describes the behavior. The unit tests confirm the expected error on double close.Are you suggesting that
Timer.clear()adopt the silent failure behavior ofclearInterval()? That is convenient for emulation ofclearInterval(). It is inconsistent with the general behavior of the Moddable SDK (and ECMAScript) which is to throw an exception on invalid object. There is an exception to this onclose()which is generally safe to call multiple time (and clear is analogous to close).To try that, update the start of
xs_timer_clear: