Skip to content

Commit

Permalink
Bug 1673931 - Remove dependency of BindingUtils.h on Document.h.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D95048

Depends on D95047
  • Loading branch information
sigiesec committed Nov 23, 2020
1 parent bce0f7a commit 6fac745
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13076,7 +13076,7 @@ nsDocShell::IssueWarning(uint32_t aWarning, bool aAsError) {
if (mContentViewer) {
RefPtr<Document> doc = mContentViewer->GetDocument();
if (doc) {
doc->WarnOnceAbout(Document::DeprecatedOperations(aWarning), aAsError);
doc->WarnOnceAbout(DeprecatedOperations(aWarning), aAsError);
}
}
return NS_OK;
Expand Down
25 changes: 14 additions & 11 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6127,9 +6127,13 @@ void Document::SetFgColor(const nsAString& aFgColor) {
}
}

void Document::CaptureEvents() { WarnOnceAbout(Document::eUseOfCaptureEvents); }
void Document::CaptureEvents() {
WarnOnceAbout(DeprecatedOperations::eUseOfCaptureEvents);
}

void Document::ReleaseEvents() { WarnOnceAbout(Document::eUseOfReleaseEvents); }
void Document::ReleaseEvents() {
WarnOnceAbout(DeprecatedOperations::eUseOfReleaseEvents);
}

