nsresult IDBRequest::NotifyHelperCompleted(HelperBase* aHelper) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(!mHaveResultOrErrorCode, "Already called!"); 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)) { SetError(rv); return NS_OK; } // Otherwise we need to get the result from the helper. JSContext* cx = GetJSContext(); if (!cx) { NS_WARNING("Failed to get safe JSContext!"); rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; SetError(rv); return rv; } JSObject* global = GetParentObject(); NS_ASSERTION(global, "This should never be null!"); JSAutoRequest ar(cx); JSAutoEnterCompartment ac; if (ac.enter(cx, global)) { AssertIsRooted(); rv = aHelper->GetSuccessResult(cx, &mResultVal); if (NS_FAILED(rv)) { NS_WARNING("GetSuccessResult failed!"); } } else { NS_WARNING("Failed to enter correct compartment!"); rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } if (NS_SUCCEEDED(rv)) { mError = nullptr; } else { SetError(rv); mResultVal = JSVAL_VOID; } return rv; }
void IDBRequest::SetResultCallback(ResultCallback* aCallback) { AssertIsOnOwningThread(); MOZ_ASSERT(aCallback); MOZ_ASSERT(!mHaveResultOrErrorCode); MOZ_ASSERT(mResultVal.isUndefined()); MOZ_ASSERT(!mError); // See if our window is still valid. if (NS_WARN_IF(NS_FAILED(CheckInnerWindowCorrectness()))) { SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); return; } AutoJSAPI autoJS; Maybe<JSAutoCompartment> ac; if (GetScriptOwner()) { // If we have a script owner we want the SafeJSContext and then to enter the // script owner's compartment. autoJS.Init(); JS::ExposeObjectToActiveJS(GetScriptOwner()); ac.emplace(autoJS.cx(), GetScriptOwner()); } else { // Otherwise our owner is a window and we use that to initialize. MOZ_ASSERT(GetOwner()); if (!autoJS.Init(GetOwner())) { IDB_WARNING("Failed to initialize AutoJSAPI!"); SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); return; } } JSContext* cx = autoJS.cx(); AssertIsRooted(); JS::Rooted<JS::Value> result(cx); nsresult rv = aCallback->GetResult(cx, &result); if (NS_WARN_IF(NS_FAILED(rv))) { // This can only fail if the structured clone contains a mutable file // and the child is not in the main thread and main process. // In that case CreateAndWrapMutableFile() returns false which shows up // as NS_ERROR_DOM_DATA_CLONE_ERR here. MOZ_ASSERT(rv == NS_ERROR_DOM_DATA_CLONE_ERR); // We are not setting a result or an error object here since we want to // throw an exception when the 'result' property is being touched. return; } mError = nullptr; mResultVal = result; mHaveResultOrErrorCode = true; }
void IDBRequest::SetResultCallback(ResultCallback* aCallback) { AssertIsOnOwningThread(); MOZ_ASSERT(aCallback); MOZ_ASSERT(!mHaveResultOrErrorCode); MOZ_ASSERT(mResultVal.isUndefined()); MOZ_ASSERT(!mError); // See if our window is still valid. if (NS_WARN_IF(NS_FAILED(CheckInnerWindowCorrectness()))) { IDB_REPORT_INTERNAL_ERR(); SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); return; } AutoJSAPI autoJS; Maybe<JSAutoCompartment> ac; if (GetScriptOwner()) { // If we have a script owner we want the SafeJSContext and then to enter the // script owner's compartment. autoJS.Init(); ac.emplace(autoJS.cx(), GetScriptOwner()); } else { // Otherwise our owner is a window and we use that to initialize. MOZ_ASSERT(GetOwner()); if (!autoJS.InitWithLegacyErrorReporting(GetOwner())) { IDB_WARNING("Failed to initialize AutoJSAPI!"); SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); return; } } JSContext* cx = autoJS.cx(); AssertIsRooted(); JS::Rooted<JS::Value> result(cx); nsresult rv = aCallback->GetResult(cx, &result); if (NS_WARN_IF(NS_FAILED(rv))) { SetError(rv); mResultVal.setUndefined(); } else { mError = nullptr; mResultVal = result; } mHaveResultOrErrorCode = true; }