Skip to content

Commit

Permalink
src: move GetNow to Environment
Browse files Browse the repository at this point in the history
PR-URL: #18562
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
apapirovski committed Feb 7, 2018
1 parent d0e4d4e commit 1573e45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
15 changes: 15 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ namespace node {
using v8::Context;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Message;
using v8::Number;
using v8::Private;
using v8::StackFrame;
using v8::StackTrace;
using v8::String;
using v8::Value;

IsolateData::IsolateData(Isolate* isolate,
uv_loop_t* event_loop,
Expand Down Expand Up @@ -362,6 +365,18 @@ void Environment::ToggleImmediateRef(bool ref) {
}


Local<Value> Environment::GetNow() {
uv_update_time(event_loop());
uint64_t now = uv_now(event_loop());
CHECK_GE(now, timer_base());
now -= timer_base();
if (now <= 0xffffffff)
return Integer::New(isolate(), static_cast<uint32_t>(now));
else
return Number::New(isolate(), static_cast<double>(now));
}


void CollectExceptionInfo(Environment* env,
v8::Local<v8::Object> obj,
int errorno,
Expand Down
2 changes: 2 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,8 @@ class Environment {

static inline Environment* ForAsyncHooks(AsyncHooks* hooks);

v8::Local<v8::Value> GetNow();

private:
inline void CreateImmediate(native_immediate_callback cb,
void* data,
Expand Down
16 changes: 2 additions & 14 deletions src/timer_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
Expand Down Expand Up @@ -142,7 +141,7 @@ class TimerWrap : public HandleWrap {
Local<Value> ret;
Local<Value> args[1];
do {
args[0] = GetNow(env);
args[0] = env->GetNow();
ret = wrap->MakeCallback(kOnTimeout, 1, args).ToLocalChecked();
} while (ret->IsUndefined() &&
!env->tick_info()->has_thrown() &&
Expand All @@ -153,18 +152,7 @@ class TimerWrap : public HandleWrap {

static void Now(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
args.GetReturnValue().Set(GetNow(env));
}

static Local<Value> GetNow(Environment* env) {
uv_update_time(env->event_loop());
uint64_t now = uv_now(env->event_loop());
CHECK(now >= env->timer_base());
now -= env->timer_base();
if (now <= 0xfffffff)
return Integer::New(env->isolate(), static_cast<uint32_t>(now));
else
return Number::New(env->isolate(), static_cast<double>(now));
args.GetReturnValue().Set(env->GetNow());
}

uv_timer_t handle_;
Expand Down

0 comments on commit 1573e45

Please sign in to comment.