Bug 1890793: Assert CallArgs::newTarget is not gray. r=spidermonkey-reviewers,sfink...
[gecko.git] / dom / base / DocumentInlines.h
blob0d1ae615428eb019d6097201be26193cdd5c5fb1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_DocumentInlines_h
7 #define mozilla_dom_DocumentInlines_h
9 #include "mozilla/dom/Document.h"
11 #include "mozilla/PresShell.h"
12 #include "mozilla/ServoStyleSet.h"
13 #include "mozilla/dom/HTMLBodyElement.h"
14 #include "nsContentUtils.h"
15 #include "nsPresContext.h"
16 #include "nsStyleSheetService.h"
18 namespace mozilla::dom {
20 inline PresShell* Document::GetObservingPresShell() const {
21 return mPresShell && mPresShell->IsObservingDocument() ? mPresShell : nullptr;
24 inline nsPresContext* Document::GetPresContext() const {
25 PresShell* presShell = GetPresShell();
26 return presShell ? presShell->GetPresContext() : nullptr;
29 inline HTMLBodyElement* Document::GetBodyElement() {
30 return static_cast<HTMLBodyElement*>(GetHtmlChildElement(nsGkAtoms::body));
33 inline void Document::SetServoRestyleRoot(nsINode* aRoot, uint32_t aDirtyBits) {
34 MOZ_ASSERT(aRoot);
36 MOZ_ASSERT(!mServoRestyleRoot || mServoRestyleRoot == aRoot ||
37 nsContentUtils::ContentIsFlattenedTreeDescendantOfForStyle(
38 mServoRestyleRoot, aRoot));
39 MOZ_ASSERT(aRoot == aRoot->OwnerDocAsNode() || aRoot->IsElement());
40 mServoRestyleRoot = aRoot;
41 SetServoRestyleRootDirtyBits(aDirtyBits);
44 // Note: we break this out of SetServoRestyleRoot so that callers can add
45 // bits without doing a no-op assignment to the restyle root, which would
46 // involve cycle-collected refcount traffic.
47 inline void Document::SetServoRestyleRootDirtyBits(uint32_t aDirtyBits) {
48 MOZ_ASSERT(aDirtyBits);
49 MOZ_ASSERT((aDirtyBits & ~Element::kAllServoDescendantBits) == 0);
50 MOZ_ASSERT((aDirtyBits & mServoRestyleRootDirtyBits) ==
51 mServoRestyleRootDirtyBits);
52 MOZ_ASSERT(mServoRestyleRoot);
53 mServoRestyleRootDirtyBits = aDirtyBits;
56 inline ServoStyleSet& Document::EnsureStyleSet() const {
57 MOZ_ASSERT(NS_IsMainThread());
58 if (!mStyleSet) {
59 Document* doc = const_cast<Document*>(this);
60 doc->mStyleSet = MakeUnique<ServoStyleSet>(*doc);
62 return *(mStyleSet.get());
65 } // namespace mozilla::dom
67 #endif // mozilla_dom_DocumentInlines_h