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: Addressed Sebastian's initial feedback Created Feb. 21, 2017, 6: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 "use strict"; 18 "use strict";
19 19
20 let fs = require("fs"); 20 const fs = require("fs");
21 let path = require("path"); 21 const path = require("path");
22 let SandboxedModule = require("sandboxed-module"); 22 const SandboxedModule = require("sandboxed-module");
23 23
24 const Cr = exports.Cr = { 24 const Cr = exports.Cr = {
25 NS_OK: 0, 25 NS_OK: 0,
26 NS_BINDING_ABORTED: 0x804B0002, 26 NS_BINDING_ABORTED: 0x804B0002,
27 NS_ERROR_FAILURE: 0x80004005 27 NS_ERROR_FAILURE: 0x80004005
28 }; 28 };
29 29
30 const MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; 30 const MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000;
31 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;
32 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;
33 33
34 function URL(urlString) 34 function URL(urlString)
35 { 35 {
36 return require("url").parse(urlString); 36 return require("url").parse(urlString);
37 } 37 }
38 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};
74
39 let globals = { 75 let globals = {
40 atob: data => new Buffer(data, "base64").toString("binary"), 76 atob: data => new Buffer(data, "base64").toString("binary"),
41 btoa: data => new Buffer(data, "binary").toString("base64"), 77 btoa: data => new Buffer(data, "binary").toString("base64"),
42 Ci: { 78 Ci: {
43 }, 79 },
44 Cu: { 80 Cu: {
45 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 },
46 reportError(e) {} 92 reportError(e) {}
47 }, 93 },
48 console: { 94 console: {
49 log() {}, 95 log() {},
50 error() {} 96 error() {}
51 }, 97 },
52 navigator: { 98 navigator: {
53 }, 99 },
54 onShutdown: { 100 onShutdown: {
55 add() {} 101 add() {}
56 },
57 Services: {
58 obs: {
59 addObserver() {}
60 },
61 vc: {
62 compare(v1, v2)
63 {
64 function comparePart(p1, p2)
65 {
66 if (p1 != "*" && p2 == "*")
67 return -1;
68 else if (p1 == "*" && p2 != "*")
69 return 1;
70 else if (p1 == p2)
71 return 0;
72 return parseInt(p1, 10) - parseInt(p2, 10);
73 }
74
75 let parts1 = v1.split(".");
76 let parts2 = v2.split(".");
77 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++)
78 {
79 let result = comparePart(parts1[i] || "0", parts2[i] || "0");
80 if (result != 0)
81 return result;
82 }
83 return 0;
84 }
85 }
86 },
87 XPCOMUtils: {
88 generateQI() {}
89 }, 102 },
90 URL 103 URL
91 }; 104 };
92 105
93 let knownModules = new Map(); 106 let knownModules = new Map();
94 for (let dir of [path.join(__dirname, "stub-modules"), 107 for (let dir of [path.join(__dirname, "stub-modules"),
95 path.join(__dirname, "..", "lib")]) 108 path.join(__dirname, "..", "lib")])
96 { 109 {
97 for (let file of fs.readdirSync(path.resolve(dir))) 110 for (let file of fs.readdirSync(path.resolve(dir)))
98 { 111 {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 nsIHttpChannel: () => null 410 nsIHttpChannel: () => null
398 }, 411 },
399 Cr, 412 Cr,
400 XMLHttpRequest, 413 XMLHttpRequest,
401 Date: { 414 Date: {
402 now: () => currentTime 415 now: () => currentTime
403 } 416 }
404 }; 417 };
405 }; 418 };
406 419
407 /* eslint-disable no-console */
Sebastian Noack 2017/02/21 09:19:32 Why is this necessary anyway? We shouldn't have an
kzar 2017/02/21 10:37:03 Honestly I'm not sure why but when running our uni
Sebastian Noack 2017/02/21 11:11:56 Please first figure out what's going on here. Perh
kzar 2017/02/21 11:27:41 Well I've tried but I couldn't figure it out. I st
408 console.warn = console.log; 420 console.warn = console.log;
409 /* eslint-enable no-console */
410 421
411 exports.setupRandomResult = function() 422 exports.setupRandomResult = function()
412 { 423 {
413 let randomResult = 0.5; 424 let randomResult = 0.5;
414 Object.defineProperty(this, "randomResult", { 425 Object.defineProperty(this, "randomResult", {
415 get: () => randomResult, 426 get: () => randomResult,
416 set: value => randomResult = value 427 set: value => randomResult = value
417 }); 428 });
418 429
419 return { 430 return {
420 Math: { 431 Math: {
421 random: () => randomResult, 432 random: () => randomResult,
422 min: Math.min, 433 min: Math.min,
423 max: Math.max, 434 max: Math.max,
424 round: Math.round 435 round: Math.round
425 } 436 }
426 }; 437 };
427 }; 438 };
428 439
429 exports.unexpectedError = function(error) 440 exports.unexpectedError = function(error)
430 { 441 {
431 console.error(error); 442 console.error(error);
432 this.ok(false, "Unexpected error: " + error); 443 this.ok(false, "Unexpected error: " + error);
433 }; 444 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld