Skip to content

Commit

Permalink
async_wrap: use double, not int64_t, for async id
Browse files Browse the repository at this point in the history
The number of ids is limited to 2^53-1 regardless of whether an int64_t
is used or not because JS is limited to a double. So to make conversion
simpler, track ids internally as a double. This will also make life
simpler when this is eventually exposed to JS via a Float64Array.

Rename AsyncWrap::get_uid() to AsyncWrap::get_id().

PR-URL: #12892
Ref: #11883
Ref: #8531
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
trevnorris authored and addaleax committed May 10, 2017
1 parent 732620c commit 0432c6e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/async-wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ inline AsyncWrap::ProviderType AsyncWrap::provider_type() const {
}


inline int64_t AsyncWrap::get_uid() const {
return uid_;
inline double AsyncWrap::get_id() const {
return id_;
}


Expand Down
12 changes: 6 additions & 6 deletions src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void AsyncWrap::DestroyIdsCb(uv_idle_t* handle) {

TryCatch try_catch(env->isolate());

std::vector<int64_t> destroy_ids_list;
std::vector<double> destroy_ids_list;
destroy_ids_list.swap(*env->destroy_ids_list());
for (auto current_id : destroy_ids_list) {
// Want each callback to be cleaned up after itself, instead of cleaning
Expand Down Expand Up @@ -255,7 +255,7 @@ AsyncWrap::AsyncWrap(Environment* env,
ProviderType provider,
AsyncWrap* parent)
: BaseObject(env, object), bits_(static_cast<uint32_t>(provider) << 1),
uid_(env->get_async_wrap_uid()) {
id_(env->get_async_wrap_uid()) {
CHECK_NE(provider, PROVIDER_NONE);
CHECK_GE(object->InternalFieldCount(), 1);

Expand All @@ -277,14 +277,14 @@ AsyncWrap::AsyncWrap(Environment* env,
HandleScope scope(env->isolate());

Local<Value> argv[] = {
Number::New(env->isolate(), get_uid()),
Number::New(env->isolate(), get_id()),
Int32::New(env->isolate(), provider),
Null(env->isolate()),
Null(env->isolate())
};

if (parent != nullptr) {
argv[2] = Number::New(env->isolate(), parent->get_uid());
argv[2] = Number::New(env->isolate(), parent->get_id());
argv[3] = parent->object();
}

Expand All @@ -309,7 +309,7 @@ AsyncWrap::~AsyncWrap() {
if (env()->destroy_ids_list()->empty())
uv_idle_start(env()->destroy_ids_idle_handle(), DestroyIdsCb);

env()->destroy_ids_list()->push_back(get_uid());
env()->destroy_ids_list()->push_back(get_id());
}


Expand All @@ -320,7 +320,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,

Local<Function> pre_fn = env()->async_hooks_pre_function();
Local<Function> post_fn = env()->async_hooks_post_function();
Local<Value> uid = Number::New(env()->isolate(), get_uid());
Local<Value> uid = Number::New(env()->isolate(), get_id());
Local<Object> context = object();
Local<Object> domain;
bool has_domain = false;
Expand Down
4 changes: 2 additions & 2 deletions src/async-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AsyncWrap : public BaseObject {

inline ProviderType provider_type() const;

inline int64_t get_uid() const;
inline double get_id() const;

// Only call these within a valid HandleScope.
v8::Local<v8::Value> MakeCallback(const v8::Local<v8::Function> cb,
Expand All @@ -109,7 +109,7 @@ class AsyncWrap : public BaseObject {
// expected the context object will receive a _asyncQueue object property
// that will be used to call pre/post in MakeCallback.
uint32_t bits_;
const int64_t uid_;
const double id_;
};

void LoadAsyncWrapperInfo(Environment* env);
Expand Down
8 changes: 4 additions & 4 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ inline Environment::Environment(IsolateData* isolate_data,
printed_error_(false),
trace_sync_io_(false),
makecallback_cntr_(0),
async_wrap_uid_(0),
async_wrap_id_(0),
#if HAVE_INSPECTOR
inspector_agent_(this),
#endif
Expand Down Expand Up @@ -320,11 +320,11 @@ inline void Environment::set_trace_sync_io(bool value) {
trace_sync_io_ = value;
}

inline int64_t Environment::get_async_wrap_uid() {
return ++async_wrap_uid_;
inline double Environment::get_async_wrap_uid() {
return ++async_wrap_id_;
}

inline std::vector<int64_t>* Environment::destroy_ids_list() {
inline std::vector<double>* Environment::destroy_ids_list() {
return &destroy_ids_list_;
}

Expand Down
8 changes: 4 additions & 4 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ class Environment {
void PrintSyncTrace() const;
inline void set_trace_sync_io(bool value);

inline int64_t get_async_wrap_uid();
inline double get_async_wrap_uid();

// List of id's that have been destroyed and need the destroy() cb called.
inline std::vector<int64_t>* destroy_ids_list();
inline std::vector<double>* destroy_ids_list();

inline double* heap_statistics_buffer() const;
inline void set_heap_statistics_buffer(double* pointer);
Expand Down Expand Up @@ -596,8 +596,8 @@ class Environment {
bool printed_error_;
bool trace_sync_io_;
size_t makecallback_cntr_;
int64_t async_wrap_uid_;
std::vector<int64_t> destroy_ids_list_;
double async_wrap_id_;
std::vector<double> destroy_ids_list_;
#if HAVE_INSPECTOR
inspector::Agent inspector_agent_;
#endif
Expand Down

0 comments on commit 0432c6e

Please sign in to comment.