Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.

PR-URL: #4600
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
AndreasMadsen committed Jun 7, 2016
commit 051103df35be0fcba774133ac1dc9f79b2ba8b40
7 changes: 5 additions & 2 deletions src/async-wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ inline AsyncWrap::AsyncWrap(Environment* env,
v8::Local<v8::Value> argv[] = {
v8::Integer::New(env->isolate(), get_uid()),
v8::Int32::New(env->isolate(), provider),
Null(env->isolate()),
Null(env->isolate())
};

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

v8::MaybeLocal<v8::Value> ret =
init_fn->Call(env->context(), object, arraysize(argv), argv);
Expand Down
13 changes: 10 additions & 3 deletions test/parallel/test-async-wrap-disabled-propagate-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ const net = require('net');
const async_wrap = process.binding('async_wrap');
const providers = Object.keys(async_wrap.Providers);

const uidSymbol = Symbol('uid');

let cntr = 0;
let client;

function init(id, type, parent) {
if (parent) {
function init(uid, type, parentUid, parentHandle) {
this[uidSymbol] = uid;

if (parentHandle) {
cntr++;
// Cannot assert in init callback or will abort.
process.nextTick(() => {
assert.equal(providers[type], 'TCPWRAP');
assert.equal(parent, server._handle, 'server doesn\'t match parent');
assert.equal(parentUid, server._handle[uidSymbol],
'server uid doesn\'t match parent uid');
assert.equal(parentHandle, server._handle,
'server handle doesn\'t match parent handle');
assert.equal(this, client._handle, 'client doesn\'t match context');
});
}
Expand Down
15 changes: 12 additions & 3 deletions test/parallel/test-async-wrap-propagate-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ const common = require('../common');
const assert = require('assert');
const net = require('net');
const async_wrap = process.binding('async_wrap');
const providers = Object.keys(async_wrap.Providers);

const uidSymbol = Symbol('uid');

let cntr = 0;
let client;

function init(id, type, parent) {
if (parent) {
function init(uid, type, parentUid, parentHandle) {
this[uidSymbol] = uid;

if (parentHandle) {
cntr++;
// Cannot assert in init callback or will abort.
process.nextTick(() => {
assert.equal(parent, server._handle, 'server doesn\'t match parent');
assert.equal(providers[type], 'TCPWRAP');
assert.equal(parentUid, server._handle[uidSymbol],
'server uid doesn\'t match parent uid');
assert.equal(parentHandle, server._handle,
'server handle doesn\'t match parent handle');
assert.equal(this, client._handle, 'client doesn\'t match context');
});
}
Expand Down