void ServiceWorkerJob::Finish(ErrorResult& aRv) { AssertIsOnMainThread(); MOZ_ASSERT(mState == State::Started); // Ensure that we only surface SecurityErr, TypeErr or InvalidStateErr to script. if (aRv.Failed() && !aRv.ErrorCodeIs(NS_ERROR_DOM_SECURITY_ERR) && !aRv.ErrorCodeIs(NS_ERROR_DOM_TYPE_ERR) && !aRv.ErrorCodeIs(NS_ERROR_DOM_INVALID_STATE_ERR)) { // Remove the old error code so we can replace it with a TypeError. aRv.SuppressException(); NS_ConvertUTF8toUTF16 scriptSpec(mScriptSpec); NS_ConvertUTF8toUTF16 scope(mScope); // Throw the type error with a generic error message. aRv.ThrowTypeError<MSG_SW_INSTALL_ERROR>(scriptSpec, scope); } // The final callback may drop the last ref to this object. RefPtr<ServiceWorkerJob> kungFuDeathGrip = this; if (!mResultCallbacksInvoked) { InvokeResultCallbacks(aRv); } mState = State::Finished; mFinalCallback->JobFinished(this, aRv); mFinalCallback = nullptr; // The callback might not consume the error. aRv.SuppressException(); // Async release this object to ensure that our caller methods complete // as well. NS_ReleaseOnMainThread(kungFuDeathGrip.forget(), true /* always proxy */); }
already_AddRefed<Promise> TelephonyCall::Resume(ErrorResult& aRv) { nsRefPtr<Promise> promise = CreatePromise(aRv); if (!promise) { return nullptr; } nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise); aRv = Resume(callback); if (NS_WARN_IF(aRv.Failed() && !aRv.ErrorCodeIs(NS_ERROR_DOM_INVALID_STATE_ERR))) { return nullptr; } return promise.forget(); }
already_AddRefed<Promise> TelephonyCallGroup::Hold(ErrorResult& aRv) { MOZ_ASSERT(!mCalls.IsEmpty()); RefPtr<Promise> promise = CreatePromise(aRv); if (!promise) { return nullptr; } nsCOMPtr<nsITelephonyCallback> callback = new TelephonyCallback(promise); aRv = Hold(callback); if (NS_WARN_IF(aRv.Failed() && !aRv.ErrorCodeIs(NS_ERROR_DOM_INVALID_STATE_ERR))) { return nullptr; } return promise.forget(); }
void ServoStyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv) { // Ensure mRuleList is constructed. GetCssRulesInternal(aRv); if (aIndex > mRuleList->Length()) { aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return; } mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true); // Hold a strong ref to the rule so it doesn't die when we remove it // from the list. XXX We may not want to hold it if stylesheet change // event is not enabled. RefPtr<css::Rule> rule = mRuleList->GetRule(aIndex); aRv = mRuleList->DeleteRule(aIndex); MOZ_ASSERT(!aRv.ErrorCodeIs(NS_ERROR_DOM_INDEX_SIZE_ERR), "IndexSizeError should have been handled earlier"); if (!aRv.Failed() && mDocument) { mDocument->StyleRuleRemoved(this, rule); } }