Skip to content

Commit 29935b8

Browse files
committed
async_hooks,inspector: inspector keeps async context untouched
1 parent e133e51 commit 29935b8

File tree

5 files changed

+75
-24
lines changed

5 files changed

+75
-24
lines changed

src/async_wrap.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,9 @@ namespace node {
102102
#define NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V)
103103
#endif // HAVE_OPENSSL
104104

105-
#if HAVE_INSPECTOR
106-
#define NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V) \
107-
V(INSPECTORJSBINDING)
108-
#else
109-
#define NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V)
110-
#endif // HAVE_INSPECTOR
111-
112105
#define NODE_ASYNC_PROVIDER_TYPES(V) \
113106
NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \
114-
NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) \
115-
NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V)
107+
NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V)
116108

117109
class Environment;
118110
class DestroyParam;

src/inspector_js_api.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "async_wrap-inl.h"
21
#include "base_object-inl.h"
32
#include "inspector_agent.h"
43
#include "inspector_io.h"
@@ -61,7 +60,7 @@ struct MainThreadConnection {
6160
};
6261

6362
template <typename ConnectionType>
64-
class JSBindingsConnection : public AsyncWrap {
63+
class JSBindingsConnection : public BaseObject {
6564
public:
6665
class JSBindingsSessionDelegate : public InspectorSessionDelegate {
6766
public:
@@ -91,15 +90,17 @@ class JSBindingsConnection : public AsyncWrap {
9190
JSBindingsConnection(Environment* env,
9291
Local<Object> wrap,
9392
Local<Function> callback)
94-
: AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING),
93+
: BaseObject(env, wrap),
9594
callback_(env->isolate(), callback) {
9695
Agent* inspector = env->inspector_agent();
9796
session_ = ConnectionType::Connect(
9897
inspector, std::make_unique<JSBindingsSessionDelegate>(env, this));
9998
}
10099

101100
void OnMessage(Local<Value> value) {
102-
MakeCallback(callback_.Get(env()->isolate()), 1, &value);
101+
auto result = callback_.Get(env()->isolate())
102+
->Call(env()->context(), object(), 1, &value);
103+
(void)result;
103104
}
104105

105106
static void Bind(Environment* env, Local<Object> target) {
@@ -108,7 +109,6 @@ class JSBindingsConnection : public AsyncWrap {
108109
NewFunctionTemplate(isolate, JSBindingsConnection::New);
109110
tmpl->InstanceTemplate()->SetInternalFieldCount(
110111
JSBindingsConnection::kInternalFieldCount);
111-
tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env));
112112
SetProtoMethod(isolate, tmpl, "dispatch", JSBindingsConnection::Dispatch);
113113
SetProtoMethod(
114114
isolate, tmpl, "disconnect", JSBindingsConnection::Disconnect);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
const common = require('../common');
4+
const { AsyncLocalStorage } = require('async_hooks');
5+
const als = new AsyncLocalStorage();
6+
7+
function getStore() {
8+
return als.getStore();
9+
}
10+
11+
common.skipIfInspectorDisabled();
12+
13+
const assert = require('assert');
14+
const { Session } = require('inspector');
15+
const path = require('path');
16+
const { pathToFileURL } = require('url');
17+
18+
let valueInFunction = 0;
19+
let valueInBreakpoint = 0;
20+
21+
function debugged() {
22+
valueInFunction = getStore();
23+
console.log('in code => ', getStore());
24+
return 42;
25+
}
26+
27+
async function test() {
28+
const session = new Session();
29+
30+
session.connect();
31+
console.log('Connected');
32+
33+
session.post('Debugger.enable');
34+
console.log('Debugger was enabled');
35+
36+
session.on('Debugger.paused', () => {
37+
valueInBreakpoint = getStore();
38+
console.log('on Debugger.paused callback => ', getStore());
39+
});
40+
41+
await new Promise((resolve, reject) => {
42+
session.post('Debugger.setBreakpointByUrl', {
43+
'lineNumber': 22,
44+
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
45+
'columnNumber': 0,
46+
'condition': ''
47+
}, (error, result) => {
48+
return error ? reject(error) : resolve(result);
49+
});
50+
});
51+
console.log('Breakpoint was set');
52+
53+
als.run(1, debugged);
54+
assert.strictEqual(valueInFunction, valueInBreakpoint);
55+
assert.strictEqual(valueInFunction, 1);
56+
assert.notStrictEqual(valueInFunction, 0);
57+
assert.notStrictEqual(valueInBreakpoint, 0);
58+
59+
console.log('Breakpoint was hit');
60+
61+
session.disconnect();
62+
console.log('Session disconnected');
63+
}
64+
65+
const interval = setInterval(() => {}, 1000);
66+
test().then(common.mustCall(() => {
67+
clearInterval(interval);
68+
console.log('Done!');
69+
}));

test/sequential/test-async-wrap-getasyncid.js

-9
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const { getSystemErrorName } = require('util');
4747
delete providers.WORKER;
4848
// TODO(danbev): Test for these
4949
delete providers.JSUDPWRAP;
50-
if (!common.isMainThread)
51-
delete providers.INSPECTORJSBINDING;
5250
delete providers.KEYPAIRGENREQUEST;
5351
delete providers.KEYGENREQUEST;
5452
delete providers.KEYEXPORTREQUEST;
@@ -316,13 +314,6 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
316314
testInitialized(req, 'SendWrap');
317315
}
318316

319-
if (process.features.inspector && common.isMainThread) {
320-
const binding = internalBinding('inspector');
321-
const handle = new binding.Connection(() => {});
322-
testInitialized(handle, 'Connection');
323-
handle.disconnect();
324-
}
325-
326317
// PROVIDER_HEAPDUMP
327318
{
328319
v8.getHeapSnapshot().destroy();

typings/internalBinding/async_wrap.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ declare namespace InternalAsyncWrapBinding {
6868
SIGNREQUEST: 54;
6969
TLSWRAP: 55;
7070
VERIFYREQUEST: 56;
71-
INSPECTORJSBINDING: 57;
7271
}
7372
}
7473

0 commit comments

Comments
 (0)