HTMLAllCollection* Document::All() {
if (!mAll) {
Expand Down Expand Up @@ -12724,11 +12728,10 @@ static const char* kDocumentWarnings[] = {
nullptr};
#undef DOCUMENT_WARNING

static UseCounter OperationToUseCounter(
Document::DeprecatedOperations aOperation) {
static UseCounter OperationToUseCounter(DeprecatedOperations aOperation) {
switch (aOperation) {
#define DEPRECATED_OPERATION(_op) \
case Document::e##_op: \
#define DEPRECATED_OPERATION(_op) \
case DeprecatedOperations::e##_op: \
return eUseCounter_##_op;
#include "nsDeprecatedOperationList.h"
#undef DEPRECATED_OPERATION
Expand All @@ -12738,7 +12741,7 @@ static UseCounter OperationToUseCounter(
}

bool Document::HasWarnedAbout(DeprecatedOperations aOperation) const {
return mDeprecationWarnedAbout[aOperation];
return mDeprecationWarnedAbout[static_cast<size_t>(aOperation)];
}

void Document::WarnOnceAbout(
Expand All @@ -12748,7 +12751,7 @@ void Document::WarnOnceAbout(
if (HasWarnedAbout(aOperation)) {
return;
}
mDeprecationWarnedAbout[aOperation] = true;
mDeprecationWarnedAbout[static_cast<size_t>(aOperation)] = true;
// Don't count deprecated operations for about pages since those pages
// are almost in our control, and we always need to remove uses there
// before we remove the operation itself anyway.
Expand All @@ -12758,9 +12761,9 @@ void Document::WarnOnceAbout(
}
uint32_t flags =
asError ? nsIScriptError::errorFlag : nsIScriptError::warningFlag;
nsContentUtils::ReportToConsole(flags, "DOM Core"_ns, this,
nsContentUtils::eDOM_PROPERTIES,
kDeprecationWarnings[aOperation], aParams);
nsContentUtils::ReportToConsole(
flags, "DOM Core"_ns, this, nsContentUtils::eDOM_PROPERTIES,
kDeprecationWarnings[static_cast<size_t>(aOperation)], aParams);
}

bool Document::HasWarnedAbout(DocumentWarnings aWarning) const {
Expand Down
17 changes: 10 additions & 7 deletions dom/base/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ class ResizeObserver;
class ResizeObserverController;
class PostMessageEvent;

#define DEPRECATED_OPERATION(_op) e##_op,
enum class DeprecatedOperations : uint16_t {
#include "nsDeprecatedOperationList.h"
eDeprecatedOperationCount
};
#undef DEPRECATED_OPERATION

// Document states

// RTL locale: specific to the XUL localedir attribute
Expand Down Expand Up @@ -3205,12 +3212,6 @@ class Document : public nsINode,
// Update state on links in mLinksToUpdate.
void FlushPendingLinkUpdates();

#define DEPRECATED_OPERATION(_op) e##_op,
enum DeprecatedOperations {
#include "nsDeprecatedOperationList.h"
eDeprecatedOperationCount
};
#undef DEPRECATED_OPERATION
bool HasWarnedAbout(DeprecatedOperations aOperation) const;
void WarnOnceAbout(
DeprecatedOperations aOperation, bool asError = false,
Expand Down Expand Up @@ -4230,7 +4231,9 @@ class Document : public nsINode,
InternalCommandDataHashtable;
static InternalCommandDataHashtable* sInternalCommandDataHashtable;

mutable std::bitset<eDeprecatedOperationCount> mDeprecationWarnedAbout;
mutable std::bitset<static_cast<size_t>(
DeprecatedOperations::eDeprecatedOperationCount)>
mDeprecationWarnedAbout;
mutable std::bitset<eDocumentWarningCount> mDocWarningWarnedAbout;

// Lazy-initialization to have mDocGroup initialized in prior to the
Expand Down
2 changes: 1 addition & 1 deletion dom/base/NodeIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ already_AddRefed<nsINode> NodeIterator::NextOrPrevNode(

void NodeIterator::Detach() {
if (mRoot) {
mRoot->OwnerDoc()->WarnOnceAbout(Document::eNodeIteratorDetach);
mRoot->OwnerDoc()->WarnOnceAbout(DeprecatedOperations::eNodeIteratorDetach);
}
}

Expand Down
9 changes: 5 additions & 4 deletions dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2891,7 +2891,7 @@ bool nsGlobalWindowInner::ResolveComponentsShim(
// Warn once.
nsCOMPtr<Document> doc = GetExtantDoc();
if (doc) {
doc->WarnOnceAbout(Document::eComponents, /* asError = */ true);
doc->WarnOnceAbout(DeprecatedOperations::eComponents, /* asError = */ true);
}

// Create a fake Components object.
Expand Down Expand Up @@ -2993,7 +2993,8 @@ bool nsGlobalWindowInner::DoResolve(
!xpc::IsXrayWrapper(aObj) &&
!nsContentUtils::ObjectPrincipal(aObj)->IsSystemPrincipal()) {
if (GetExtantDoc()) {
GetExtantDoc()->WarnOnceAbout(Document::eWindow_Cc_ontrollers);
GetExtantDoc()->WarnOnceAbout(
DeprecatedOperations::eWindow_Cc_ontrollers);
}
const JSClass* clazz;
if (aId ==
Expand Down Expand Up @@ -3877,13 +3878,13 @@ void nsGlobalWindowInner::SetResizable(bool aResizable) const {

void nsGlobalWindowInner::CaptureEvents() {
if (mDoc) {
mDoc->WarnOnceAbout(Document::eUseOfCaptureEvents);
mDoc->WarnOnceAbout(DeprecatedOperations::eUseOfCaptureEvents);
}
}

void nsGlobalWindowInner::ReleaseEvents() {
if (mDoc) {
mDoc->WarnOnceAbout(Document::eUseOfReleaseEvents);
mDoc->WarnOnceAbout(DeprecatedOperations::eUseOfReleaseEvents);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3345,7 +3345,7 @@ already_AddRefed<nsPIDOMWindowOuter> nsGlobalWindowOuter::GetContentInternal(
nsCOMPtr<nsIDocShellTreeItem> primaryContent;
if (aCallerType != CallerType::System) {
if (mDoc) {
mDoc->WarnOnceAbout(Document::eWindowContentUntrusted);
mDoc->WarnOnceAbout(DeprecatedOperations::eWindowContentUntrusted);
}
// If we're called by non-chrome code, make sure we don't return
// the primary content window if the calling tab is hidden. In
Expand Down
20 changes: 10 additions & 10 deletions dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2499,7 +2499,7 @@ bool ReportLenientThisUnwrappingFailure(JSContext* cx, JSObject* obj) {
nsCOMPtr<nsPIDOMWindowInner> window =
do_QueryInterface(global.GetAsSupports());
if (window && window->GetDoc()) {
window->GetDoc()->WarnOnceAbout(Document::eLenientThis);
window->GetDoc()->WarnOnceAbout(DeprecatedOperations::eLenientThis);
}
return true;
}
Expand Down Expand Up @@ -4017,7 +4017,7 @@ class GetLocalizedStringRunnable final : public WorkerMainThreadRunnable {
};

void ReportDeprecation(nsIGlobalObject* aGlobal, nsIURI* aURI,
Document::DeprecatedOperations aOperation,
DeprecatedOperations aOperation,
const nsAString& aFileName,
const Nullable<uint32_t>& aLineNumber,
const Nullable<uint32_t>& aColumnNumber) {
Expand All @@ -4034,10 +4034,10 @@ void ReportDeprecation(nsIGlobalObject* aGlobal, nsIURI* aURI,
}

nsAutoString type;
type.AssignASCII(kDeprecatedOperations[aOperation]);
type.AssignASCII(kDeprecatedOperations[static_cast<size_t>(aOperation)]);

nsAutoCString key;
key.AssignASCII(kDeprecatedOperations[aOperation]);
key.AssignASCII(kDeprecatedOperations[static_cast<size_t>(aOperation)]);
key.AppendASCII("Warning");

nsAutoString msg;
Expand Down Expand Up @@ -4082,10 +4082,10 @@ void ReportDeprecation(nsIGlobalObject* aGlobal, nsIURI* aURI,
// console running on the main-thread.
class DeprecationWarningRunnable final
: public WorkerProxyToMainThreadRunnable {
const Document::DeprecatedOperations mOperation;
const DeprecatedOperations mOperation;

public:
explicit DeprecationWarningRunnable(Document::DeprecatedOperations aOperation)
explicit DeprecationWarningRunnable(DeprecatedOperations aOperation)
: mOperation(aOperation) {}

private:
Expand All @@ -4110,7 +4110,7 @@ class DeprecationWarningRunnable final
};

void MaybeShowDeprecationWarning(const GlobalObject& aGlobal,
Document::DeprecatedOperations aOperation) {
DeprecatedOperations aOperation) {
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindowInner> window =
do_QueryInterface(aGlobal.GetAsSupports());
Expand All @@ -4131,7 +4131,7 @@ void MaybeShowDeprecationWarning(const GlobalObject& aGlobal,
}

void MaybeReportDeprecation(const GlobalObject& aGlobal,
Document::DeprecatedOperations aOperation) {
DeprecatedOperations aOperation) {
nsCOMPtr<nsIURI> uri;

if (NS_IsMainThread()) {
Expand Down Expand Up @@ -4177,7 +4177,7 @@ void MaybeReportDeprecation(const GlobalObject& aGlobal,
} // anonymous namespace

void DeprecationWarning(JSContext* aCx, JSObject* aObject,
Document::DeprecatedOperations aOperation) {
DeprecatedOperations aOperation) {
GlobalObject global(aCx, aObject);
if (global.Failed()) {
NS_ERROR("Could not create global for DeprecationWarning");
Expand All @@ -4188,7 +4188,7 @@ void DeprecationWarning(JSContext* aCx, JSObject* aObject,
}

void DeprecationWarning(const GlobalObject& aGlobal,
Document::DeprecatedOperations aOperation) {
DeprecatedOperations aOperation) {
MaybeShowDeprecationWarning(aGlobal, aOperation);
MaybeReportDeprecation(aGlobal, aOperation);
}
Expand Down
13 changes: 10 additions & 3 deletions dom/bindings/BindingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/Likely.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Document.h"
#include "nsIGlobalObject.h"
#include "nsJSUtils.h"
#include "nsISupportsImpl.h"
Expand All @@ -53,19 +52,27 @@
#include "mozilla/BasePrincipal.h"
#include "nsJSPrincipals.h"

class nsGlobalWindowInner;
class nsGlobalWindowOuter;
class nsIInterfaceRequestor;

namespace mozilla {

enum UseCounter : int16_t;
enum class UseCounterWorker : int16_t;

namespace dom {
class CustomElementReactionsStack;
class Document;
class EventTarget;
class MessageManagerGlobal;
class DedicatedWorkerGlobalScope;
template <typename KeyType, typename ValueType>
class Record;
class WindowProxyHolder;

enum class DeprecatedOperations : uint16_t;

nsresult UnwrapArgImpl(JSContext* cx, JS::Handle<JSObject*> src,
const nsIID& iid, void** ppArg);

Expand Down Expand Up @@ -3097,10 +3104,10 @@ void SetUseCounter(UseCounterWorker aUseCounter);

// Warnings
void DeprecationWarning(JSContext* aCx, JSObject* aObject,
Document::DeprecatedOperations aOperation);
DeprecatedOperations aOperation);

void DeprecationWarning(const GlobalObject& aGlobal,
Document::DeprecatedOperations aOperation);
DeprecatedOperations aOperation);

// A callback to perform funToString on an interface object
JSString* InterfaceObjectToString(JSContext* aCx, JS::Handle<JSObject*> aObject,
Expand Down
4 changes: 2 additions & 2 deletions dom/bindings/Codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9191,7 +9191,7 @@ def __init__(
CGGeneric(
dedent(
"""
DeprecationWarning(cx, obj, Document::e%s);
DeprecationWarning(cx, obj, DeprecatedOperations::e%s);
"""
% deprecated[0]
)
Expand Down Expand Up @@ -11483,7 +11483,7 @@ def definition_body(self):
assert all(ord(c) < 128 for c in attrName)
return dedent(
"""
DeprecationWarning(cx, obj, Document::eLenientSetter);
DeprecationWarning(cx, obj, DeprecatedOperations::eLenientSetter);
return true;
"""
)
Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/ImageBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ already_AddRefed<ImageBitmap> ImageBitmap::CreateInternal(
}

window->GetExtantDoc()->WarnOnceAbout(
Document::eCreateImageBitmapCanvasRenderingContext2D);
DeprecatedOperations::eCreateImageBitmapCanvasRenderingContext2D);

// Check write-only mode.
bool writeOnly =
Expand Down
2 changes: 1 addition & 1 deletion dom/events/EventListenerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void EventListenerManager::AddEventListenerInternal(
if (doc &&
!(aFlags.mInSystemGroup &&
doc->DontWarnAboutMutationEventsAndAllowSlowDOMMutations())) {
doc->WarnOnceAbout(Document::eMutationEvent);
doc->WarnOnceAbout(DeprecatedOperations::eMutationEvent);
}
// If aEventMessage is eLegacySubtreeModified, we need to listen all
// mutations. nsContentUtils::HasMutationListeners relies on this.
Expand Down
2 changes: 1 addition & 1 deletion dom/indexedDB/IDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ RefPtr<IDBOpenDBRequest> IDBFactory::Open(JSContext* aCx,
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
if (window && window->GetExtantDoc()) {
window->GetExtantDoc()->WarnOnceAbout(
Document::eIDBOpenDBOptions_StorageType);
DeprecatedOperations::eIDBOpenDBOptions_StorageType);
} else if (!NS_IsMainThread()) {
// The method below reports on the main thread too, so we need to make
// sure we're on a worker. Workers don't have a WarnOnceAbout mechanism,
Expand Down
Loading

0 comments on commit 6fac745

Please sign in to comment.