Bug 1594304. Add deprecation notes to methods that allow throwing a bare nsresult with no useful message. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 14 Nov 2019 22:51:21 +0000
changeset 502064 55c9bc5fb1fe59bb21afcde021cbb3553d17fd9e
parent 502063 4eb85afc10db43b9c64e0a19adefd78afd616418
child 502065 bba1ab697faa083c7fe335061b8ca607bd83a2c7
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1594304
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594304. Add deprecation notes to methods that allow throwing a bare nsresult with no useful message. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D53092
dom/bindings/ErrorResult.h
dom/promise/Promise.h
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -159,16 +159,21 @@ class TErrorResult {
   TErrorResult& operator=(TErrorResult&& aRHS);
 
   explicit TErrorResult(nsresult aRv) : TErrorResult() { AssignErrorCode(aRv); }
 
   operator ErrorResult&();
   operator const ErrorResult&() const;
   operator OOMReporter&();
 
+  // This method is deprecated.  Consumers should ThrowDOMException if they are
+  // throwing a DOMException.  If they have a random nsresult which may or may
+  // not correspond to a DOMException type, they should consider using an
+  // appropriate DOMException-type nsresult with an informative message and
+  // calling ThrowDOMException.
   void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG Throw(nsresult rv) {
     MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success");
     AssignErrorCode(rv);
   }
 
   // Duplicate our current state on the given TErrorResult object.  Any
   // existing errors or messages on the target will be suppressed before
   // cloning.  Our own error state remains unchanged.
@@ -363,17 +368,17 @@ class TErrorResult {
   }
 
   // In the future, we can add overloads of Throw that take more
   // interesting things, like strings or DOM exception types or
   // something if desired.
 
   // Backwards-compat to make conversion simpler.  We don't call
   // Throw() here because people can easily pass success codes to
-  // this.
+  // this.  This operator is deprecated and ideally shouldn't be used.
   void operator=(nsresult rv) { AssignErrorCode(rv); }
 
   bool Failed() const { return NS_FAILED(mResult); }
 
   bool ErrorCodeIs(nsresult rv) const { return mResult == rv; }
 
   // For use in logging ONLY.
   uint32_t ErrorCodeAsInt() const { return static_cast<uint32_t>(ErrorCode()); }
@@ -594,16 +599,17 @@ class ErrorResult : public binding_dange
 
  public:
   ErrorResult() : BaseErrorResult() {}
 
   ErrorResult(ErrorResult&& aRHS) : BaseErrorResult(std::move(aRHS)) {}
 
   explicit ErrorResult(nsresult aRv) : BaseErrorResult(aRv) {}
 
+  // This operator is deprecated and ideally shouldn't be used.
   void operator=(nsresult rv) { BaseErrorResult::operator=(rv); }
 
   ErrorResult& operator=(ErrorResult&& aRHS) {
     BaseErrorResult::operator=(std::move(aRHS));
     return *this;
   }
 
  private:
@@ -654,16 +660,17 @@ class CopyableErrorResult
     operator=(val);
   }
 
   CopyableErrorResult(CopyableErrorResult&& aRHS)
       : BaseErrorResult(std::move(aRHS)) {}
 
   explicit CopyableErrorResult(nsresult aRv) : BaseErrorResult(aRv) {}
 
+  // This operator is deprecated and ideally shouldn't be used.
   void operator=(nsresult rv) { BaseErrorResult::operator=(rv); }
 
   CopyableErrorResult& operator=(CopyableErrorResult&& aRHS) {
     BaseErrorResult::operator=(std::move(aRHS));
     return *this;
   }
 
   CopyableErrorResult(const CopyableErrorResult& aRight) : BaseErrorResult() {
--- a/dom/promise/Promise.h
+++ b/dom/promise/Promise.h
@@ -84,16 +84,23 @@ class Promise : public nsISupports, publ
     MaybeSomething(std::forward<T>(aArg), &Promise::MaybeResolve);
   }
 
   void MaybeResolveWithUndefined();
 
   void MaybeReject(JS::Handle<JS::Value> aValue) {
     MaybeSomething(aValue, &Promise::MaybeReject);
   }
+
+  // This method is deprecated.  Consumers should MaybeRejectWithDOMException if
+  // they are rejecting with a DOMException, or use one of the other
+  // MaybeReject* methods otherwise.  If they have a random nsresult which may
+  // or may not correspond to a DOMException type, they should consider using an
+  // appropriate DOMException-type nsresult with an informative message and
+  // calling MaybeRejectWithDOMException.
   inline void MaybeReject(nsresult aArg) {
     MOZ_ASSERT(NS_FAILED(aArg));
     MaybeSomething(aArg, &Promise::MaybeReject);
   }
 
   inline void MaybeReject(ErrorResult& aArg) {
     MOZ_ASSERT(aArg.Failed());
     MaybeSomething(aArg, &Promise::MaybeReject);