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; }
nsresult KeyPath::ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const { if (IsArray()) { uint32_t len = mStrings.Length(); JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, len)); if (!array) { IDB_WARNING("Failed to make array!"); return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } for (uint32_t i = 0; i < len; ++i) { JS::Rooted<JS::Value> val(aCx); nsString tmp(mStrings[i]); if (!xpc::StringToJsval(aCx, tmp, &val)) { IDB_REPORT_INTERNAL_ERR(); return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } if (!JS_SetElement(aCx, array, i, val)) { IDB_REPORT_INTERNAL_ERR(); return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } } aValue.setObject(*array); return NS_OK; } if (IsString()) { nsString tmp(mStrings[0]); if (!xpc::StringToJsval(aCx, tmp, aValue)) { IDB_REPORT_INTERNAL_ERR(); return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } return NS_OK; } aValue.setNull(); return NS_OK; }