Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 // | 22 // |
23 // Module framework stuff | 23 // Module framework stuff |
24 // | 24 // |
25 | 25 |
26 function require(module) | 26 function require(module) |
27 { | 27 { |
28 return require.scopes[module]; | 28 return require.scopes[module]; |
29 } | 29 } |
30 require.scopes = {__proto__: null}; | 30 require.scopes = {__proto__: null}; |
31 | |
32 function importAll(module, globalObj) | |
sergei
2017/09/18 07:59:05
It seems this function is not used, could you just
hub
2017/09/18 12:43:05
Done.
| |
33 { | |
34 let exports = require(module); | |
35 for (let key in exports) | |
36 globalObj[key] = exports[key]; | |
37 } | |
38 | 31 |
39 const onShutdown = { | 32 const onShutdown = { |
40 done: false, | 33 done: false, |
41 add() {}, | 34 add() {}, |
42 remove() {} | 35 remove() {} |
43 }; | 36 }; |
44 | 37 |
45 // | 38 // |
46 // XPCOM emulation | 39 // XPCOM emulation |
47 // | 40 // |
48 | 41 |
49 // nsIHttpChannel is checked against instanceof. | 42 // nsIHttpChannel is checked against instanceof. |
50 class nsIHttpChannel | 43 class nsIHttpChannel |
51 { | 44 { |
52 } | 45 } |
53 | 46 |
54 const Components = | 47 const Components = |
55 { | 48 { |
56 interfaces: | 49 interfaces: |
57 { | 50 { |
58 nsIHttpChannel, | 51 nsIHttpChannel, |
hub
2017/09/15 19:44:00
This one was a bit of a corner case. eslint style
sergei
2017/09/18 07:59:05
Acknowledged.
| |
59 nsITimer: {TYPE_REPEATING_SLACK: 0} | 52 nsITimer: {TYPE_REPEATING_SLACK: 0} |
60 }, | 53 }, |
61 classes: | 54 classes: |
62 { | 55 { |
63 "@mozilla.org/timer;1": | 56 "@mozilla.org/timer;1": |
64 { | 57 { |
65 createInstance() | 58 createInstance() |
66 { | 59 { |
67 return new FakeTimer(); | 60 return new FakeTimer(); |
68 } | 61 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 send(data) | 306 send(data) |
314 { | 307 { |
315 if (this.readyState != 1) | 308 if (this.readyState != 1) |
316 throw new Error( | 309 throw new Error( |
317 "XMLHttpRequest.send() is being called before XMLHttpRequest.open()"); | 310 "XMLHttpRequest.send() is being called before XMLHttpRequest.open()"); |
318 if (typeof data != "undefined" && data) | 311 if (typeof data != "undefined" && data) |
319 throw new Error("Sending data to server is not supported"); | 312 throw new Error("Sending data to server is not supported"); |
320 | 313 |
321 this.readyState = 3; | 314 this.readyState = 3; |
322 | 315 |
323 let onGetDone = function(result) | 316 let onGetDone = result => |
324 { | 317 { |
325 this.channel.status = result.status; | 318 this.channel.status = result.status; |
326 this.status = result.responseStatus; | 319 this.status = result.responseStatus; |
327 this.responseText = result.responseText; | 320 this.responseText = result.responseText; |
328 this._responseHeaders = result.responseHeaders; | 321 this._responseHeaders = result.responseHeaders; |
329 this.readyState = 4; | 322 this.readyState = 4; |
330 | 323 |
331 // Notify event listeners | 324 // Notify event listeners |
332 const NS_OK = 0; | 325 const NS_OK = 0; |
333 let eventName = (this.channel.status == NS_OK ? "load" : "error"); | 326 let eventName = (this.channel.status == NS_OK ? "load" : "error"); |
334 let event = {type: eventName}; | 327 let event = {type: eventName}; |
335 | 328 |
336 if (this["on" + eventName]) | 329 if (this["on" + eventName]) |
337 this["on" + eventName].call(this, event); | 330 this["on" + eventName].call(this, event); |
338 | 331 |
339 let list = this["_" + eventName + "Handlers"]; | 332 let list = this["_" + eventName + "Handlers"]; |
340 for (let i = 0; i < list.length; i++) | 333 for (let i = 0; i < list.length; i++) |
341 list[i].call(this, event); | 334 list[i].call(this, event); |
342 }.bind(this); | 335 }; |
sergei
2017/09/18 07:59:05
Could you also turn this function into the arrow f
hub
2017/09/18 12:43:05
Done.
| |
343 // HACK (#5066): the code checking whether the connection is | 336 // HACK (#5066): the code checking whether the connection is |
344 // allowed is temporary, the actual check should be in the core | 337 // allowed is temporary, the actual check should be in the core |
345 // when we make a decision whether to update a subscription with | 338 // when we make a decision whether to update a subscription with |
346 // current connection or not, thus whether to even construct | 339 // current connection or not, thus whether to even construct |
347 // XMLHttpRequest object or not. | 340 // XMLHttpRequest object or not. |
348 _isSubscriptionDownloadAllowed(isAllowed => | 341 _isSubscriptionDownloadAllowed(isAllowed => |
349 { | 342 { |
350 if (!isAllowed) | 343 if (!isAllowed) |
351 { | 344 { |
352 onGetDone({ | 345 onGetDone({ |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 // It's a bit hacky, JsEngine interface which is used by FilterEngine does | 394 // It's a bit hacky, JsEngine interface which is used by FilterEngine does |
402 // not allow to inject an arbitrary callback, so we use triggerEvent | 395 // not allow to inject an arbitrary callback, so we use triggerEvent |
403 // mechanism. | 396 // mechanism. |
404 // Yet one hack (#5039). | 397 // Yet one hack (#5039). |
405 let allowedConnectionType = require("prefs").Prefs.allowed_connection_type; | 398 let allowedConnectionType = require("prefs").Prefs.allowed_connection_type; |
406 if (allowedConnectionType == "") | 399 if (allowedConnectionType == "") |
407 allowedConnectionType = null; | 400 allowedConnectionType = null; |
408 _triggerEvent("_isSubscriptionDownloadAllowed", allowedConnectionType, | 401 _triggerEvent("_isSubscriptionDownloadAllowed", allowedConnectionType, |
409 callback); | 402 callback); |
410 } | 403 } |
411 | |
412 // Polyfill Array.prototype.find | |
413 // from https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Ob jects/Array/find | |
414 // https://tc39.github.io/ecma262/#sec-array.prototype.find | |
415 if (!Array.prototype.find) | |
sergei
2017/09/18 07:59:05
Is it possible to remove this polyfill? We are alr
hub
2017/09/18 12:43:05
Done.
| |
416 { | |
417 Object.defineProperty(Array.prototype, "find", | |
418 { | |
419 value(predicate, ...args) | |
420 { | |
421 // 1. Let O be ? ToObject(this value). | |
422 if (this == null) | |
423 { | |
424 throw new TypeError("\"this\" is null or not defined"); | |
425 } | |
426 | |
427 let o = Object(this); | |
428 | |
429 // 2. Let len be ? ToLength(? Get(O, "length")). | |
430 let len = o.length >>> 0; | |
431 | |
432 // 3. If IsCallable(predicate) is false, throw a TypeError exception. | |
433 if (typeof predicate !== "function") | |
434 { | |
435 throw new TypeError("predicate must be a function"); | |
436 } | |
437 | |
438 // 4. If thisArg was supplied, let T be thisArg; else | |
439 // let T be undefined. | |
440 let thisArg = args[0]; | |
441 | |
442 // 5. Let k be 0. | |
443 let k = 0; | |
444 | |
445 // 6. Repeat, while k < len | |
446 while (k < len) | |
447 { | |
448 // a. Let Pk be ! ToString(k). | |
449 // b. Let kValue be ? Get(O, Pk). | |
450 // c. Let testResult be ToBoolean(? Call(predicate, T, "kValue, | |
451 // k, O")). | |
452 // d. If testResult is true, return kValue. | |
453 let kValue = o[k]; | |
454 if (predicate.call(thisArg, kValue, k, o)) | |
455 { | |
456 return kValue; | |
457 } | |
458 // e. Increase k by 1. | |
459 k++; | |
460 } | |
461 } | |
462 }); | |
463 } | |
LEFT | RIGHT |