Skip to content

Lightpanda: the headless browser designed for AI and automation

remove deprecated setImmediate and clearImmediate

Pierre Tachoire322b0f433fe3
diff --git a/src/browser/tests/window/timers.html b/src/browser/tests/window/timers.html
index 2f4825528..e34bd3043 100644
--- a/src/browser/tests/window/timers.html
+++ b/src/browser/tests/window/timers.html
@@ -48,10 +48,19 @@
// Surprisingly, these don't fail but silently ignored.
clearTimeout(-1);
clearInterval(-2);
- clearImmediate(-3);
testing.expectEqual(true, true);
</script>
+<script id=no-setImmediate>
+ // setImmediate is non-standard (legacy IE/Edge only); no current browser
+ // exposes it. Libraries feature-detect it ahead of MessageChannel (React's
+ // scheduler does), and it would route them onto the clamped timer path.
+ testing.expectEqual('undefined', typeof setImmediate);
+ testing.expectEqual('undefined', typeof clearImmediate);
+ testing.expectEqual(false, 'setImmediate' in window);
+ testing.expectEqual(false, 'clearImmediate' in window);
+</script>
+
<script id=setTimeout-string-handler>
// Per HTML spec, TimerHandler = Function or DOMString. The string form
// is legacy but still required by the spec, and many sites (especially
diff --git a/src/browser/webapi/Timers.zig b/src/browser/webapi/Timers.zig
index bd501797e..ef01385d1 100644
--- a/src/browser/webapi/Timers.zig
+++ b/src/browser/webapi/Timers.zig
@@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// Shared bookkeeping for setTimeout / setInterval (and Window-only
-// setImmediate / requestAnimationFrame / requestIdleCallback). Both Window
+// requestAnimationFrame / requestIdleCallback). Both Window
// and WorkerGlobalScope embed a Timers and forward their JS-bridged
// methods through `schedule` / `clear`.
@@ -36,7 +36,7 @@ const CLAMP_NESTING = 5;
// from considering the page "done" forever (more commonly seen with requestAnimationFrame)
const BLOCKING_NESTING = 10;
-// Every pending timeout, interval, animation frame and setImmediate. Past
+// Every pending timeout, interval, animation frame and idle callback. Past
// the cap setTimeout throws, which no browser does; keep it a backstop for
// runaway pages, not a budget (a paginated storefront listing holds ~2.7k).
const MAX_CALLBACKS = 8192;
diff --git a/src/browser/webapi/Window.zig b/src/browser/webapi/Window.zig
index 5d0494189..f464c3c62 100644
--- a/src/browser/webapi/Window.zig
+++ b/src/browser/webapi/Window.zig
@@ -539,14 +539,6 @@ pub fn setInterval(self: *Window, handler: Timers.LegacyHandler, delay_ms: ?i32,
});
}
-pub fn setImmediate(self: *Window, cb: js.Function.Global, params: []js.Value.Global, exec: *js.Execution) !u32 {
- return self._timers.schedule(exec, cb, 0, .{
- .repeat = false,
- .params = params,
- .name = "window.setImmediate",
- });
-}
-
pub fn requestAnimationFrame(self: *Window, cb: js.Function.Global, exec: *js.Execution) !u32 {
return self._timers.schedule(exec, cb, 5, .{
.repeat = false,
@@ -568,10 +560,6 @@ fn clearInterval(self: *Window, id: u32) void {
self._timers.clear(id);
}
-fn clearImmediate(self: *Window, id: u32) void {
- self._timers.clear(id);
-}
-
pub fn cancelAnimationFrame(self: *Window, id: u32) void {
self._timers.clear(id);
}
@@ -1226,8 +1214,6 @@ pub const JsApi = struct {
pub const clearTimeout = bridge.function(Window.clearTimeout, .{});
pub const setInterval = bridge.function(Window.setInterval, .{});
pub const clearInterval = bridge.function(Window.clearInterval, .{});
- pub const setImmediate = bridge.function(Window.setImmediate, .{});
- pub const clearImmediate = bridge.function(Window.clearImmediate, .{});
pub const requestAnimationFrame = bridge.function(Window.requestAnimationFrame, .{});
pub const cancelAnimationFrame = bridge.function(Window.cancelAnimationFrame, .{});
pub const requestIdleCallback = bridge.function(Window.requestIdleCallback, .{});