| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d2c169a commit ad5282e
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -193,6 +193,12 @@ static void SetPromiseHooks(const FunctionCallbackInfo<Value>& args) { | |||
| 193 | 193 | args[3]->IsFunction() ? args[3].As<Function>() : Local<Function>()); | |
| 194 | 194 | } | |
| 195 | 195 | ||
| 196 | + static void GetPromiseHooks(const FunctionCallbackInfo<Value>& args) { | ||
| 197 | + Environment* env = Environment::GetCurrent(args); | ||
| 198 | + args.GetReturnValue().Set( | ||
| 199 | + env->async_hooks()->GetPromiseHooks(args.GetIsolate())); | ||
| 200 | + } | ||
| 201 | + | ||
| 196 | 202 | class DestroyParam { | |
| 197 | 203 | public: | |
| 198 | 204 | double asyncId; | |
@@ -364,6 +370,7 @@ void AsyncWrap::CreatePerIsolateProperties(IsolateData* isolate_data, | |||
| 364 | 370 | SetMethod(isolate, target, "clearAsyncIdStack", ClearAsyncIdStack); | |
| 365 | 371 | SetMethod(isolate, target, "queueDestroyAsyncId", QueueDestroyAsyncId); | |
| 366 | 372 | SetMethod(isolate, target, "setPromiseHooks", SetPromiseHooks); | |
| 373 | + SetMethod(isolate, target, "getPromiseHooks", GetPromiseHooks); | ||
| 367 | 374 | SetMethod(isolate, target, "registerDestroyHook", RegisterDestroyHook); | |
| 368 | 375 | AsyncWrap::GetConstructorTemplate(isolate_data); | |
| 369 | 376 | } | |
@@ -469,6 +476,7 @@ void AsyncWrap::RegisterExternalReferences( | |||
| 469 | 476 | registry->Register(ClearAsyncIdStack); | |
| 470 | 477 | registry->Register(QueueDestroyAsyncId); | |
| 471 | 478 | registry->Register(SetPromiseHooks); | |
| 479 | + registry->Register(GetPromiseHooks); | ||
| 472 | 480 | registry->Register(RegisterDestroyHook); | |
| 473 | 481 | registry->Register(AsyncWrap::GetAsyncId); | |
| 474 | 482 | registry->Register(AsyncWrap::AsyncReset); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,18 @@ void AsyncHooks::ResetPromiseHooks(Local<Function> init, | |||
| 87 | 87 | js_promise_hooks_[3].Reset(env()->isolate(), resolve); | |
| 88 | 88 | } | |
| 89 | 89 | ||
| 90 | + Local<Array> AsyncHooks::GetPromiseHooks(Isolate* isolate) { | ||
| 91 | + std::vector<Local<Value>> values; | ||
| 92 | + for (size_t i = 0; i < js_promise_hooks_.size(); ++i) { | ||
| 93 | + if (js_promise_hooks_[i].IsEmpty()) { | ||
| 94 | + values.push_back(Undefined(isolate)); | ||
| 95 | + } else { | ||
| 96 | + values.push_back(js_promise_hooks_[i].Get(isolate)); | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + return Array::New(isolate, values.data(), values.size()); | ||
| 100 | + } | ||
| 101 | + | ||
| 90 | 102 | void Environment::ResetPromiseHooks(Local<Function> init, | |
| 91 | 103 | Local<Function> before, | |
| 92 | 104 | Local<Function> after, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -322,7 +322,9 @@ class AsyncHooks : public MemoryRetainer { | |||
| 322 | 322 | v8::Local<v8::Function> before, | |
| 323 | 323 | v8::Local<v8::Function> after, | |
| 324 | 324 | v8::Local<v8::Function> resolve); | |
| 325 | - | ||
| 325 | + // Used for testing since V8 doesn't provide API for retrieving configured | ||
| 326 | + // JS promise hooks. | ||
| 327 | + v8::Local<v8::Array> GetPromiseHooks(v8::Isolate* isolate); | ||
| 326 | 328 | inline v8::Local<v8::String> provider_string(int idx); | |
| 327 | 329 | ||
| 328 | 330 | inline void no_force_checks(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -923,7 +923,7 @@ void Agent::EnableAsyncHook() { | |||
| 923 | 923 | ||
| 924 | 924 | void Agent::DisableAsyncHook() { | |
| 925 | 925 | HandleScope scope(parent_env_->isolate()); | |
| 926 | - Local<Function> disable = parent_env_->inspector_enable_async_hooks(); | ||
| 926 | + Local<Function> disable = parent_env_->inspector_disable_async_hooks(); | ||
| 927 | 927 | if (!disable.IsEmpty()) { | |
| 928 | 928 | ToggleAsyncHook(parent_env_->isolate(), disable); | |
| 929 | 929 | } else if (pending_enable_async_hook_) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,21 +5,32 @@ common.skipIfInspectorDisabled(); | |||
| 5 | 5 | common.skipIf32Bits(); | |
| 6 | 6 | ||
| 7 | 7 | const assert = require('assert'); | |
| 8 | + const { inspect } = require('util'); | ||
| 8 | 9 | const { internalBinding } = require('internal/test/binding'); | |
| 9 | - const { async_hook_fields, constants } = internalBinding('async_wrap'); | ||
| 10 | + const { async_hook_fields, constants, getPromiseHooks } = internalBinding('async_wrap'); | ||
| 10 | 11 | const { kTotals } = constants; | |
| 11 | - const inspector = require('inspector'); | ||
| 12 | + const inspector = require('inspector/promises'); | ||
| 12 | 13 | ||
| 13 | 14 | const setDepth = 'Debugger.setAsyncCallStackDepth'; | |
| 14 | - | ||
| 15 | + const emptyPromiseHooks = [ undefined, undefined, undefined, undefined ]; | ||
| 15 | 16 | function verifyAsyncHookDisabled(message) { | |
| 16 | 17 | assert.strictEqual(async_hook_fields[kTotals], 0, | |
| 17 | 18 | `${async_hook_fields[kTotals]} !== 0: ${message}`); | |
| 19 | + const promiseHooks = getPromiseHooks(); | ||
| 20 | + assert.deepStrictEqual( | ||
| 21 | + promiseHooks, emptyPromiseHooks, | ||
| 22 | + `${message}: promise hooks ${inspect(promiseHooks)}` | ||
| 23 | + ); | ||
| 18 | 24 | } | |
| 19 | 25 | ||
| 20 | 26 | function verifyAsyncHookEnabled(message) { | |
| 21 | 27 | assert.strictEqual(async_hook_fields[kTotals], 4, | |
| 22 | 28 | `${async_hook_fields[kTotals]} !== 4: ${message}`); | |
| 29 | + const promiseHooks = getPromiseHooks(); | ||
| 30 | + assert.notDeepStrictEqual( | ||
| 31 | + promiseHooks, emptyPromiseHooks, | ||
| 32 | + `${message}: promise hooks ${inspect(promiseHooks)}` | ||
| 33 | + ); | ||
| 23 | 34 | } | |
| 24 | 35 | ||
| 25 | 36 | // By default inspector async hooks should not have been installed. | |
@@ -31,53 +42,38 @@ verifyAsyncHookDisabled('creating a session should not enable async hooks'); | |||
| 31 | 42 | session.connect(); | |
| 32 | 43 | verifyAsyncHookDisabled('connecting a session should not enable async hooks'); | |
| 33 | 44 | ||
| 34 | - session.post('Debugger.enable', () => { | ||
| 45 | + (async () => { | ||
| 46 | + await session.post('Debugger.enable'); | ||
| 35 | 47 | verifyAsyncHookDisabled('enabling debugger should not enable async hooks'); | |
| 36 | - | ||
| 37 | - session.post(setDepth, { invalid: 'message' }, () => { | ||
| 38 | - verifyAsyncHookDisabled('invalid message should not enable async hooks'); | ||
| 39 | - | ||
| 40 | - session.post(setDepth, { maxDepth: 'five' }, () => { | ||
| 41 | - verifyAsyncHookDisabled('invalid maxDepth (string) should not enable ' + | ||
| 42 | - 'async hooks'); | ||
| 43 | - | ||
| 44 | - session.post(setDepth, { maxDepth: NaN }, () => { | ||
| 45 | - verifyAsyncHookDisabled('invalid maxDepth (NaN) should not enable ' + | ||
| 46 | - 'async hooks'); | ||
| 47 | - | ||
| 48 | - session.post(setDepth, { maxDepth: 10 }, () => { | ||
| 49 | - verifyAsyncHookEnabled('valid message should enable async hooks'); | ||
| 50 | - | ||
| 51 | - session.post(setDepth, { maxDepth: 0 }, () => { | ||
| 52 | - verifyAsyncHookDisabled('Setting maxDepth to 0 should disable ' + | ||
| 53 | - 'async hooks'); | ||
| 54 | - | ||
| 55 | - runTestSet2(session); | ||
| 56 | - }); | ||
| 57 | - }); | ||
| 58 | - }); | ||
| 59 | - }); | ||
| 60 | - }); | ||
| 61 | - }); | ||
| 62 | - | ||
| 63 | - function runTestSet2(session) { | ||
| 64 | - session.post(setDepth, { maxDepth: 32 }, () => { | ||
| 65 | - verifyAsyncHookEnabled('valid message should enable async hooks'); | ||
| 66 | - | ||
| 67 | - session.post('Debugger.disable', () => { | ||
| 68 | - verifyAsyncHookDisabled('Debugger.disable should disable async hooks'); | ||
| 69 | - | ||
| 70 | - session.post('Debugger.enable', () => { | ||
| 71 | - verifyAsyncHookDisabled('Enabling debugger should not enable hooks'); | ||
| 72 | - | ||
| 73 | - session.post(setDepth, { maxDepth: 64 }, () => { | ||
| 74 | - verifyAsyncHookEnabled('valid message should enable async hooks'); | ||
| 75 | - | ||
| 76 | - session.disconnect(); | ||
| 77 | - verifyAsyncHookDisabled('Disconnecting session should disable ' + | ||
| 78 | - 'async hooks'); | ||
| 79 | - }); | ||
| 80 | - }); | ||
| 81 | - }); | ||
| 82 | - }); | ||
| 83 | - } | ||
| 48 | + await assert.rejects(session.post(setDepth, { invalid: 'message' }), { code: 'ERR_INSPECTOR_COMMAND' }); | ||
| 49 | + verifyAsyncHookDisabled('invalid message should not enable async hooks'); | ||
| 50 | + await assert.rejects(session.post(setDepth, { maxDepth: 'five' }), { code: 'ERR_INSPECTOR_COMMAND' }); | ||
| 51 | + verifyAsyncHookDisabled('invalid maxDepth (string) should not enable ' + | ||
| 52 | + 'async hooks'); | ||
| 53 | + await assert.rejects(session.post(setDepth, { maxDepth: NaN }), { code: 'ERR_INSPECTOR_COMMAND' }); | ||
| 54 | + verifyAsyncHookDisabled('invalid maxDepth (NaN) should not enable ' + | ||
| 55 | + 'async hooks'); | ||
| 56 | + await session.post(setDepth, { maxDepth: 10 }); | ||
| 57 | + verifyAsyncHookEnabled('valid message should enable async hooks'); | ||
| 58 | + | ||
| 59 | + await session.post(setDepth, { maxDepth: 0 }); | ||
| 60 | + verifyAsyncHookDisabled('Setting maxDepth to 0 should disable ' + | ||
| 61 | + 'async hooks'); | ||
| 62 | + | ||
| 63 | + await session.post(setDepth, { maxDepth: 32 }); | ||
| 64 | + verifyAsyncHookEnabled('valid message should enable async hooks'); | ||
| 65 | + | ||
| 66 | + await session.post('Debugger.disable'); | ||
| 67 | + verifyAsyncHookDisabled('Debugger.disable should disable async hooks'); | ||
| 68 | + | ||
| 69 | + await session.post('Debugger.enable'); | ||
| 70 | + verifyAsyncHookDisabled('Enabling debugger should not enable hooks'); | ||
| 71 | + | ||
| 72 | + await session.post(setDepth, { maxDepth: 64 }); | ||
| 73 | + verifyAsyncHookEnabled('valid message should enable async hooks'); | ||
| 74 | + | ||
| 75 | + await session.disconnect(); | ||
| 76 | + | ||
| 77 | + verifyAsyncHookDisabled('Disconnecting session should disable ' + | ||
| 78 | + 'async hooks'); | ||
| 79 | + })().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments