Implement wrapping of document.register

This works by creating a new object hierarchy that mimics the one passed into document.register. The returned function is a wrapper function which uses the passed in prototype as its prototype.

Fixes #190