Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 let resourceName = match && match[1]; | 84 let resourceName = match && match[1]; |
85 if (resourceName && resources.hasOwnProperty(resourceName)) | 85 if (resourceName && resources.hasOwnProperty(resourceName)) |
86 return {[resourceName]: resources[resourceName]}; | 86 return {[resourceName]: resources[resourceName]}; |
87 | 87 |
88 throw new Error( | 88 throw new Error( |
89 "Attempt to import unknown JavaScript module " + resource | 89 "Attempt to import unknown JavaScript module " + resource |
90 ); | 90 ); |
91 }, | 91 }, |
92 reportError(e) {} | 92 reportError(e) {} |
93 }, | 93 }, |
94 console: { | |
95 log: console.log.bind(console), | |
96 error: console.error.bind(console) | |
97 }, | |
98 navigator: { | 94 navigator: { |
99 }, | 95 }, |
100 onShutdown: { | 96 onShutdown: { |
101 add() {} | 97 add() {} |
102 }, | 98 }, |
103 URL | 99 URL |
104 }; | 100 }; |
105 | 101 |
106 let knownModules = new Map(); | 102 let knownModules = new Map(); |
107 for (let dir of [path.join(__dirname, "stub-modules"), | 103 for (let dir of [path.join(__dirname, "stub-modules"), |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 Date: { | 410 Date: { |
415 now: () => currentTime | 411 now: () => currentTime |
416 } | 412 } |
417 }; | 413 }; |
418 }; | 414 }; |
419 | 415 |
420 console.warn = console.log; | 416 console.warn = console.log; |
421 | 417 |
422 exports.silenceWarnOutput = function(test, msg) | 418 exports.silenceWarnOutput = function(test, msg) |
423 { | 419 { |
424 let warnHandler = globals.console.warn; | 420 let warnHandler = console.warn; |
425 globals.console.warn = s => | 421 console.warn = s => |
426 { | 422 { |
427 if (s != msg) | 423 if (s != msg) |
428 warnHandler(s); | 424 warnHandler(s); |
429 }; | 425 }; |
430 try | 426 try |
431 { | 427 { |
432 return test(); | 428 return test(); |
433 } | 429 } |
434 finally | 430 finally |
435 { | 431 { |
436 globals.console.warn = warnHandler; | 432 console.warn = warnHandler; |
437 } | 433 } |
438 }; | 434 }; |
439 | 435 |
440 exports.silenceAssertionOutput = function(test, msg) | 436 exports.silenceAssertionOutput = function(test, msg) |
441 { | 437 { |
442 let msgMatch = new RegExp(`^Error: ${msg}[\r\n]`); | 438 let msgMatch = new RegExp("^Error: (.*)[\r\n]"); |
443 let errorHandler = globals.console.error; | 439 let errorHandler = console.error; |
444 globals.console.error = s => | 440 console.error = s => |
sergei
2017/11/28 15:46:22
should not we wrap even a single argument of the l
hub
2017/11/28 15:54:20
This follow our code style.
| |
445 { | 441 { |
446 if (!msgMatch.test(s)) | 442 let match = msgMatch.match(s); |
sergei
2017/11/28 15:46:22
AFAIR regexp does not have method `match`, it shou
hub
2017/11/28 15:54:20
Already fixed in the patch update. I have no idea
| |
443 if (!match || match[1] != msg) | |
447 errorHandler(s); | 444 errorHandler(s); |
448 }; | 445 }; |
449 try | 446 try |
450 { | 447 { |
451 return test(); | 448 return test(); |
452 } | 449 } |
453 finally | 450 finally |
454 { | 451 { |
455 globals.console.error = errorHandler; | 452 console.error = errorHandler; |
456 } | 453 } |
457 }; | 454 }; |
458 | 455 |
459 exports.setupRandomResult = function() | 456 exports.setupRandomResult = function() |
460 { | 457 { |
461 let randomResult = 0.5; | 458 let randomResult = 0.5; |
462 Object.defineProperty(this, "randomResult", { | 459 Object.defineProperty(this, "randomResult", { |
463 get: () => randomResult, | 460 get: () => randomResult, |
464 set: value => randomResult = value | 461 set: value => randomResult = value |
465 }); | 462 }); |
466 | 463 |
467 return { | 464 return { |
468 Math: Object.create(Math, { | 465 Math: Object.create(Math, { |
469 random: { | 466 random: { |
470 value: () => randomResult | 467 value: () => randomResult |
471 } | 468 } |
472 }) | 469 }) |
473 }; | 470 }; |
474 }; | 471 }; |
475 | 472 |
476 exports.unexpectedError = function(error) | 473 exports.unexpectedError = function(error) |
477 { | 474 { |
478 console.error(error); | 475 console.error(error); |
479 this.ok(false, "Unexpected error: " + error); | 476 this.ok(false, "Unexpected error: " + error); |
480 }; | 477 }; |
OLD | NEW |