Last active
August 29, 2015 14:22
-
-
Save rniwa/2d8f1a17268c7d6fb5b7 to your computer and use it in GitHub Desktop.
no-layout
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> | |
<html> | |
<body> | |
<script> | |
var NoLayout = (function () { | |
var layoutGuardCount = 0; | |
function wrapMethod(name, propertyName) { | |
if (NoLayout.InProduction) | |
return; | |
var proto = window[name].prototype; | |
var descriptor = Object.getOwnPropertyDescriptor(proto, propertyName); | |
var originalGetter = descriptor.value; | |
var NoLayoutWrapper = function () { | |
if (layoutGuardCount) | |
throw new Error(name + '.prototype.' + propertyName + ' should not be called'); | |
return originalGetter.apply(this, arguments); | |
} | |
descriptor.value = NoLayoutWrapper; | |
Object.defineProperty(proto, propertyName, descriptor); | |
} | |
wrapMethod('Element', 'getClientRects'); | |
return function (callback) { | |
layoutGuardCount++; | |
callback(); | |
layoutGuardCount--; | |
} | |
})(); | |
NoLayout.InProduction = false; | |
NoLayout(function () { | |
document.body.getClientRects(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment