Skip to content

Commit 75ecf8e

Browse files
AndreasMadsenMyles Borins
authored and
Myles Borins
committed
async_wrap: add parent uid to init hook
When the parent uid is required it is not necessary to store the uid in the parent handle object. Ref: #7048 PR-URL: #4600 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent e10eebf commit 75ecf8e

3 files changed

+27
-8
lines changed

src/async-wrap-inl.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ inline AsyncWrap::AsyncWrap(Environment* env,
4242
v8::Local<v8::Value> argv[] = {
4343
v8::Integer::New(env->isolate(), get_uid()),
4444
v8::Int32::New(env->isolate(), provider),
45+
Null(env->isolate()),
4546
Null(env->isolate())
4647
};
4748

48-
if (parent != nullptr)
49-
argv[2] = parent->object();
49+
if (parent != nullptr) {
50+
argv[2] = v8::Integer::New(env->isolate(), parent->get_uid());
51+
argv[3] = parent->object();
52+
}
5053

5154
v8::MaybeLocal<v8::Value> ret =
5255
init_fn->Call(env->context(), object, arraysize(argv), argv);

test/parallel/test-async-wrap-disabled-propagate-parent.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ const net = require('net');
66
const async_wrap = process.binding('async_wrap');
77
const providers = Object.keys(async_wrap.Providers);
88

9+
const uidSymbol = Symbol('uid');
10+
911
let cntr = 0;
1012
let client;
1113

12-
function init(id, type, parent) {
13-
if (parent) {
14+
function init(uid, type, parentUid, parentHandle) {
15+
this[uidSymbol] = uid;
16+
17+
if (parentHandle) {
1418
cntr++;
1519
// Cannot assert in init callback or will abort.
1620
process.nextTick(() => {
1721
assert.equal(providers[type], 'TCPWRAP');
18-
assert.equal(parent, server._handle, 'server doesn\'t match parent');
22+
assert.equal(parentUid, server._handle[uidSymbol],
23+
'server uid doesn\'t match parent uid');
24+
assert.equal(parentHandle, server._handle,
25+
'server handle doesn\'t match parent handle');
1926
assert.equal(this, client._handle, 'client doesn\'t match context');
2027
});
2128
}

test/parallel/test-async-wrap-propagate-parent.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ const common = require('../common');
44
const assert = require('assert');
55
const net = require('net');
66
const async_wrap = process.binding('async_wrap');
7+
const providers = Object.keys(async_wrap.Providers);
8+
9+
const uidSymbol = Symbol('uid');
710

811
let cntr = 0;
912
let client;
1013

11-
function init(id, type, parent) {
12-
if (parent) {
14+
function init(uid, type, parentUid, parentHandle) {
15+
this[uidSymbol] = uid;
16+
17+
if (parentHandle) {
1318
cntr++;
1419
// Cannot assert in init callback or will abort.
1520
process.nextTick(() => {
16-
assert.equal(parent, server._handle, 'server doesn\'t match parent');
21+
assert.equal(providers[type], 'TCPWRAP');
22+
assert.equal(parentUid, server._handle[uidSymbol],
23+
'server uid doesn\'t match parent uid');
24+
assert.equal(parentHandle, server._handle,
25+
'server handle doesn\'t match parent handle');
1726
assert.equal(this, client._handle, 'client doesn\'t match context');
1827
});
1928
}

0 commit comments

Comments
 (0)