Skip to content

Commit 1573e45

Browse files
committed
src: move GetNow to Environment
PR-URL: #18562 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent d0e4d4e commit 1573e45

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/env.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ namespace node {
1111
using v8::Context;
1212
using v8::FunctionTemplate;
1313
using v8::HandleScope;
14+
using v8::Integer;
1415
using v8::Isolate;
1516
using v8::Local;
1617
using v8::Message;
18+
using v8::Number;
1719
using v8::Private;
1820
using v8::StackFrame;
1921
using v8::StackTrace;
2022
using v8::String;
23+
using v8::Value;
2124

2225
IsolateData::IsolateData(Isolate* isolate,
2326
uv_loop_t* event_loop,
@@ -362,6 +365,18 @@ void Environment::ToggleImmediateRef(bool ref) {
362365
}
363366

364367

368+
Local<Value> Environment::GetNow() {
369+
uv_update_time(event_loop());
370+
uint64_t now = uv_now(event_loop());
371+
CHECK_GE(now, timer_base());
372+
now -= timer_base();
373+
if (now <= 0xffffffff)
374+
return Integer::New(isolate(), static_cast<uint32_t>(now));
375+
else
376+
return Number::New(isolate(), static_cast<double>(now));
377+
}
378+
379+
365380
void CollectExceptionInfo(Environment* env,
366381
v8::Local<v8::Object> obj,
367382
int errorno,

src/env.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ class Environment {
735735

736736
static inline Environment* ForAsyncHooks(AsyncHooks* hooks);
737737

738+
v8::Local<v8::Value> GetNow();
739+
738740
private:
739741
inline void CreateImmediate(native_immediate_callback cb,
740742
void* data,

src/timer_wrap.cc

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ using v8::FunctionTemplate;
3737
using v8::HandleScope;
3838
using v8::Integer;
3939
using v8::Local;
40-
using v8::Number;
4140
using v8::Object;
4241
using v8::String;
4342
using v8::Value;
@@ -142,7 +141,7 @@ class TimerWrap : public HandleWrap {
142141
Local<Value> ret;
143142
Local<Value> args[1];
144143
do {
145-
args[0] = GetNow(env);
144+
args[0] = env->GetNow();
146145
ret = wrap->MakeCallback(kOnTimeout, 1, args).ToLocalChecked();
147146
} while (ret->IsUndefined() &&
148147
!env->tick_info()->has_thrown() &&
@@ -153,18 +152,7 @@ class TimerWrap : public HandleWrap {
153152

154153
static void Now(const FunctionCallbackInfo<Value>& args) {
155154
Environment* env = Environment::GetCurrent(args);
156-
args.GetReturnValue().Set(GetNow(env));
157-
}
158-
159-
static Local<Value> GetNow(Environment* env) {
160-
uv_update_time(env->event_loop());
161-
uint64_t now = uv_now(env->event_loop());
162-
CHECK(now >= env->timer_base());
163-
now -= env->timer_base();
164-
if (now <= 0xfffffff)
165-
return Integer::New(env->isolate(), static_cast<uint32_t>(now));
166-
else
167-
return Number::New(env->isolate(), static_cast<double>(now));
155+
args.GetReturnValue().Set(env->GetNow());
168156
}
169157

170158
uv_timer_t handle_;

0 commit comments

Comments
 (0)