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

Unified Diff: lib/hooks.js

Issue 5462707926990848: Issue 1434 - Removed remaining non-standard JavaScript code from buildtools (Closed)
Patch Set: Rebased Created May 6, 2015, 11 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bootstrap.js.tmpl ('k') | lib/keySelector.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
};
}
exports.hook = hook;
« no previous file with comments | « bootstrap.js.tmpl ('k') | lib/keySelector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld