Skip to content
File

Blob: src/workerd/api/node/timers.c++

1.1 KB
1#include "timers.h"
2 
3#include <workerd/api/global-scope.h>
4#include <workerd/jsg/jsg.h>
5 
6namespace workerd::api::node {
7 
8// The setImmediate/clearImmediate methods are only exposed on globalThis if the
9// node_compat_v2 flag is set. However, we want them exposed via `node:timers`
10// generally when just the original node_compat is enabled. Therefore, we provide
11// this alternative route to the implementations on ServiceWorkerGlobalScope.
12jsg::Ref<Immediate> TimersUtil::setImmediate(jsg::Lock& js,
13 jsg::Function<void(jsg::Arguments<jsg::Value>)> function,
14 jsg::Arguments<jsg::Value> args) {
15 auto context = js.v8Context();
16 auto& global =
17 jsg::extractInternalPointer<ServiceWorkerGlobalScope, true>(context, context->Global());
18 return global.setImmediate(js, kj::mv(function), kj::mv(args));
19}
20 
21void TimersUtil::clearImmediate(jsg::Lock& js, kj::Maybe<jsg::Ref<Immediate>> maybeImmediate) {
22 auto context = js.v8Context();
23 auto& global =
24 jsg::extractInternalPointer<ServiceWorkerGlobalScope, true>(context, context->Global());
25 global.clearImmediate(kj::mv(maybeImmediate));
26}
27} // namespace workerd::api::node