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

Delta Between Two Patch Sets: lib/content/snippets.js

Issue 29886700: Issue 6969 - Implement abort-on-property-read snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rework wrapPropertyAccess Created Oct. 31, 2018, 4:35 p.m.
Right Patch Set: Another round of changes Created Oct. 31, 2018, 8:43 p.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 | « no previous file | no next file » | 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-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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (currentDescriptor && !currentDescriptor.configurable) 514 if (currentDescriptor && !currentDescriptor.configurable)
515 return false; 515 return false;
516 516
517 Object.defineProperty(object, property, descriptor); 517 Object.defineProperty(object, property, descriptor);
518 return true; 518 return true;
519 } 519 }
520 520
521 /** 521 /**
522 * Patches a property on the window object to abort execution when the 522 * Patches a property on the window object to abort execution when the
523 * property is read. 523 * property is read.
524 * No error will be printed in the console. 524 *
Manish Jethani 2018/10/31 19:54:49 Nit: Again, is the "No error will be printed" part
Manish Jethani 2018/10/31 19:54:49 Nit: Even though it doesn't matter to the generate
hub 2018/10/31 20:44:16 Done.
hub 2018/10/31 20:44:17 Done.
525 * No error is be printed to the console.
526 *
525 * The idea originates from 527 * The idea originates from
Manish Jethani 2018/10/31 19:54:49 Nit: Period at the end of the sentence.
hub 2018/10/31 20:44:16 Done.
526 * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237b fc268ecfc9d9d2b/filters/resources.txt#L1703 uBlock Origin} 528 * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237b fc268ecfc9d9d2b/filters/resources.txt#L1703 uBlock Origin}.
527 * 529 *
528 * @param {string} property The name of the property. 530 * @param {string} property The name of the property.
529 */ 531 */
530 function abortOnPropertyRead(property) 532 function abortOnPropertyRead(property)
531 { 533 {
532 if (!property) 534 if (!property)
533 return; 535 return;
534 536
535 let rid = randomId(); 537 let rid = randomId();
536 538
537 function abort() 539 function abort()
538 { 540 {
539 throw new ReferenceError(rid); 541 throw new ReferenceError(rid);
540 } 542 }
541 543
544 let {onerror} = window;
542 if (wrapPropertyAccess(window, property, {get: abort, set() {}})) 545 if (wrapPropertyAccess(window, property, {get: abort, set() {}}))
543 { 546 {
544 let {onerror} = window;
Manish Jethani 2018/10/31 19:38:16 Can we move this line outside the if block? In the
hub 2018/10/31 20:44:16 It can be moved. But it would still bomb if it wa
Manish Jethani 2018/10/31 20:52:22 Alright, fair enough.
545 window.onerror = (message, ...rest) => 547 window.onerror = (message, ...rest) =>
546 { 548 {
547 if (typeof message == "string" && message.includes(rid)) 549 if (typeof message == "string" && message.includes(rid))
548 return true; 550 return true;
549 if (typeof onerror == "function") 551 if (typeof onerror == "function")
550 return (() => {}).call.call(onerror, this, message, ...rest); 552 return (() => {}).call.call(onerror, this, message, ...rest);
551 }; 553 };
552 } 554 }
553 } 555 }
554 556
555 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, 557 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead,
556 wrapPropertyAccess, 558 wrapPropertyAccess,
557 randomId); 559 randomId);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld