void ServiceWorkerUpdateJob::ContinueUpdateAfterScriptEval(bool aScriptEvaluationResult) { AssertIsOnMainThread(); RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); if (Canceled() || !swm) { FailUpdateJob(NS_ERROR_DOM_ABORT_ERR); return; } // Step 7.5 of the Update algorithm verifying that the script evaluated // successfully. if (NS_WARN_IF(!aScriptEvaluationResult)) { ErrorResult error; NS_ConvertUTF8toUTF16 scriptSpec(mScriptSpec); NS_ConvertUTF8toUTF16 scope(mRegistration->mScope); error.ThrowTypeError<MSG_SW_SCRIPT_THREW>(scriptSpec, scope); FailUpdateJob(error); return; } Install(swm); }
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 */); }