src: pass resource object along with InternalMakeCallback
This was an oversight in 9fdb6e6aaf45b2364bac89a. Fixing this is necessary to make `executionAsyncResource()` work as expected. Refs: https://github.com/nodejs/node/pull/30959 Fixes: https://github.com/nodejs/node/issues/32060 PR-URL: https://github.com/nodejs/node/pull/32063 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
2130474890
commit
787143bf3e
@ -139,6 +139,7 @@ void InternalCallbackScope::Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MaybeLocal<Value> InternalMakeCallback(Environment* env,
|
MaybeLocal<Value> InternalMakeCallback(Environment* env,
|
||||||
|
Local<Object> resource,
|
||||||
Local<Object> recv,
|
Local<Object> recv,
|
||||||
const Local<Function> callback,
|
const Local<Function> callback,
|
||||||
int argc,
|
int argc,
|
||||||
@ -150,7 +151,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,
|
|||||||
CHECK(!argv[i].IsEmpty());
|
CHECK(!argv[i].IsEmpty());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
InternalCallbackScope scope(env, recv, asyncContext);
|
InternalCallbackScope scope(env, resource, asyncContext);
|
||||||
if (scope.Failed()) {
|
if (scope.Failed()) {
|
||||||
return MaybeLocal<Value>();
|
return MaybeLocal<Value>();
|
||||||
}
|
}
|
||||||
@ -224,7 +225,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
|
|||||||
CHECK_NOT_NULL(env);
|
CHECK_NOT_NULL(env);
|
||||||
Context::Scope context_scope(env->context());
|
Context::Scope context_scope(env->context());
|
||||||
MaybeLocal<Value> ret =
|
MaybeLocal<Value> ret =
|
||||||
InternalMakeCallback(env, recv, callback, argc, argv, asyncContext);
|
InternalMakeCallback(env, recv, recv, callback, argc, argv, asyncContext);
|
||||||
if (ret.IsEmpty() && env->async_callback_scope_depth() == 0) {
|
if (ret.IsEmpty() && env->async_callback_scope_depth() == 0) {
|
||||||
// This is only for legacy compatibility and we may want to look into
|
// This is only for legacy compatibility and we may want to look into
|
||||||
// removing/adjusting it.
|
// removing/adjusting it.
|
||||||
|
@ -749,7 +749,7 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
|
|||||||
ProviderType provider = provider_type();
|
ProviderType provider = provider_type();
|
||||||
async_context context { get_async_id(), get_trigger_async_id() };
|
async_context context { get_async_id(), get_trigger_async_id() };
|
||||||
MaybeLocal<Value> ret = InternalMakeCallback(
|
MaybeLocal<Value> ret = InternalMakeCallback(
|
||||||
env(), object(), cb, argc, argv, context);
|
env(), GetResource(), object(), cb, argc, argv, context);
|
||||||
|
|
||||||
// This is a static call with cached values because the `this` object may
|
// This is a static call with cached values because the `this` object may
|
||||||
// no longer be alive at this point.
|
// no longer be alive at this point.
|
||||||
|
@ -199,6 +199,7 @@ static v8::MaybeLocal<v8::Object> New(Environment* env,
|
|||||||
|
|
||||||
v8::MaybeLocal<v8::Value> InternalMakeCallback(
|
v8::MaybeLocal<v8::Value> InternalMakeCallback(
|
||||||
Environment* env,
|
Environment* env,
|
||||||
|
v8::Local<v8::Object> resource,
|
||||||
v8::Local<v8::Object> recv,
|
v8::Local<v8::Object> recv,
|
||||||
const v8::Local<v8::Function> callback,
|
const v8::Local<v8::Function> callback,
|
||||||
int argc,
|
int argc,
|
||||||
|
37
test/async-hooks/test-async-exec-resource-http-32060.js
Normal file
37
test/async-hooks/test-async-exec-resource-http-32060.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const {
|
||||||
|
executionAsyncResource,
|
||||||
|
executionAsyncId,
|
||||||
|
createHook,
|
||||||
|
} = require('async_hooks');
|
||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
const hooked = {};
|
||||||
|
createHook({
|
||||||
|
init(asyncId, type, triggerAsyncId, resource) {
|
||||||
|
hooked[asyncId] = resource;
|
||||||
|
}
|
||||||
|
}).enable();
|
||||||
|
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
res.write('hello');
|
||||||
|
setTimeout(() => {
|
||||||
|
res.end(' world!');
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(0, () => {
|
||||||
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
||||||
|
http.get({ port: server.address().port }, (res) => {
|
||||||
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
||||||
|
res.on('data', () => {
|
||||||
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
||||||
|
});
|
||||||
|
res.on('end', () => {
|
||||||
|
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
|
||||||
|
server.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user