Index: lib/hooks.js |
=================================================================== |
--- a/lib/hooks.js |
+++ b/lib/hooks.js |
@@ -5,8 +5,7 @@ |
function hook(obj, name, func, cleanup) |
{ |
let orig = obj[name]; |
- let origGet = obj.__lookupGetter__(name); |
- let origSet = obj.__lookupSetter__(name); |
+ let origDesc = Object.getOwnPropertyDescriptor(obj, name); |
let dumbOverrideAttempt = false; |
let newFunc = function() |
@@ -42,39 +41,33 @@ |
{ |
dumbOverrideAttempt = true; |
return orig.toSource(); |
- } |
+ }; |
- obj.__defineGetter__(name, function() |
- { |
- dumbOverrideAttempt = false; |
- return newFunc; |
- }); |
- |
- obj.__defineSetter__(name, function(value) |
- { |
- if (dumbOverrideAttempt) |
+ Object.defineProperty(obj, name, { |
+ get: function() |
{ |
- orig = value; |
- } |
- else |
+ dumbOverrideAttempt = false; |
+ return newFunc; |
+ }, |
+ set: function(value) |
{ |
- delete obj[name]; |
- obj[name] = value; |
- } |
+ if (dumbOverrideAttempt) |
+ { |
+ orig = value; |
+ } |
+ else |
+ { |
+ delete obj[name]; |
+ obj[name] = value; |
tschuster
2015/06/17 11:01:55
I would almost use Object.defineProperty here, but
|
+ } |
+ }, |
+ enumerable: true, |
+ configurable: true |
}); |
return function() |
{ |
- delete obj[name]; |
- obj[name] = orig; |
- if (origGet) |
- { |
- obj.__defineGetter__(name, origGet); |
- } |
- if (origSet) |
- { |
- obj.__defineSetter__(name, origSet); |
- } |
+ Object.defineProperty(obj, name, origDesc); |
}; |
} |
exports.hook = hook; |