Skip to content

Commit 0432c6e

Browse files
trevnorrisaddaleax
authored andcommitted
async_wrap: use double, not int64_t, for async id
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 732620c commit 0432c6e

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/async-wrap-inl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ inline AsyncWrap::ProviderType AsyncWrap::provider_type() const {
4646
}
4747

4848

49-
inline int64_t AsyncWrap::get_uid() const {
50-
return uid_;
49+
inline double AsyncWrap::get_id() const {
50+
return id_;
5151
}
5252

5353

src/async-wrap.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void AsyncWrap::DestroyIdsCb(uv_idle_t* handle) {
220220

221221
TryCatch try_catch(env->isolate());
222222

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

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

279279
Local<Value> argv[] = {
280-
Number::New(env->isolate(), get_uid()),
280+
Number::New(env->isolate(), get_id()),
281281
Int32::New(env->isolate(), provider),
282282
Null(env->isolate()),
283283
Null(env->isolate())
284284
};
285285

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

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

312-
env()->destroy_ids_list()->push_back(get_uid());
312+
env()->destroy_ids_list()->push_back(get_id());
313313
}
314314

315315

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

321321
Local<Function> pre_fn = env()->async_hooks_pre_function();
322322
Local<Function> post_fn = env()->async_hooks_post_function();
323-
Local<Value> uid = Number::New(env()->isolate(), get_uid());
323+
Local<Value> uid = Number::New(env()->isolate(), get_id());
324324
Local<Object> context = object();
325325
Local<Object> domain;
326326
bool has_domain = false;

src/async-wrap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class AsyncWrap : public BaseObject {
8686

8787
inline ProviderType provider_type() const;
8888

89-
inline int64_t get_uid() const;
89+
inline double get_id() const;
9090

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

115115
void LoadAsyncWrapperInfo(Environment* env);

src/env-inl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ inline Environment::Environment(IsolateData* isolate_data,
192192
printed_error_(false),
193193
trace_sync_io_(false),
194194
makecallback_cntr_(0),
195-
async_wrap_uid_(0),
195+
async_wrap_id_(0),
196196
#if HAVE_INSPECTOR
197197
inspector_agent_(this),
198198
#endif
@@ -320,11 +320,11 @@ inline void Environment::set_trace_sync_io(bool value) {
320320
trace_sync_io_ = value;
321321
}
322322

323-
inline int64_t Environment::get_async_wrap_uid() {
324-
return ++async_wrap_uid_;
323+
inline double Environment::get_async_wrap_uid() {
324+
return ++async_wrap_id_;
325325
}
326326

327-
inline std::vector<int64_t>* Environment::destroy_ids_list() {
327+
inline std::vector<double>* Environment::destroy_ids_list() {
328328
return &destroy_ids_list_;
329329
}
330330

src/env.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,10 @@ class Environment {
488488
void PrintSyncTrace() const;
489489
inline void set_trace_sync_io(bool value);
490490

491-
inline int64_t get_async_wrap_uid();
491+
inline double get_async_wrap_uid();
492492

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

496496
inline double* heap_statistics_buffer() const;
497497
inline void set_heap_statistics_buffer(double* pointer);
@@ -596,8 +596,8 @@ class Environment {
596596
bool printed_error_;
597597
bool trace_sync_io_;
598598
size_t makecallback_cntr_;
599-
int64_t async_wrap_uid_;
600-
std::vector<int64_t> destroy_ids_list_;
599+
double async_wrap_id_;
600+
std::vector<double> destroy_ids_list_;
601601
#if HAVE_INSPECTOR
602602
inspector::Agent inspector_agent_;
603603
#endif

0 commit comments

Comments
 (0)