Skip to content

Commit dfedbf9

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

File tree

5 files changed

+77
-27
lines changed

5 files changed

+77
-27
lines changed

‎src/async_wrap.h‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,9 @@ namespace node{
102102
#defineNODE_ASYNC_CRYPTO_PROVIDER_TYPES(V)
103103
#endif// HAVE_OPENSSL
104104

105-
#if HAVE_INSPECTOR
106-
#defineNODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V) \
107-
V(INSPECTORJSBINDING)
108-
#else
109-
#defineNODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V)
110-
#endif// HAVE_INSPECTOR
111-
112-
#defineNODE_ASYNC_PROVIDER_TYPES(V) \
113-
NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \
114-
NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V) \
115-
NODE_ASYNC_INSPECTOR_PROVIDER_TYPES(V)
105+
#defineNODE_ASYNC_PROVIDER_TYPES(V) \
106+
NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \
107+
NODE_ASYNC_CRYPTO_PROVIDER_TYPES(V)
116108

117109
classEnvironment;
118110
classDestroyParam;

‎src/inspector_js_api.cc‎

Lines changed: 5 additions & 6 deletions
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-
classJSBindingsConnection : publicAsyncWrap{
63+
classJSBindingsConnection : publicBaseObject{
6564
public:
6665
classJSBindingsSessionDelegate : publicInspectorSessionDelegate{
6766
public:
@@ -91,15 +90,16 @@ class JSBindingsConnection : public AsyncWrap{
9190
JSBindingsConnection(Environment* env,
9291
Local<Object> wrap,
9392
Local<Function> callback)
94-
: AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING),
95-
callback_(env->isolate(), callback){
93+
: BaseObject(env, wrap), callback_(env->isolate(), callback){
9694
Agent* inspector = env->inspector_agent();
9795
session_ = ConnectionType::Connect(
9896
inspector, std::make_unique<JSBindingsSessionDelegate>(env, this));
9997
}
10098

10199
voidOnMessage(Local<Value> value){
102-
MakeCallback(callback_.Get(env()->isolate()), 1, &value);
100+
auto result = callback_.Get(env()->isolate())
101+
->Call(env()->context(), object(), 1, &value);
102+
(void)result;
103103
}
104104

105105
staticvoidBind(Environment* env, Local<Object> target){
@@ -108,7 +108,6 @@ class JSBindingsConnection : public AsyncWrap{
108108
NewFunctionTemplate(isolate, JSBindingsConnection::New);
109109
tmpl->InstanceTemplate()->SetInternalFieldCount(
110110
JSBindingsConnection::kInternalFieldCount);
111-
tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env));
112111
SetProtoMethod(isolate, tmpl, "dispatch", JSBindingsConnection::Dispatch);
113112
SetProtoMethod(
114113
isolate, tmpl, "disconnect", JSBindingsConnection::Disconnect);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
constcommon=require('../common');
4+
const{ AsyncLocalStorage }=require('async_hooks');
5+
constals=newAsyncLocalStorage();
6+
7+
functiongetStore(){
8+
returnals.getStore();
9+
}
10+
11+
common.skipIfInspectorDisabled();
12+
13+
constassert=require('assert');
14+
const{ Session }=require('inspector');
15+
constpath=require('path');
16+
const{ pathToFileURL }=require('url');
17+
18+
letvalueInFunction=0;
19+
letvalueInBreakpoint=0;
20+
21+
functiondebugged(){
22+
valueInFunction=getStore();
23+
console.log('in code => ',getStore());
24+
return42;
25+
}
26+
27+
asyncfunctiontest(){
28+
constsession=newSession();
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+
awaitnewPromise((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+
returnerror ? 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+
constinterval=setInterval(()=>{},1000);
66+
test().then(common.mustCall(()=>{
67+
clearInterval(interval);
68+
console.log('Done!');
69+
}));

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const{getSystemErrorName } = require('util');
4747
deleteproviders.WORKER;
4848
// TODO(danbev): Test for these
4949
deleteproviders.JSUDPWRAP;
50-
if(!common.isMainThread)
51-
deleteproviders.INSPECTORJSBINDING;
5250
deleteproviders.KEYPAIRGENREQUEST;
5351
deleteproviders.KEYGENREQUEST;
5452
deleteproviders.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-
constbinding=internalBinding('inspector');
321-
consthandle=newbinding.Connection(()=>{});
322-
testInitialized(handle,'Connection');
323-
handle.disconnect();
324-
}
325-
326317
// PROVIDER_HEAPDUMP
327318
{
328319
v8.getHeapSnapshot().destroy();

‎typings/internalBinding/async_wrap.d.ts‎

Lines changed: 0 additions & 1 deletion
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)