Files
node/src/timers.h
T
Joyee Cheung c0365fd52a src: avoid prototype access in binding templates
This patch makes the binding templates ObjectTemplates, since we
don't actually need the constructor function. This also avoids
setting the properties on prototype, and instead initializes them
directly on the object template.

Previously the initialization was similar to:

```
function Binding() {}
Binding.prototype.property = ...;
module.exports = new Binding;
```

Now it's similar to:

```
module.exports = { property: ... };
```

PR-URL: https://github.com/nodejs/node/pull/47913
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-05-24 16:45:05 +02:00

71 lines
2.4 KiB
C++

#ifndef SRC_TIMERS_H_
#define SRC_TIMERS_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include <cinttypes>
#include "node_snapshotable.h"
namespace node {
class ExternalReferenceRegistry;
namespace timers {
class BindingData : public SnapshotableObject {
public:
BindingData(Realm* env, v8::Local<v8::Object> obj);
using InternalFieldInfo = InternalFieldInfoBase;
SET_BINDING_ID(timers_binding_data)
SERIALIZABLE_OBJECT_METHODS()
SET_NO_MEMORY_INFO()
SET_SELF_SIZE(BindingData)
SET_MEMORY_INFO_NAME(BindingData)
static void SetupTimers(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SlowGetLibuvNow(const v8::FunctionCallbackInfo<v8::Value>& args);
static double FastGetLibuvNow(v8::Local<v8::Object> receiver);
static double GetLibuvNowImpl(BindingData* data);
static void SlowScheduleTimer(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void FastScheduleTimer(v8::Local<v8::Object> receiver,
int64_t duration);
static void ScheduleTimerImpl(BindingData* data, int64_t duration);
static void SlowToggleTimerRef(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void FastToggleTimerRef(v8::Local<v8::Object> receiver, bool ref);
static void ToggleTimerRefImpl(BindingData* data, bool ref);
static void SlowToggleImmediateRef(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void FastToggleImmediateRef(v8::Local<v8::Object> receiver, bool ref);
static void ToggleImmediateRefImpl(BindingData* data, bool ref);
static void CreatePerIsolateProperties(IsolateData* isolate_data,
v8::Local<v8::ObjectTemplate> target);
static void CreatePerContextProperties(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv);
static void RegisterTimerExternalReferences(
ExternalReferenceRegistry* registry);
private:
static v8::CFunction fast_get_libuv_now_;
static v8::CFunction fast_schedule_timers_;
static v8::CFunction fast_toggle_timer_ref_;
static v8::CFunction fast_toggle_immediate_ref_;
};
} // namespace timers
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_TIMERS_H_