window.document is an accessor property where the getter almost always returns the same value:
if you do something like this:
var w = window.open(location.href);
var d = window.document;
setTimeout(function() { alert(w.document === d)}, 1000);
it should alert false: during the navigation in the new window, the initial document was replaced with the actual document for the new page. However, since from that point on, window.document will always return the same wrapper, and window.document is accessed a lot, we replace the getter with the actual result here: https://cs.chromium.org/chromium/src/third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp?rcl=0&l=414
That way, the optimizing compiler will treat document as a constant and avoid looking it up multiple times (and the fact that it's a value also avoids the call to the getter).
This breaks however both the ecmascript spec and the html spec: ecmascript doesn't allow for replacing a non-configurable, non-writable getter with something else, and html says it's supposed to be a getter not a value.
To fix this, we need to make the spec compliant way fast enough. I propose to use an compiled DOM accessor for document so the cost of the call in the baseline compiler is minimal. For TF, we need to find a way to signal that the getter will always return the same value.
Comment 1 by haraken@chromium.org
, Aug 4 2016