Skip to content

Commit

Permalink
fix(ext): enable prefer-primordials for internal TypeScript (#21813)
Browse files Browse the repository at this point in the history
Enabled prefer-primordials lint for ext/cron and ext/kv.
  • Loading branch information
petamoriken committed Jan 7, 2024
1 parent a731647 commit c2c115e
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 62 deletions.
21 changes: 15 additions & 6 deletions ext/cron/01_cron.ts
Original file line number Diff line number Diff line change
@@ -1,7 1,16 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { core, internals } from "ext:core/mod.js";
import { core, internals, primordials } from "ext:core/mod.js";
const {
ArrayPrototypeJoin,
NumberPrototypeToString,
TypeError,
} = primordials;
const {
isPromise,
} = core;
const {
op_cron_create,
op_cron_next,
} = core.ensureFastOps();

Expand All @@ -15,7 24,7 @@ export function formatToCronSchedule(
if (value === undefined) {
return "*";
} else if (typeof value === "number") {
return value.toString();
return NumberPrototypeToString(value);
} else {
const { exact } = value as { exact: number | number[] };
if (exact === undefined) {
Expand All @@ -39,9 48,9 @@ export function formatToCronSchedule(
}
} else {
if (typeof exact === "number") {
return exact.toString();
return NumberPrototypeToString(exact);
} else {
return exact.join(",");
return ArrayPrototypeJoin(exact, ",");
}
}
}
Expand Down Expand Up @@ -104,7 113,7 @@ function cron(
throw new TypeError("Deno.cron requires a handler");
}

const rid = core.ops.op_cron_create(
const rid = op_cron_create(
name,
schedule,
options?.backoffSchedule,
Expand All @@ -130,7 139,7 @@ function cron(
}
try {
const result = handler();
const _res = result instanceof Promise ? (await result) : result;
const _res = isPromise(result) ? (await result) : result;
success = true;
} catch (error) {
console.error(`Exception in cron handler ${name}`, error);
Expand Down
Loading

0 comments on commit c2c115e

Please sign in to comment.