Created
April 5, 2011 17:52
-
-
Save DavidBruant/904114 to your computer and use it in GitHub Desktop.
Default fowarding fix trap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object.{freeze|seal|preventExtensions}(proxy) -> proxy | |
fix: function() { | |
// As long as target is not frozen, the proxy won't allow itself to be fixed | |
if (!Object.isFrozen(this.target)) | |
return undefined; | |
var props = {}; | |
var handler = this; | |
Object.getOwnPropertyNames(this.target).forEach(function (name) { | |
var desc = Object.getOwnPropertyDescriptor(this.target, name); | |
// turn descriptor into a trapping accessor property | |
props[name] = { | |
get: function( ) { return handler.get(this, name); }, | |
set: function(v) { return handler.set(this, name, v); }, | |
enumerable: desc.enumerable, | |
configurable: desc.configurable | |
}; | |
}); | |
return props; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment