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: eslint fixes Created Sept. 20, 2018, 10:26 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} prop 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 {
440 throw new ReferenceError(magic);
441 };
442
443 let {onerror} = window.onerror;
444 window.onerror = (msg, ...args) =>
445 {
446 if (typeof msg === "string" && msg.indexOf(magic) != -1)
447 return true;
448 if (onerror)
449 return onerror(msg, ...args);
450 };
451
452 // patching function
453 (function(o, p)
454 {
455 // simple property
456 let d = Object.getOwnPropertyDescriptor(o, p);
457 if (!d || d.get !== abort)
458 Object.defineProperty(o, p, {get: abort, set() {}});
459 })(window, prop);
460 }
461
462 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