I was getting interest in looking for 'WHERE document() comes from?'.
'Chromium' is quite big and complicated open-source project, so even traversing source code for looking 'where it comes from' also hard. However, it was statred from HTMLMediaElement class(chromium/src/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp). And, finally real implementaion of document() belongs to a class TreeScope(third_party/WebKit/Source/core/dom/TreeScope.h).
The inheritance seems like below, shortly. HTMLMediaElement - HTMLElement - Element - ContainerNode - Node and, Node has TreeScope and it has 'Document& document() const'.
I hope, someone (including me) needs this quick information.