Skip to content

Commit 8bd7a2f

Browse files
committed
Timer.clear silently ignores undefined and null (matches clearTimeout)
1 parent c8b9fbb commit 8bd7a2f

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

documentation/base/base.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Base
2-
Copyright 2017-2020 Moddable Tech, Inc.<BR>
3-
Revised: October 7, 2020
2+
Copyright 2017-2022 Moddable Tech, Inc.<BR>
3+
Revised: March 8, 2022
44

55
**Warning**: These notes are preliminary. Omissions and errors are likely. If you encounter problems, please ask for assistance.
66

@@ -98,6 +98,9 @@ Timer.clear(aTimer);
9898

9999
> **Note**: Immediate and one shot timers are automatically cleared after invoking their callback function. There is no need to call `clear` except to cancel the timer before it fires.
100100
101+
> **Note**: If `Timer.clear` is passed a value of `undefined` or `null` for the ID, no exception is generated.
102+
103+
101104
***
102105

103106
### `Timer.delay(ms)`

modules/base/timer/modTimer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ void xs_timer_schedule(xsMachine *the)
126126
void xs_timer_clear(xsMachine *the)
127127
{
128128
modTimerScript ts;
129-
modTimer timer = xsmcGetHostDataValidate(xsArg(0), (void *)&modTimerHooks);
129+
modTimer timer;
130130

131+
if (xsReferenceType != xsmcTypeOf(xsArg(0)))
132+
return;
133+
134+
timer = xsmcGetHostDataValidate(xsArg(0), (void *)&modTimerHooks);
131135
ts = (modTimerScript)modTimerGetRefcon(timer);
132136
xsForget(ts->self);
133137
ts->callback = NULL;

xs/sources/xsAPI.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ txKind fxTypeOf(txMachine* the, txSlot* theSlot)
5353
return XS_STRING_KIND;
5454
if (theSlot->kind == XS_BIGINT_X_KIND)
5555
return XS_BIGINT_KIND;
56+
#ifdef mxHostFunctionPrimitive
57+
if (theSlot->kind == XS_HOST_FUNCTION_KIND)
58+
return XS_REFERENCE_KIND;
59+
#endif
5660
return theSlot->kind;
5761
}
5862

0 commit comments

Comments
 (0)