Skip to content

Commit da71c3a

Browse files
committed
Force console output when explicitly requested from dev tools
Related feedback: - https://bugzilla.mozilla.org/show_bug.cgi?id=1617666#c0 Not being able to see benchmark results when explicitly requesting benchmark results is not very user-friendly; this commit fixes this.
1 parent 953e0c3 commit da71c3a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/js/console.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ self.log = (function() {
3030
this.info = console.info = level === 'info' ? info : noopFunc;
3131
},
3232
info: noopFunc,
33+
print: info,
3334
};
3435
})();

src/js/static-net-filtering.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,9 @@ FilterContainer.prototype.benchmark = async function(action, target) {
34513451
return;
34523452
}
34533453

3454-
console.info(`Benchmarking staticNetFilteringEngine.matchString()...`);
3454+
const print = log.print;
3455+
3456+
print(`Benchmarking staticNetFilteringEngine.matchString()...`);
34553457
const fctxt = µb.filteringContext.duplicate();
34563458

34573459
if ( typeof target === 'number' ) {
@@ -3460,10 +3462,10 @@ FilterContainer.prototype.benchmark = async function(action, target) {
34603462
fctxt.setDocOriginFromURL(request.frameUrl);
34613463
fctxt.setType(request.cpt);
34623464
const r = this.matchString(fctxt);
3463-
console.log(`Result=${r}:`);
3464-
console.log(`\ttype=${fctxt.type}`);
3465-
console.log(`\turl=${fctxt.url}`);
3466-
console.log(`\tdocOrigin=${fctxt.getDocOrigin()}`);
3465+
print(`Result=${r}:`);
3466+
print(`\ttype=${fctxt.type}`);
3467+
print(`\turl=${fctxt.url}`);
3468+
print(`\tdocOrigin=${fctxt.getDocOrigin()}`);
34673469
if ( r !== 0 ) {
34683470
console.log(this.toLogData());
34693471
}
@@ -3492,21 +3494,21 @@ FilterContainer.prototype.benchmark = async function(action, target) {
34923494
const r = this.matchString(fctxt);
34933495
if ( recorded !== undefined ) { recorded.push(r); }
34943496
if ( expected !== undefined && r !== expected[i] ) {
3495-
console.log(`Mismatch with reference results at ${i}:`);
3496-
console.log(`\tExpected ${expected[i]}, got ${r}:`);
3497-
console.log(`\ttype=${fctxt.type}`);
3498-
console.log(`\turl=${fctxt.url}`);
3499-
console.log(`\tdocOrigin=${fctxt.getDocOrigin()}`);
3497+
print(`Mismatch with reference results at ${i}:`);
3498+
print(`\tExpected ${expected[i]}, got ${r}:`);
3499+
print(`\ttype=${fctxt.type}`);
3500+
print(`\turl=${fctxt.url}`);
3501+
print(`\tdocOrigin=${fctxt.getDocOrigin()}`);
35003502
}
35013503
}
35023504
const t1 = self.performance.now();
35033505
const dur = t1 - t0;
35043506

3505-
console.info(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
3506-
console.info(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
3507+
print(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
3508+
print(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
35073509
if ( expected !== undefined ) {
3508-
console.info(`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`);
3509-
console.info(`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`);
3510+
print(`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`);
3511+
print(`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`);
35103512
}
35113513
if ( recorded !== undefined ) {
35123514
vAPI.localStorage.setItem(

0 commit comments

Comments
 (0)