mirror of
https://github.com/nodejs/node.git
synced 2026-12-04 02:19:15 -05:00
This is a continuation of the name reification on the internal bindings. Renames NODE_MODULE_CONTEXT_AWARE_INTERNAL and NODE_MODULE_EXTERNAL_REFERENCE to NODE_BINDING_CONTEXT_AWARE_INTERNAL and NODE_BINDING_EXTERNAL_REFERENCE respectively. PR-URL: https://github.com/nodejs/node/pull/45551 Backport-PR-URL: https://github.com/nodejs/node/pull/46336 Refs: https://github.com/nodejs/node/issues/44036 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
#include "env-inl.h"
|
|
#include "node_external_reference.h"
|
|
#include "util-inl.h"
|
|
#include "v8.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace node {
|
|
namespace {
|
|
|
|
using v8::Context;
|
|
using v8::Function;
|
|
using v8::FunctionCallbackInfo;
|
|
using v8::Local;
|
|
using v8::Object;
|
|
using v8::Value;
|
|
|
|
void SetupTimers(const FunctionCallbackInfo<Value>& args) {
|
|
CHECK(args[0]->IsFunction());
|
|
CHECK(args[1]->IsFunction());
|
|
auto env = Environment::GetCurrent(args);
|
|
|
|
env->set_immediate_callback_function(args[0].As<Function>());
|
|
env->set_timers_callback_function(args[1].As<Function>());
|
|
}
|
|
|
|
void GetLibuvNow(const FunctionCallbackInfo<Value>& args) {
|
|
Environment* env = Environment::GetCurrent(args);
|
|
args.GetReturnValue().Set(env->GetNow());
|
|
}
|
|
|
|
void ScheduleTimer(const FunctionCallbackInfo<Value>& args) {
|
|
auto env = Environment::GetCurrent(args);
|
|
env->ScheduleTimer(args[0]->IntegerValue(env->context()).FromJust());
|
|
}
|
|
|
|
void ToggleTimerRef(const FunctionCallbackInfo<Value>& args) {
|
|
Environment::GetCurrent(args)->ToggleTimerRef(args[0]->IsTrue());
|
|
}
|
|
|
|
void ToggleImmediateRef(const FunctionCallbackInfo<Value>& args) {
|
|
Environment::GetCurrent(args)->ToggleImmediateRef(args[0]->IsTrue());
|
|
}
|
|
|
|
void Initialize(Local<Object> target,
|
|
Local<Value> unused,
|
|
Local<Context> context,
|
|
void* priv) {
|
|
Environment* env = Environment::GetCurrent(context);
|
|
|
|
SetMethod(context, target, "getLibuvNow", GetLibuvNow);
|
|
SetMethod(context, target, "setupTimers", SetupTimers);
|
|
SetMethod(context, target, "scheduleTimer", ScheduleTimer);
|
|
SetMethod(context, target, "toggleTimerRef", ToggleTimerRef);
|
|
SetMethod(context, target, "toggleImmediateRef", ToggleImmediateRef);
|
|
|
|
target
|
|
->Set(context,
|
|
FIXED_ONE_BYTE_STRING(env->isolate(), "immediateInfo"),
|
|
env->immediate_info()->fields().GetJSArray())
|
|
.Check();
|
|
|
|
target
|
|
->Set(context,
|
|
FIXED_ONE_BYTE_STRING(env->isolate(), "timeoutInfo"),
|
|
env->timeout_info().GetJSArray())
|
|
.Check();
|
|
}
|
|
} // anonymous namespace
|
|
void RegisterTimerExternalReferences(ExternalReferenceRegistry* registry) {
|
|
registry->Register(GetLibuvNow);
|
|
registry->Register(SetupTimers);
|
|
registry->Register(ScheduleTimer);
|
|
registry->Register(ToggleTimerRef);
|
|
registry->Register(ToggleImmediateRef);
|
|
}
|
|
|
|
} // namespace node
|
|
|
|
NODE_BINDING_CONTEXT_AWARE_INTERNAL(timers, node::Initialize)
|
|
NODE_BINDING_EXTERNAL_REFERENCE(timers, node::RegisterTimerExternalReferences)
|