Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function testNoCrashWithExceptionInCallback() {
// There is a deliberate exception in the callback
const session = new inspector.Session();
session.connect();
const error = new Error('We expect this');
console.log('Expecting warning to be emitted');
const promise = new Promise(waitForWarningSkipAsyncStackTraces);
session.post('Console.enable', () => { throw error; });
assert.strictEqual(await promise, error);
session.disconnect();
}
const inspector = require('inspector');
const setDepth = 'Debugger.setAsyncCallStackDepth';
function verifyAsyncHookDisabled(message) {
assert.strictEqual(async_wrap.async_hook_fields[kTotals], 0);
}
function verifyAsyncHookEnabled(message) {
assert.strictEqual(async_wrap.async_hook_fields[kTotals], 4);
}
// By default inspector async hooks should not have been installed.
verifyAsyncHookDisabled('inspector async hook should be disabled at startup');
const session = new inspector.Session();
verifyAsyncHookDisabled('creating a session should not enable async hooks');
session.connect();
verifyAsyncHookDisabled('connecting a session should not enable async hooks');
session.post('Debugger.enable', () => {
verifyAsyncHookDisabled('enabling debugger should not enable async hooks');
session.post(setDepth, { invalid: 'message' }, () => {
verifyAsyncHookDisabled('invalid message should not enable async hooks');
session.post(setDepth, { maxDepth: 'five' }, () => {
verifyAsyncHookDisabled('invalid maxDepth (string) should not enable ' +
'async hooks');
session.post(setDepth, { maxDepth: NaN }, () => {
'IOPIPE_ENABLE_HEAPSNAPSHOT',
this.config.heapSnapshot
);
this.enabled = this.profilerEnabled || this.heapEnabled;
this.uploads = [];
// pre-invoke hooks cannot be async, so create our own promise to wait on
// before the post-invoke method runs
this.pluginReadyPromise = Promise.resolve();
this.hooks = {
'pre:invoke': this.preInvoke.bind(this),
'post:invoke': this.postInvoke.bind(this),
'post:report': this.postReport.bind(this)
};
this.session = new inspector.Session();
// promisify session.post
this.sessionPost = (key, obj = {}) => {
this.log(`${key}, opts = ${JSON.stringify(obj)}`);
return new Promise((resolve, reject) => {
this.session.post(
key,
obj,
(err, msg) => (err ? reject(err) : resolve(msg))
);
});
};
this.coreUtil = null;
return this;
}
const notify = require("./notify");
const { Byte } = require("./metrics/byte");
const { Logical } = require("./metrics/logical");
const { Arithmetic } = require("./metrics/arithmetic");
/**
* @see https://nodejs.org/api/modules.html#modules_the_module_wrapper
*/
// @ts-ignore: This uses an internal API.
const [header] = require("module").wrapper;
const { min, max } = Math;
const session = new Session();
const metrics = [
{
...Arithmetic,
weight: 1 / 3
},
{
...Byte,
weight: 1 / 3
},
{
...Logical,
weight: 1 / 3
}
];
async function testNoCrashConsoleLogBeforeThrow() {
const session = new inspector.Session();
session.connect();
let attempt = 1;
process.on('warning', common.mustCall(3));
session.on('inspectorNotification', () => {
if (attempt++ > 3)
return;
console.log('console.log in handler');
throw new Error('Exception in handler');
});
session.post('Runtime.enable');
console.log('Did not crash');
session.disconnect();
}
async function testConsoleLog() {
const session = new inspector.Session();
session.connect();
session.on('inspectorNotification', (data) => {
if (data.method === 'Runtime.consoleAPICalled') {
assert.strictEqual(data.params.args.length, 1);
assert.strictEqual(data.params.args[0].value, msg);
asserted = true;
}
});
session.post('Runtime.enable');
console.log(msg);
session.disconnect();
}
i: [0, 1, 2, 3, 4],
accum: [0, 0, 1, 3, 6]
};
scopeCallback = function(error, result) {
const i = cur++;
let v, actual, expected;
for (v of result.result) {
actual = v.value.value;
expected = expects[v.name][i];
if (actual !== expected) {
failures.push(`Iteration ${i} variable: ${v.name} ` +
`expected: ${expected} actual: ${actual}`);
}
}
};
const session = new inspector.Session();
session.connect();
session.on('Debugger.paused',
(notification) => debuggerPausedCallback(session, notification));
let cbAsSecondArgCalled = false;
assert.throws(() => {
session.post('Debugger.enable', function() {}, function() {});
}, TypeError);
session.post('Debugger.enable', () => cbAsSecondArgCalled = true);
session.post('Debugger.setBreakpointByUrl', {
'lineNumber': 14,
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
'columnNumber': 0,
'condition': ''
});
debuggedFunction();
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const { Session } = require('inspector');
const { inspect } = require('util');
const session = new Session();
common.expectsError(
() => session.post('Runtime.evaluate', { expression: '2 + 2' }),
{
code: 'ERR_INSPECTOR_NOT_CONNECTED',
type: Error,
message: 'Session is not connected'
}
);
session.connect();
session.post('Runtime.evaluate', { expression: '2 + 2' });
[1, {}, [], true, Infinity, undefined].forEach((i) => {
common.expectsError(
() => session.post(i),
const common = require('../common');
const { Worker } = require('worker_threads');
common.skipIfInspectorDisabled();
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
new Worker(__filename);
return;
}
const assert = require('assert');
const { Session } = require('inspector');
const session = new Session();
session.connect();
session.post('NodeTracing.start', {
traceConfig: { includedCategories: ['node.perf'] }
}, common.mustCall((err) => {
assert.deepStrictEqual(err, {
code: -32000,
message:
'Tracing properties can only be changed through main thread sessions'
});
}));
session.disconnect();
(async () => {
let enabled = 0;
registerAsyncHook(() => ++enabled, () => {});
const session = new Session();
session.connect();
session.post = promisify(session.post);
await session.post('Debugger.enable');
strictEqual(enabled, 0);
await session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 42 });
strictEqual(enabled, 1);
throw new Error(eyecatcher);
})();
} else {