| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f0a8166 commit 5cc2574
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,8 +42,6 @@ const { getOptionValue } = NativeModule.require('internal/options'); | |||
| 42 | 42 | const config = internalBinding('config'); | |
| 43 | 43 | const { deprecate } = NativeModule.require('internal/util'); | |
| 44 | 44 | ||
| 45 | - setupTraceCategoryState(); | ||
| 46 | - | ||
| 47 | 45 | setupProcessObject(); | |
| 48 | 46 | ||
| 49 | 47 | setupGlobalProxy(); | |
@@ -354,35 +352,6 @@ if (getOptionValue('--experimental-report')) { | |||
| 354 | 352 | } | |
| 355 | 353 | } | |
| 356 | 354 | ||
| 357 | - function setupTraceCategoryState() { | ||
| 358 | - const { | ||
| 359 | - traceCategoryState, | ||
| 360 | - setTraceCategoryStateUpdateHandler | ||
| 361 | - } = internalBinding('trace_events'); | ||
| 362 | - const kCategoryAsyncHooks = 0; | ||
| 363 | - let traceEventsAsyncHook; | ||
| 364 | - | ||
| 365 | - function toggleTraceCategoryState() { | ||
| 366 | - // Dynamically enable/disable the traceEventsAsyncHook | ||
| 367 | - const asyncHooksEnabled = !!traceCategoryState[kCategoryAsyncHooks]; | ||
| 368 | - | ||
| 369 | - if (asyncHooksEnabled) { | ||
| 370 | - // Lazy load internal/trace_events_async_hooks only if the async_hooks | ||
| 371 | - // trace event category is enabled. | ||
| 372 | - if (!traceEventsAsyncHook) { | ||
| 373 | - traceEventsAsyncHook = | ||
| 374 | - NativeModule.require('internal/trace_events_async_hooks'); | ||
| 375 | - } | ||
| 376 | - traceEventsAsyncHook.enable(); | ||
| 377 | - } else if (traceEventsAsyncHook) { | ||
| 378 | - traceEventsAsyncHook.disable(); | ||
| 379 | - } | ||
| 380 | - } | ||
| 381 | - | ||
| 382 | - toggleTraceCategoryState(); | ||
| 383 | - setTraceCategoryStateUpdateHandler(toggleTraceCategoryState); | ||
| 384 | - } | ||
| 385 | - | ||
| 386 | 355 | function setupProcessObject() { | |
| 387 | 356 | const EventEmitter = NativeModule.require('events'); | |
| 388 | 357 | const origProcProto = Object.getPrototypeOf(process); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,8 @@ | |||
| 3 | 3 | const { getOptionValue } = require('internal/options'); | |
| 4 | 4 | ||
| 5 | 5 | function prepareMainThreadExecution() { | |
| 6 | + setupTraceCategoryState(); | ||
| 7 | + | ||
| 6 | 8 | // If the process is spawned with env NODE_CHANNEL_FD, it's probably | |
| 7 | 9 | // spawned by our child_process module, then initialize IPC. | |
| 8 | 10 | // This attaches some internal event listeners and creates: | |
@@ -23,6 +25,34 @@ function prepareMainThreadExecution() { | |||
| 23 | 25 | loadPreloadModules(); | |
| 24 | 26 | } | |
| 25 | 27 | ||
| 28 | + function setupTraceCategoryState() { | ||
| 29 | + const { | ||
| 30 | + traceCategoryState, | ||
| 31 | + setTraceCategoryStateUpdateHandler | ||
| 32 | + } = internalBinding('trace_events'); | ||
| 33 | + const kCategoryAsyncHooks = 0; | ||
| 34 | + let traceEventsAsyncHook; | ||
| 35 | + | ||
| 36 | + function toggleTraceCategoryState() { | ||
| 37 | + // Dynamically enable/disable the traceEventsAsyncHook | ||
| 38 | + const asyncHooksEnabled = !!traceCategoryState[kCategoryAsyncHooks]; | ||
| 39 | + | ||
| 40 | + if (asyncHooksEnabled) { | ||
| 41 | + // Lazy load internal/trace_events_async_hooks only if the async_hooks | ||
| 42 | + // trace event category is enabled. | ||
| 43 | + if (!traceEventsAsyncHook) { | ||
| 44 | + traceEventsAsyncHook = require('internal/trace_events_async_hooks'); | ||
| 45 | + } | ||
| 46 | + traceEventsAsyncHook.enable(); | ||
| 47 | + } else if (traceEventsAsyncHook) { | ||
| 48 | + traceEventsAsyncHook.disable(); | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + toggleTraceCategoryState(); | ||
| 53 | + setTraceCategoryStateUpdateHandler(toggleTraceCategoryState); | ||
| 54 | + } | ||
| 55 | + | ||
| 26 | 56 | // In general deprecations are intialized wherever the APIs are implemented, | |
| 27 | 57 | // this is used to deprecate APIs implemented in C++ where the deprecation | |
| 28 | 58 | // utitlities are not easily accessible. | |
@@ -150,5 +180,6 @@ module.exports = { | |||
| 150 | 180 | prepareMainThreadExecution, | |
| 151 | 181 | initializeDeprecations, | |
| 152 | 182 | initializeESMLoader, | |
| 153 | - loadPreloadModules | ||
| 183 | + loadPreloadModules, | ||
| 184 | + setupTraceCategoryState | ||
| 154 | 185 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,14 +22,16 @@ if (process.argv[1] && process.argv[1] !== '-') { | |||
| 22 | 22 | // Expand process.argv[1] into a full path. | |
| 23 | 23 | const path = require('path'); | |
| 24 | 24 | process.argv[1] = path.resolve(process.argv[1]); | |
| 25 | + | ||
| 26 | + // TODO(joyeecheung): not every one of these are necessary | ||
| 27 | + prepareMainThreadExecution(); | ||
| 28 | + | ||
| 25 | 29 | // Read the source. | |
| 26 | 30 | const filename = CJSModule._resolveFilename(process.argv[1]); | |
| 27 | 31 | ||
| 28 | 32 | const fs = require('fs'); | |
| 29 | 33 | const source = fs.readFileSync(filename, 'utf-8'); | |
| 30 | 34 | ||
| 31 | - // TODO(joyeecheung): not every one of these are necessary | ||
| 32 | - prepareMainThreadExecution(); | ||
| 33 | 35 | markBootstrapComplete(); | |
| 34 | 36 | ||
| 35 | 37 | checkScriptSyntax(source, filename); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,8 @@ | |||
| 6 | 6 | const { | |
| 7 | 7 | initializeDeprecations, | |
| 8 | 8 | initializeESMLoader, | |
| 9 | - loadPreloadModules | ||
| 9 | + loadPreloadModules, | ||
| 10 | + setupTraceCategoryState | ||
| 10 | 11 | } = require('internal/bootstrap/pre_execution'); | |
| 11 | 12 | ||
| 12 | 13 | const { | |
@@ -72,6 +73,8 @@ port.on('message', (message) => { | |||
| 72 | 73 | manifestURL, | |
| 73 | 74 | hasStdin | |
| 74 | 75 | } = message; | |
| 76 | + | ||
| 77 | + setupTraceCategoryState(); | ||
| 75 | 78 | if (manifestSrc) { | |
| 76 | 79 | require('internal/process/policy').setup(manifestSrc, manifestURL); | |
| 77 | 80 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments