| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 723aa41 commit 6a9cea9
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,6 +139,7 @@ void InternalCallbackScope::Close() { | |||
| 139 | 139 | } | |
| 140 | 140 | ||
| 141 | 141 | MaybeLocal<Value> InternalMakeCallback(Environment* env, | |
| 142 | + Local<Object> resource, | ||
| 142 | 143 | Local<Object> recv, | |
| 143 | 144 | const Local<Function> callback, | |
| 144 | 145 | int argc, | |
@@ -150,7 +151,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env, | |||
| 150 | 151 | CHECK(!argv[i].IsEmpty()); | |
| 151 | 152 | #endif | |
| 152 | 153 | ||
| 153 | - InternalCallbackScope scope(env, recv, asyncContext); | ||
| 154 | + InternalCallbackScope scope(env, resource, asyncContext); | ||
| 154 | 155 | if (scope.Failed()) { | |
| 155 | 156 | return MaybeLocal<Value>(); | |
| 156 | 157 | } | |
@@ -224,7 +225,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate, | |||
| 224 | 225 | CHECK_NOT_NULL(env); | |
| 225 | 226 | Context::Scope context_scope(env->context()); | |
| 226 | 227 | MaybeLocal<Value> ret = | |
| 227 | - InternalMakeCallback(env, recv, callback, argc, argv, asyncContext); | ||
| 228 | + InternalMakeCallback(env, recv, recv, callback, argc, argv, asyncContext); | ||
| 228 | 229 | if (ret.IsEmpty() && env->async_callback_scope_depth() == 0) { | |
| 229 | 230 | // This is only for legacy compatibility and we may want to look into | |
| 230 | 231 | // removing/adjusting it. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -749,7 +749,7 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb, | |||
| 749 | 749 | ProviderType provider = provider_type(); | |
| 750 | 750 | async_context context { get_async_id(), get_trigger_async_id() }; | |
| 751 | 751 | MaybeLocal<Value> ret = InternalMakeCallback( | |
| 752 | - env(), object(), cb, argc, argv, context); | ||
| 752 | + env(), GetResource(), object(), cb, argc, argv, context); | ||
| 753 | 753 | ||
| 754 | 754 | // This is a static call with cached values because the `this` object may | |
| 755 | 755 | // no longer be alive at this point. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,6 +199,7 @@ static v8::MaybeLocal<v8::Object> New(Environment* env, | |||
| 199 | 199 | ||
| 200 | 200 | v8::MaybeLocal<v8::Value> InternalMakeCallback( | |
| 201 | 201 | Environment* env, | |
| 202 | + v8::Local<v8::Object> resource, | ||
| 202 | 203 | v8::Local<v8::Object> recv, | |
| 203 | 204 | const v8::Local<v8::Function> callback, | |
| 204 | 205 | int argc, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const { | ||
| 5 | + executionAsyncResource, | ||
| 6 | + executionAsyncId, | ||
| 7 | + createHook, | ||
| 8 | + } = require('async_hooks'); | ||
| 9 | + const http = require('http'); | ||
| 10 | + | ||
| 11 | + const hooked = {}; | ||
| 12 | + createHook({ | ||
| 13 | + init(asyncId, type, triggerAsyncId, resource) { | ||
| 14 | + hooked[asyncId] = resource; | ||
| 15 | + } | ||
| 16 | + }).enable(); | ||
| 17 | + | ||
| 18 | + const server = http.createServer((req, res) => { | ||
| 19 | + res.write('hello'); | ||
| 20 | + setTimeout(() => { | ||
| 21 | + res.end(' world!'); | ||
| 22 | + }, 1000); | ||
| 23 | + }); | ||
| 24 | + | ||
| 25 | + server.listen(0, () => { | ||
| 26 | + assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | ||
| 27 | + http.get({ port: server.address().port }, (res) => { | ||
| 28 | + assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | ||
| 29 | + res.on('data', () => { | ||
| 30 | + assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | ||
| 31 | + }); | ||
| 32 | + res.on('end', () => { | ||
| 33 | + assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | ||
| 34 | + server.close(); | ||
| 35 | + }); | ||
| 36 | + }); | ||
| 37 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments