void IDBRequest::Reset() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); mResultVal = JSVAL_VOID; mHaveResultOrErrorCode = false; mErrorCode = 0; if (mResultValRooted) { UnrootResultVal(); } }
IDBRequest::~IDBRequest() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (mResultValRooted) { // Calling a virtual from the destructor is bad... But we know that we won't // call a subclass' implementation because mResultValRooted will be set to // false. UnrootResultVal(); } }
nsresult IDBRequest::SetDone(AsyncConnectionHelper* aHelper) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(!mHaveResultOrErrorCode, "Already called!"); NS_ASSERTION(!mResultValRooted, "Already rooted?!"); NS_ASSERTION(JSVAL_IS_VOID(mResultVal), "Should be undefined!"); // See if our window is still valid. If not then we're going to pretend that // we never completed. if (NS_FAILED(CheckInnerWindowCorrectness())) { return NS_OK; } mHaveResultOrErrorCode = true; nsresult rv = aHelper->GetResultCode(); // If the request failed then set the error code and return. if (NS_FAILED(rv)) { mErrorCode = NS_ERROR_GET_CODE(rv); return NS_OK; } // Otherwise we need to get the result from the helper. JSContext* cx = static_cast<JSContext*>(mScriptContext->GetNativeContext()); NS_ASSERTION(cx, "Failed to get a context!"); JSObject* global = static_cast<JSObject*>(mScriptContext->GetNativeGlobal()); NS_ASSERTION(global, "Failed to get global object!"); JSAutoRequest ar(cx); JSAutoEnterCompartment ac; if (!ac.enter(cx, global)) { rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } else { RootResultVal(); rv = aHelper->GetSuccessResult(cx, &mResultVal); if (NS_SUCCEEDED(rv)) { // Unroot if we don't really need to be rooted. if (!JSVAL_IS_GCTHING(mResultVal)) { UnrootResultVal(); } } else { NS_WARNING("GetSuccessResult failed!"); } } if (NS_SUCCEEDED(rv)) { mErrorCode = 0; } else { mErrorCode = NS_ERROR_GET_CODE(rv); mResultVal = JSVAL_VOID; } return rv; }