mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: drop DEBUG for public API calls (#3246)
This proved to be useless: we've never used it since we released the initial version of puppeteer more than a year ago.
This commit is contained in:
@@ -103,67 +103,32 @@ class Helper {
|
||||
* @param {string=} publicName
|
||||
*/
|
||||
static tracePublicAPI(classType, publicName) {
|
||||
if (!apiCoverage)
|
||||
return;
|
||||
|
||||
let className = publicName || classType.prototype.constructor.name;
|
||||
className = className.substring(0, 1).toLowerCase() + className.substring(1);
|
||||
const debug = require('debug')(`puppeteer:${className}`);
|
||||
if (!debug.enabled && !apiCoverage)
|
||||
return;
|
||||
for (const methodName of Reflect.ownKeys(classType.prototype)) {
|
||||
const method = Reflect.get(classType.prototype, methodName);
|
||||
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function')
|
||||
continue;
|
||||
if (apiCoverage)
|
||||
apiCoverage.set(`${className}.${methodName}`, false);
|
||||
apiCoverage.set(`${className}.${methodName}`, false);
|
||||
Reflect.set(classType.prototype, methodName, function(...args) {
|
||||
const argsText = args.map(stringifyArgument).join(', ');
|
||||
const callsite = `${className}.${methodName}(${argsText})`;
|
||||
if (debug.enabled)
|
||||
debug(callsite);
|
||||
if (apiCoverage)
|
||||
apiCoverage.set(`${className}.${methodName}`, true);
|
||||
apiCoverage.set(`${className}.${methodName}`, true);
|
||||
return method.call(this, ...args);
|
||||
});
|
||||
}
|
||||
|
||||
if (classType.Events) {
|
||||
if (apiCoverage) {
|
||||
for (const event of Object.values(classType.Events))
|
||||
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, false);
|
||||
}
|
||||
for (const event of Object.values(classType.Events))
|
||||
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, false);
|
||||
const method = Reflect.get(classType.prototype, 'emit');
|
||||
Reflect.set(classType.prototype, 'emit', function(event, ...args) {
|
||||
const argsText = [JSON.stringify(event)].concat(args.map(stringifyArgument)).join(', ');
|
||||
if (debug.enabled && this.listenerCount(event))
|
||||
debug(`${className}.emit(${argsText})`);
|
||||
if (apiCoverage && this.listenerCount(event))
|
||||
if (this.listenerCount(event))
|
||||
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, true);
|
||||
return method.call(this, event, ...args);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Object} arg
|
||||
* @return {string}
|
||||
*/
|
||||
function stringifyArgument(arg) {
|
||||
if (Helper.isString(arg) || Helper.isNumber(arg) || !arg)
|
||||
return JSON.stringify(arg);
|
||||
if (typeof arg === 'function') {
|
||||
let text = arg.toString().split('\n').map(line => line.trim()).join('');
|
||||
if (text.length > 20)
|
||||
text = text.substring(0, 20) + '…';
|
||||
return `"${text}"`;
|
||||
}
|
||||
const state = {};
|
||||
const keys = Object.keys(arg);
|
||||
for (const key of keys) {
|
||||
const value = arg[key];
|
||||
if (Helper.isString(value) || Helper.isNumber(value))
|
||||
state[key] = JSON.stringify(value);
|
||||
}
|
||||
const name = arg.constructor.name === 'Object' ? '' : arg.constructor.name;
|
||||
return name + JSON.stringify(state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user