Fix segfault caused by document wrapper being GCed.