platform/bindings/ActiveScriptWrappable.h does actually depend on core/dom/ExecutionContext.h and this is a layering violation. ActiveScriptWrappable.h shouldn't depend on ExecutionContext.h.
The current implementation of ActiveScriptWrappable::IsContextDestroyed is as follows.
https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/bindings/ActiveScriptWrappable.h?rcl=38bca25edcd71c1cb99d4d951fc0d6783aeb8a10&l=49
----
bool IsContextDestroyed() const final {
const auto* execution_context =
static_cast<const T*>(this)->GetExecutionContext();
return !execution_context || execution_context->IsContextDestroyed();
}
----
Where this inline function implicitly requires the call sites (Foo.h or Foo.cpp) to #include "core/dom/ExecutionContext.h". This breaks the IWYU (Include What You Use) rule.
(This actually bit me when I tried to change
#include "core/dom/ExecutionContext.h"
to
class ExecutionContext; // forward decl
in MutationObserver.h where we shouldn't need the actual class definition.)
There are many options to fix this issue.
a) Move ActiveScriptWrappable class definition into core/dom/ActiveScriptWrappableAdapter.h for example. (Then, it would make sense to rename ActiveScriptWrappableBase => ActiveScriptWrappable and ActiveScriptWrappable => ActiveScriptWrappableAdapter.)
b) Remove the definition of IsContextDestroyed() from ActiveScriptWrappable.h. Let each implementation class directly implement IsContextDestroyed.
c) Move only IsContextDestroyed that needs ExecutionContext to core/dom/.
I personally prefer Option a).
Comment 1 by jbroman@chromium.org
, Jul 31 2017