 Issue 8433028:
  added hook function to appIntegration to handle function-overwrites from other extensions  (Closed)
    
  
    Issue 8433028:
  added hook function to appIntegration to handle function-overwrites from other extensions  (Closed) 
  | Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
| 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| 4 | |
| 5 function hook(obj, name, func) | |
| 6 { | |
| 7 let orig = obj[name]; | |
| 8 let origGet = obj.__lookupGetter__(name); | |
| 9 let origSet = obj.__lookupSetter__(name); | |
| 10 let dumbOverrideAttempt = false; | |
| 11 | |
| 12 let newFunc = function() | |
| 13 { | |
| 14 try | |
| 15 { | |
| 16 func.apply(this, arguments); | |
| 17 } | |
| 18 catch(e) | |
| 19 { | |
| 20 Cu.reportError(e); | |
| 21 } | |
| 22 orig.apply(this, arguments); | |
| 
Wladimir Palant
2012/09/27 14:36:01
This should be: return orig.apply(...)
We don't wa
 | |
| 23 }; | |
| 24 newFunc.toString = function() | |
| 25 { | |
| 26 dumbOverrideAttempt = true; | |
| 27 return orig.toString(); | |
| 28 }; | |
| 29 | |
| 30 obj.__defineGetter__(name, function() { | |
| 
Wladimir Palant
2012/09/27 14:36:01
This bracket should be on next line.
 | |
| 31 dumbOverrideAttempt = false; | |
| 32 return newFunc; | |
| 33 }); | |
| 34 | |
| 35 obj.__defineSetter__(name, function(value) { | |
| 
Wladimir Palant
2012/09/27 14:36:01
This bracket should be on next line.
 | |
| 36 if (dumbOverrideAttempt) | |
| 37 { | |
| 38 orig = value; | |
| 39 } | |
| 40 else | |
| 41 { | |
| 42 delete obj[name]; | |
| 43 obj[name] = value; | |
| 44 } | |
| 45 }); | |
| 46 | |
| 47 return function() | |
| 48 { | |
| 49 delete obj[name]; | |
| 50 obj[name] = orig; | |
| 51 if (origGet) | |
| 52 { | |
| 53 obj.__defineGetter__(name, origGet); | |
| 54 } | |
| 55 if (origSet) | |
| 56 { | |
| 57 obj.__defineSetter__(name, origSet); | |
| 58 } | |
| 59 }; | |
| 60 } | |
| 61 exports.hook = hook; | |
| OLD | NEW |