Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use primordials for extensions/timers #11234

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
18 changes: 14 additions & 4 deletions extensions/timers/01_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

((window) => {
const core = window.Deno.core;
const {
Map,
Date,
Error,
ArrayPrototypePush,
MathMax,
TypeError,
Number,
String,
} = window.__bootstrap.primordials;

// Shamelessly cribbed from extensions/fetch/11_streams.js
class AssertionError extends Error {
Expand Down Expand Up @@ -363,7 +373,7 @@
// With the list dropped, the timer is no longer scheduled.
timer.scheduled = false;
// Place the callback to pending timers to fire.
pendingFireTimers.push(timer);
ArrayPrototypePush(pendingFireTimers, timer);
}
}
setOrClearGlobalTimeout(nextDueNode && nextDueNode.due, now);
Expand All @@ -388,7 +398,7 @@
dueNode = maybeNewDueNode;
}
// Append the newly scheduled timer to the list and mark it as scheduled.
dueNode.timers.push(timer);
ArrayPrototypePush(dueNode.timers, timer);
timer.scheduled = true;
// If the new timer is scheduled to fire before any timer that existed before,
// update the global timeout to reflect this.
Expand Down Expand Up @@ -450,7 +460,7 @@
// Interval timer: compute when timer was supposed to fire next.
// However make sure to never schedule the next interval in the past.
const now = OriginalDateNow();
timer.due = Math.max(now, timer.due + timer.delay);
timer.due = MathMax(now, timer.due + timer.delay);
schedule(timer, now);
}
// Call the user callback. Intermediate assignment is to avoid leaking `this`
Expand Down Expand Up @@ -497,7 +507,7 @@
);
delay = 1;
}
delay = Math.max(0, delay | 0);
delay = MathMax(0, delay | 0);

// Create a new, unscheduled timer object.
const timer = {
Expand Down
7 changes: 5 additions & 2 deletions extensions/timers/02_performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"use strict";

((window) => {
const { ArrayPrototypePush, Symbol, TypeError, JSON, Object } =
window.__bootstrap.primordials;

const { webidl, structuredClone } = window.__bootstrap;
const { opNow } = window.__bootstrap.timers;
const illegalConstructorKey = Symbol("illegalConstructorKey");
Expand Down Expand Up @@ -262,7 +265,7 @@
// throw a SyntaxError. - not implemented
const entry = new PerformanceMark(markName, options);
// 3.1.1.7 Queue entry - not implemented
performanceEntries.push(entry);
ArrayPrototypePush(performanceEntries, entry);
return entry;
}

Expand Down Expand Up @@ -343,7 +346,7 @@
: null,
illegalConstructorKey,
);
performanceEntries.push(entry);
ArrayPrototypePush(performanceEntries, entry);
return entry;
}

Expand Down