Skip to content

Instantly share code, notes, and snippets.

@rniwa
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rniwa/2d8f1a17268c7d6fb5b7 to your computer and use it in GitHub Desktop.
Save rniwa/2d8f1a17268c7d6fb5b7 to your computer and use it in GitHub Desktop.
no-layout
<!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