Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/_common.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Left Patch Set: Stop using commonjs, fix other problems Created Feb. 21, 2017, 5:12 a.m.
Right Patch Set: Removed unused imports Created March 15, 2017, 3:11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/.eslintrc.json ('k') | test/domainRestrictions.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* globals __dirname, console, Buffer */
19
20 "use strict"; 18 "use strict";
21 19
22 let fs = require("fs"); 20 const fs = require("fs");
23 let path = require("path"); 21 const path = require("path");
24 let SandboxedModule = require("sandboxed-module"); 22 const SandboxedModule = require("sandboxed-module");
25 23
26 const Cr = exports.Cr = { 24 const Cr = exports.Cr = {
27 NS_OK: 0, 25 NS_OK: 0,
28 NS_BINDING_ABORTED: 0x804B0002, 26 NS_BINDING_ABORTED: 0x804B0002,
29 NS_ERROR_FAILURE: 0x80004005 27 NS_ERROR_FAILURE: 0x80004005
30 }; 28 };
31 29
32 const MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; 30 const MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000;
33 const MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; 31 const MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND;
34 const MILLIS_IN_HOUR = exports.MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE; 32 const MILLIS_IN_HOUR = exports.MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE;
35 const MILLIS_IN_DAY = exports.MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR;
36 33
37 function URL(urlString) 34 function URL(urlString)
38 { 35 {
39 return require("url").parse(urlString); 36 return require("url").parse(urlString);
40 } 37 }
38
39 let Services = {
40 obs: {
41 addObserver() {}
42 },
43 vc: {
44 compare(v1, v2)
45 {
46 function comparePart(p1, p2)
47 {
48 if (p1 != "*" && p2 == "*")
49 return -1;
50 else if (p1 == "*" && p2 != "*")
51 return 1;
52 else if (p1 == p2)
53 return 0;
54 return parseInt(p1, 10) - parseInt(p2, 10);
55 }
56
57 let parts1 = v1.split(".");
58 let parts2 = v2.split(".");
59 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++)
60 {
61 let result = comparePart(parts1[i] || "0", parts2[i] || "0");
62 if (result != 0)
63 return result;
64 }
65 return 0;
66 }
67 }
68 };
69 let XPCOMUtils = {
70 generateQI() {}
71 };
72 let FileUtils = {};
73 let resources = {Services, XPCOMUtils, FileUtils};
41 74
42 let globals = { 75 let globals = {
43 atob: data => new Buffer(data, "base64").toString("binary"), 76 atob: data => new Buffer(data, "base64").toString("binary"),
44 btoa: data => new Buffer(data, "binary").toString("base64"), 77 btoa: data => new Buffer(data, "binary").toString("base64"),
45 Ci: { 78 Ci: {
46 }, 79 },
47 Cu: { 80 Cu: {
48 import() {}, 81 import(resource)
82 {
83 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource);
84 let resourceName = match && match[1];
85 if (resourceName && resources.hasOwnProperty(resourceName))
86 return {[resourceName]: resources[resourceName]};
87
88 throw new Error(
89 "Attempt to import unknown JavaScript module " + resource
90 );
91 },
49 reportError(e) {} 92 reportError(e) {}
50 }, 93 },
51 console: { 94 console: {
52 log() {}, 95 log() {},
53 error() {} 96 error() {}
54 }, 97 },
55 navigator: { 98 navigator: {
56 }, 99 },
57 onShutdown: { 100 onShutdown: {
58 add() {} 101 add() {}
59 },
60 Services: {
61 obs: {
62 addObserver() {}
63 },
64 vc: {
65 compare(v1, v2)
66 {
67 function comparePart(p1, p2)
68 {
69 if (p1 != "*" && p2 == "*")
70 return -1;
71 else if (p1 == "*" && p2 != "*")
72 return 1;
73 else if (p1 == p2)
74 return 0;
75 return parseInt(p1, 10) - parseInt(p2, 10);
76 }
77
78 let parts1 = v1.split(".");
79 let parts2 = v2.split(".");
80 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++)
81 {
82 let result = comparePart(parts1[i] || "0", parts2[i] || "0");
83 if (result != 0)
84 return result;
85 }
86 return 0;
87 }
88 }
89 },
90 XPCOMUtils: {
91 generateQI() {}
92 }, 102 },
93 URL 103 URL
94 }; 104 };
95 105
96 let knownModules = new Map(); 106 let knownModules = new Map();
97 for (let dir of [path.join(__dirname, "stub-modules"), 107 for (let dir of [path.join(__dirname, "stub-modules"),
98 path.join(__dirname, "..", "lib")]) 108 path.join(__dirname, "..", "lib")])
99 { 109 {
100 for (let file of fs.readdirSync(path.resolve(dir))) 110 for (let file of fs.readdirSync(path.resolve(dir)))
101 { 111 {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 nsIHttpChannel: () => null 410 nsIHttpChannel: () => null
401 }, 411 },
402 Cr, 412 Cr,
403 XMLHttpRequest, 413 XMLHttpRequest,
404 Date: { 414 Date: {
405 now: () => currentTime 415 now: () => currentTime
406 } 416 }
407 }; 417 };
408 }; 418 };
409 419
410 /* eslint-disable no-console */
411 console.warn = console.log; 420 console.warn = console.log;
412 /* eslint-enable no-console */
413 421
414 exports.setupRandomResult = function() 422 exports.setupRandomResult = function()
415 { 423 {
416 let randomResult = 0.5; 424 let randomResult = 0.5;
417 Object.defineProperty(this, "randomResult", { 425 Object.defineProperty(this, "randomResult", {
418 get: () => randomResult, 426 get: () => randomResult,
419 set: value => randomResult = value 427 set: value => randomResult = value
420 }); 428 });
421 429
422 return { 430 return {
423 Math: { 431 Math: {
424 random: () => randomResult, 432 random: () => randomResult,
425 min: Math.min, 433 min: Math.min,
426 max: Math.max, 434 max: Math.max,
427 round: Math.round 435 round: Math.round
428 } 436 }
429 }; 437 };
430 }; 438 };
431 439
432 exports.unexpectedError = function(error) 440 exports.unexpectedError = function(error)
433 { 441 {
434 console.error(error); 442 console.error(error);
435 this.ok(false, "Unexpected error: " + error); 443 this.ok(false, "Unexpected error: " + error);
436 }; 444 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld