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; |
+ } |
+ }, |
+ 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); |
Wladimir Palant
2015/12/16 13:00:25
For reference, this introduced a behavior change.
|
}; |
} |
exports.hook = hook; |