Skip to content

Commit 91d5e3d

Browse files
committed
style: reformat using eslint
1 parent 54a6eac commit 91d5e3d

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

python/pythonmonkey/builtin_modules/timers.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* @author Tom Tang <[email protected]>
44
* @date May 2023
55
*/
6-
const internalBinding = require("internal-binding")
6+
const internalBinding = require('internal-binding');
77

88
const {
99
enqueueWithDelay,
1010
cancelByTimeoutId
11-
} = internalBinding("timers")
11+
} = internalBinding('timers');
1212

1313
/**
1414
* Implement the `setTimeout` global function
@@ -19,28 +19,30 @@ const {
1919
* @param {any[]} args additional arguments to be passed to the `handler`
2020
* @return {number} timeoutId
2121
*/
22-
function setTimeout(handler, delayMs = 0, ...args) {
22+
function setTimeout(handler, delayMs = 0, ...args)
23+
{
2324
// Ensure the first parameter is a function
2425
// We support passing a `code` string to `setTimeout` as the callback function
25-
if (typeof handler !== "function") {
26-
handler = new Function(handler)
26+
if (typeof handler !== 'function')
27+
{
28+
handler = new Function(handler);
2729
}
2830

2931
// `setTimeout` allows passing additional arguments to the callback, as spec-ed
3032
// FIXME (Tom Tang): the spec doesn't allow additional arguments to be passed if the original `handler` is not a function
31-
const thisArg = globalThis // HTML spec requires `thisArg` to be the global object
33+
const thisArg = globalThis; // HTML spec requires `thisArg` to be the global object
3234
// Wrap the job function into a bound function with the given additional arguments
3335
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
3436
/** @type {Function} */
35-
const boundHandler = handler.bind(thisArg, ...args)
37+
const boundHandler = handler.bind(thisArg, ...args);
3638

3739
// Get the delay time in seconds
3840
// JS `setTimeout` takes milliseconds, but Python takes seconds
39-
delayMs = Number(delayMs) || 0 // ensure the `delayMs` is a `number`, explicitly do type coercion
40-
if (delayMs < 0) { delayMs = 0 } // as spec-ed
41-
const delaySeconds = delayMs / 1000 // convert ms to s
41+
delayMs = Number(delayMs) || 0; // ensure the `delayMs` is a `number`, explicitly do type coercion
42+
if (delayMs < 0) { delayMs = 0; } // as spec-ed
43+
const delaySeconds = delayMs / 1000; // convert ms to s
4244

43-
return enqueueWithDelay(boundHandler, delaySeconds)
45+
return enqueueWithDelay(boundHandler, delaySeconds);
4446
}
4547

4648
/**
@@ -50,14 +52,17 @@ function setTimeout(handler, delayMs = 0, ...args) {
5052
* @param {number} timeoutId
5153
* @return {void}
5254
*/
53-
function clearTimeout(timeoutId) {
54-
return cancelByTimeoutId(timeoutId)
55+
function clearTimeout(timeoutId)
56+
{
57+
return cancelByTimeoutId(timeoutId);
5558
}
5659

57-
if (!globalThis.setTimeout) {
60+
if (!globalThis.setTimeout)
61+
{
5862
globalThis.setTimeout = setTimeout;
5963
}
60-
if (!globalThis.clearTimeout) {
64+
if (!globalThis.clearTimeout)
65+
{
6166
globalThis.clearTimeout = clearTimeout;
6267
}
6368

0 commit comments

Comments
 (0)