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; }
JSContext* IDBRequest::GetJSContext() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); JSContext* cx; if (GetScriptOwner()) { nsIThreadJSContextStack* cxStack = nsContentUtils::ThreadJSContextStack(); NS_ASSERTION(cxStack, "Failed to get thread context stack!"); cx = cxStack->GetSafeJSContext(); NS_ENSURE_TRUE(cx, nullptr); return cx; } nsresult rv; nsIScriptContext* sc = GetContextForEventHandlers(&rv); NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_TRUE(sc, nullptr); cx = sc->GetNativeContext(); NS_ASSERTION(cx, "Failed to get a context!"); return cx; }