Created
May 17, 2012 18:36
-
-
Save erichocean/2720807 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> | |
<html> | |
<head> | |
<title></title> | |
<script> | |
Object.defineProperty(Float32Array.prototype, 'width', { | |
get: function() { | |
return this[0]; | |
}, | |
set: function(val) { | |
this[0] = val; | |
}, | |
enumerable: false, | |
configurable: false | |
}); | |
var f = new Float32Array(1); | |
console.log('f[0] is', f[0], ', should be 0', f[0]===0? "" : "-- ERROR"); | |
console.log('f.width is', f.width, ', should be 0', f.width===0? "" : "-- ERROR"); | |
console.log('Doing: f.width = 2;') | |
f.width = 2; | |
console.log('f[0] is', f[0], ', should be 2', f[0]===2? "" : "-- ERROR"); | |
console.log('f.width is', f.width, ', should be 2', f.width===2? "" : "-- ERROR"); | |
console.log("Doing: Float32Array.prototype.__lookupSetter__('width').call(f, 2)") | |
Float32Array.prototype.__lookupSetter__('width').call(f, 2); | |
console.log('f[0] is', f[0], ', should be 2', f[0]===2? "" : "-- ERROR"); | |
console.log('f.width is', f.width, ', should be 2', f.width===2? "" : "-- ERROR"); | |
</script> | |
</head> | |
<body> | |
Check the JavaScript console output. | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output on Firefox: