mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
src: use internalBinding('config').hasInspector
in JS land
Instead of `process.config.variables.v8_enable_inspector` which depends on the variable name in gyp files, or detecting `internalBinding('inspector').Connection`. PR-URL: https://github.com/nodejs/node/pull/25291 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d4934ae6f2
commit
b22c86ed3b
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const {
|
||||
ERR_INSPECTOR_ALREADY_CONNECTED,
|
||||
ERR_INSPECTOR_CLOSED,
|
||||
@ -9,13 +8,16 @@ const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_CALLBACK
|
||||
} = require('internal/errors').codes;
|
||||
|
||||
const { hasInspector } = internalBinding('config');
|
||||
if (!hasInspector)
|
||||
throw new ERR_INSPECTOR_NOT_AVAILABLE();
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const { validateString } = require('internal/validators');
|
||||
const util = require('util');
|
||||
const { Connection, open, url } = internalBinding('inspector');
|
||||
|
||||
if (!Connection)
|
||||
throw new ERR_INSPECTOR_NOT_AVAILABLE();
|
||||
|
||||
const connectionSymbol = Symbol('connectionProperty');
|
||||
const messageCallbacksSymbol = Symbol('messageCallbacks');
|
||||
const nextIdSymbol = Symbol('nextId');
|
||||
|
@ -9,7 +9,7 @@ const { NativeModule } = require('internal/bootstrap/loaders');
|
||||
const {
|
||||
source, getCodeCache, compileFunction
|
||||
} = internalBinding('native_module');
|
||||
const { hasTracing } = process.binding('config');
|
||||
const { hasTracing, hasInspector } = process.binding('config');
|
||||
|
||||
const depsModule = Object.keys(source).filter(
|
||||
(key) => NativeModule.isDepsModule(key) || key.startsWith('internal/deps')
|
||||
@ -33,7 +33,7 @@ const cannotUseCache = [
|
||||
|
||||
// Skip modules that cannot be required when they are not
|
||||
// built into the binary.
|
||||
if (process.config.variables.v8_enable_inspector !== 1) {
|
||||
if (!hasInspector) {
|
||||
cannotUseCache.push(
|
||||
'inspector',
|
||||
'internal/util/inspector',
|
||||
|
@ -19,6 +19,7 @@
|
||||
const { internalBinding, NativeModule } = loaderExports;
|
||||
|
||||
const { getOptionValue } = NativeModule.require('internal/options');
|
||||
const config = internalBinding('config');
|
||||
|
||||
function startup() {
|
||||
setupTraceCategoryState();
|
||||
@ -164,7 +165,7 @@ function startup() {
|
||||
NativeModule.require('internal/process/coverage').setupExitHooks();
|
||||
}
|
||||
|
||||
if (process.config.variables.v8_enable_inspector) {
|
||||
if (config.hasInspector) {
|
||||
NativeModule.require('internal/inspector_async_hook').setup();
|
||||
}
|
||||
|
||||
@ -280,7 +281,7 @@ function startup() {
|
||||
|
||||
// TODO(joyeecheung): this property has not been well-maintained, should we
|
||||
// deprecate it in favor of a better API?
|
||||
const { isDebugBuild, hasOpenSSL } = internalBinding('config');
|
||||
const { isDebugBuild, hasOpenSSL } = config;
|
||||
Object.defineProperty(process, 'features', {
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
@ -630,7 +631,7 @@ function setupGlobalConsole() {
|
||||
writable: true
|
||||
});
|
||||
// TODO(joyeecheung): can we skip this if inspector is not active?
|
||||
if (process.config.variables.v8_enable_inspector) {
|
||||
if (config.hasInspector) {
|
||||
const inspector =
|
||||
NativeModule.require('internal/console/inspector');
|
||||
inspector.addInspectorApis(consoleFromNode, consoleFromVM);
|
||||
|
@ -51,12 +51,13 @@ function disableAllAsyncHooks() {
|
||||
exports.writeCoverage = writeCoverage;
|
||||
|
||||
function setup() {
|
||||
const { Connection } = internalBinding('inspector');
|
||||
if (!Connection) {
|
||||
const { hasInspector } = internalBinding('config');
|
||||
if (!hasInspector) {
|
||||
process._rawDebug('inspector not enabled');
|
||||
return;
|
||||
}
|
||||
|
||||
const { Connection } = internalBinding('inspector');
|
||||
coverageConnection = new Connection((res) => {
|
||||
if (coverageConnection._coverageCallback) {
|
||||
coverageConnection._coverageCallback(res);
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const hasInspector = process.config.variables.v8_enable_inspector === 1;
|
||||
const { hasInspector } = internalBinding('config');
|
||||
const inspector = hasInspector ? require('inspector') : undefined;
|
||||
|
||||
let session;
|
||||
|
@ -57,6 +57,12 @@ static void Initialize(Local<Object> target,
|
||||
READONLY_TRUE_PROPERTY(target, "hasTracing");
|
||||
#endif
|
||||
|
||||
#if HAVE_INSPECTOR
|
||||
READONLY_TRUE_PROPERTY(target, "hasInspector");
|
||||
#else
|
||||
READONLY_FALSE_PROPERTY(target, "hasInspector");
|
||||
#endif
|
||||
|
||||
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
|
||||
READONLY_TRUE_PROPERTY(target, "hasNodeOptions");
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user