Implement document_from_node and window_from_node helpers.(fixes #1761)