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

Side by Side Diff: lib/content/snippets.js

Issue 29886700: Issue 6969 - Implement abort-on-property-read snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 20, 2018, 10:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // We don't have the location of the element in its former parent, 406 // We don't have the location of the element in its former parent,
407 // but it's usually OK to just add it at the end. 407 // but it's usually OK to just add it at the end.
408 mutation.target.appendChild(node); 408 mutation.target.appendChild(node);
409 } 409 }
410 } 410 }
411 } 411 }
412 }); 412 });
413 } 413 }
414 414
415 exports.readd = readd; 415 exports.readd = readd;
416
417 function randomId()
418 {
419 // 2176782336 is 36^6 which mean 6 chars [a-z0-9]
420 return Math.floor(Math.random() * 2176782336).toString(36);
421 }
422
423 /**
424 * Will patch a property on the window object to abort when read.
425 * It will intercept the onerror callback and block it if tagged.
426 *
427 * @todo handle properties of properties.
428 *
429 * @param {string} the name of the property
430 */
431 function abortOnPropertyRead(prop)
432 {
433 if (!prop)
434 return;
435
436 let magic = randomId();
437
438 let abort = function() {
439 throw new ReferenceError(magic);
440 };
441
442 let onerror = window.onerror;
443 window.onerror = (msg, ...args) =>
444 {
445 if (typeof msg === "string" && msg.indexOf(magic) != -1)
446 return true;
447 if (onerror)
448 return onerror(msg, ...args);
449 };
450
451 // patching function
452 (function (o, p) {
453 // simple property
454 let d = Object.getOwnPropertyDescriptor(o, p);
455 if (!d || d.get !== abort) {
456 Object.defineProperty(o, p, { get: abort, set: () => {}});
457 }
458 })(window, prop);
459 }
460
461 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, randomId);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld