зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1665347 - Do not indicate SpecialValues::Invalid could be returned on functions that never return it. r=dom-workers-and-storage-reviewers,janv
Differential Revision: https://phabricator.services.mozilla.com/D90962
This commit is contained in:
Родитель
c1f01271fa
Коммит
64635ee87f
|
@ -6355,11 +6355,7 @@ nsresult LocalizeKey(const Key& aBaseKey, const nsCString& aLocale,
|
|||
MOZ_ASSERT(aLocalizedKey);
|
||||
MOZ_ASSERT(!aLocale.IsEmpty());
|
||||
|
||||
IDB_TRY_UNWRAP(*aLocalizedKey,
|
||||
aBaseKey.ToLocaleAwareKey(aLocale).mapErr([](auto&& err) {
|
||||
return err.ExtractNSResult(
|
||||
InvalidMapsTo<NS_ERROR_DOM_INDEXEDDB_DATA_ERR>);
|
||||
}));
|
||||
IDB_TRY_UNWRAP(*aLocalizedKey, aBaseKey.ToLocaleAwareKey(aLocale));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -17313,14 +17309,8 @@ nsresult OpenDatabaseOp::UpdateLocaleAwareIndex(
|
|||
IDB_TRY(oldKey.SetFromStatement(&readStmt, 0));
|
||||
IDB_TRY(oldKey.BindToStatement(writeStmt, kStmtParamNameValue));
|
||||
|
||||
auto result = oldKey.ToLocaleAwareKey(aLocale);
|
||||
if (result.isErr()) {
|
||||
return Err(
|
||||
NS_WARN_IF(result.inspectErr().Is(SpecialValues::Exception))
|
||||
? result.unwrapErr().AsException().StealNSResult()
|
||||
: NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
||||
}
|
||||
const auto newSortKey = result.unwrap();
|
||||
IDB_TRY_INSPECT(const auto& newSortKey,
|
||||
oldKey.ToLocaleAwareKey(aLocale));
|
||||
|
||||
IDB_TRY(
|
||||
newSortKey.BindToStatement(writeStmt, kStmtParamNameValueLocale));
|
||||
|
@ -22016,16 +22006,9 @@ void Cursor<CursorType>::SetOptionalKeyRange(
|
|||
(range.isOnly() || lowerBound) ? range.lower() : range.upper();
|
||||
if constexpr (IsIndexCursor) {
|
||||
if (this->IsLocaleAware()) {
|
||||
auto res = bound.ToLocaleAwareKey(this->mLocale);
|
||||
|
||||
// XXX Explain why an error or Invalid result is ignored here (If it's
|
||||
// impossible, then
|
||||
// we should change this to an assertion.)
|
||||
if (res.isErr() && res.inspectErr().Is(SpecialValues::Exception)) {
|
||||
res.unwrapErr().AsException().SuppressException();
|
||||
}
|
||||
|
||||
localeAwareRangeBound = res.unwrap();
|
||||
// XXX Don't we need to propagate the error?
|
||||
IDB_TRY_UNWRAP(localeAwareRangeBound,
|
||||
bound.ToLocaleAwareKey(this->mLocale), QM_VOID);
|
||||
} else {
|
||||
localeAwareRangeBound = bound;
|
||||
}
|
||||
|
|
|
@ -357,8 +357,7 @@ void IDBTypedCursor<CursorType>::Continue(JSContext* const aCx,
|
|||
if (IsLocaleAware() && !key.IsUnset()) {
|
||||
auto result = key.ToLocaleAwareKey(GetSourceRef().Locale());
|
||||
if (result.isErr()) {
|
||||
aRv = result.unwrapErr().ExtractErrorResult(
|
||||
InvalidMapsTo<NS_ERROR_DOM_INDEXEDDB_DATA_ERR>);
|
||||
aRv.Throw(result.inspectErr());
|
||||
return;
|
||||
}
|
||||
key = result.unwrap();
|
||||
|
@ -459,8 +458,7 @@ void IDBTypedCursor<CursorType>::ContinuePrimaryKey(
|
|||
if (IsLocaleAware() && !key.IsUnset()) {
|
||||
auto result = key.ToLocaleAwareKey(GetSourceRef().Locale());
|
||||
if (result.isErr()) {
|
||||
aRv = result.unwrapErr().ExtractErrorResult(
|
||||
InvalidMapsTo<NS_ERROR_DOM_INDEXEDDB_DATA_ERR>);
|
||||
aRv.Throw(result.inspectErr());
|
||||
return;
|
||||
}
|
||||
key = result.unwrap();
|
||||
|
|
|
@ -61,19 +61,14 @@ using namespace mozilla::ipc;
|
|||
|
||||
namespace {
|
||||
|
||||
IndexUpdateInfo MakeIndexUpdateInfo(const int64_t aIndexID, const Key& aKey,
|
||||
const nsCString& aLocale,
|
||||
ErrorResult* const aRv) {
|
||||
Result<IndexUpdateInfo, nsresult> MakeIndexUpdateInfo(
|
||||
const int64_t aIndexID, const Key& aKey, const nsCString& aLocale) {
|
||||
IndexUpdateInfo indexUpdateInfo;
|
||||
indexUpdateInfo.indexId() = aIndexID;
|
||||
indexUpdateInfo.value() = aKey;
|
||||
if (!aLocale.IsEmpty()) {
|
||||
auto result = aKey.ToLocaleAwareKey(aLocale);
|
||||
if (result.isErr()) {
|
||||
*aRv = result.unwrapErr().ExtractErrorResult(
|
||||
InvalidMapsTo<NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR>);
|
||||
}
|
||||
indexUpdateInfo.localizedValue() = result.unwrap();
|
||||
IDB_TRY_UNWRAP(indexUpdateInfo.localizedValue(),
|
||||
aKey.ToLocaleAwareKey(aLocale));
|
||||
}
|
||||
return indexUpdateInfo;
|
||||
}
|
||||
|
@ -521,8 +516,11 @@ void IDBObjectStore::AppendIndexUpdateInfo(
|
|||
return;
|
||||
}
|
||||
|
||||
*aUpdateInfoArray->AppendElement() =
|
||||
MakeIndexUpdateInfo(aIndexID, key, aLocale, aRv);
|
||||
IDB_TRY_UNWRAP(auto item, MakeIndexUpdateInfo(aIndexID, key, aLocale),
|
||||
QM_VOID,
|
||||
[aRv](const nsresult tryResult) { aRv->Throw(tryResult); });
|
||||
|
||||
aUpdateInfoArray->AppendElement(std::move(item));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -584,11 +582,11 @@ void IDBObjectStore::AppendIndexUpdateInfo(
|
|||
continue;
|
||||
}
|
||||
|
||||
*aUpdateInfoArray->AppendElement() =
|
||||
MakeIndexUpdateInfo(aIndexID, value, aLocale, aRv);
|
||||
if (aRv->Failed()) {
|
||||
return;
|
||||
}
|
||||
IDB_TRY_UNWRAP(
|
||||
auto item, MakeIndexUpdateInfo(aIndexID, value, aLocale), QM_VOID,
|
||||
[aRv](const nsresult tryResult) { aRv->Throw(tryResult); });
|
||||
|
||||
aUpdateInfoArray->AppendElement(std::move(item));
|
||||
}
|
||||
} else {
|
||||
Key value;
|
||||
|
@ -601,8 +599,11 @@ void IDBObjectStore::AppendIndexUpdateInfo(
|
|||
return;
|
||||
}
|
||||
|
||||
*aUpdateInfoArray->AppendElement() =
|
||||
MakeIndexUpdateInfo(aIndexID, value, aLocale, aRv);
|
||||
IDB_TRY_UNWRAP(auto item, MakeIndexUpdateInfo(aIndexID, value, aLocale),
|
||||
QM_VOID,
|
||||
[aRv](const nsresult tryResult) { aRv->Throw(tryResult); });
|
||||
|
||||
aUpdateInfoArray->AppendElement(std::move(item));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,8 @@ class IDBError {
|
|||
friend class IDBError;
|
||||
|
||||
public:
|
||||
MOZ_IMPLICIT IDBError(nsresult aRv) : mVariant(ErrorResult{aRv}) {}
|
||||
|
||||
IDBError(ExceptionType, ErrorResult&& aErrorResult)
|
||||
: mVariant(std::move(aErrorResult)) {}
|
||||
|
||||
|
@ -99,7 +101,8 @@ class IDBError {
|
|||
|
||||
template <typename... SpecialValueMappers>
|
||||
ErrorResult ExtractErrorResult(SpecialValueMappers... aSpecialValueMappers) {
|
||||
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 8)
|
||||
#if (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 8)) && \
|
||||
!defined(XGILL_PLUGIN)
|
||||
return mVariant.match(
|
||||
[](ErrorResult& aException) { return std::move(aException); },
|
||||
[aSpecialValueMappers...](const SpecialConstant<S>& aSpecialValue) {
|
||||
|
|
|
@ -182,8 +182,7 @@ IDBResult<Ok, IDBSpecialValue::Invalid> ConvertArrayValueToKey(
|
|||
[[]] // 0x80
|
||||
*/
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> Key::SetFromString(
|
||||
const nsAString& aString) {
|
||||
Result<Ok, nsresult> Key::SetFromString(const nsAString& aString) {
|
||||
mBuffer.Truncate();
|
||||
auto result = EncodeString(aString, 0);
|
||||
if (result.isOk()) {
|
||||
|
@ -213,8 +212,7 @@ uint32_t Key::LengthOfEncodedBinary(const EncodedDataType* aPos,
|
|||
return iter - aPos - 1;
|
||||
}
|
||||
|
||||
IDBResult<Key, IDBSpecialValue::Invalid> Key::ToLocaleAwareKey(
|
||||
const nsCString& aLocale) const {
|
||||
Result<Key, nsresult> Key::ToLocaleAwareKey(const nsCString& aLocale) const {
|
||||
Key res;
|
||||
|
||||
if (IsUnset()) {
|
||||
|
@ -258,7 +256,7 @@ IDBResult<Key, IDBSpecialValue::Invalid> Key::ToLocaleAwareKey(
|
|||
}
|
||||
|
||||
if (!res.mBuffer.SetCapacity(mBuffer.Length(), fallible)) {
|
||||
return Err(IDBException(NS_ERROR_OUT_OF_MEMORY));
|
||||
return Err(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// A string was found, so we need to copy the data we've read so far
|
||||
|
@ -292,21 +290,21 @@ IDBResult<Key, IDBSpecialValue::Invalid> Key::ToLocaleAwareKey(
|
|||
if (type == eTerminator) {
|
||||
// Copy array TypeID and terminator from raw key
|
||||
if (!updateBufferAndIter(0)) {
|
||||
return Err(IDBException(NS_ERROR_OUT_OF_MEMORY));
|
||||
return Err(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
} else if (type == eFloat || type == eDate) {
|
||||
// Copy number from raw key
|
||||
const size_t byteCount = std::min(sizeof(uint64_t), size_t(end - it - 1));
|
||||
|
||||
if (!updateBufferAndIter(byteCount)) {
|
||||
return Err(IDBException(NS_ERROR_OUT_OF_MEMORY));
|
||||
return Err(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
} else if (type == eBinary) {
|
||||
// skip all binary data
|
||||
const auto binaryLength = LengthOfEncodedBinary(it, end);
|
||||
|
||||
if (!updateBufferAndIter(binaryLength)) {
|
||||
return Err(IDBException(NS_ERROR_OUT_OF_MEMORY));
|
||||
return Err(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
} else {
|
||||
// Decode string and reencode
|
||||
|
@ -546,24 +544,24 @@ IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeJSVal(
|
|||
return EncodeJSValInternal(aCx, aVal, aTypeOffset, 0);
|
||||
}
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeString(
|
||||
const nsAString& aString, uint8_t aTypeOffset) {
|
||||
Result<Ok, nsresult> Key::EncodeString(const nsAString& aString,
|
||||
uint8_t aTypeOffset) {
|
||||
return EncodeString(Span{aString}, aTypeOffset);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeString(
|
||||
const Span<const T> aInput, uint8_t aTypeOffset) {
|
||||
Result<Ok, nsresult> Key::EncodeString(const Span<const T> aInput,
|
||||
uint8_t aTypeOffset) {
|
||||
return EncodeAsString(aInput, eString + aTypeOffset);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeAsString(
|
||||
const Span<const T> aInput, uint8_t aType) {
|
||||
Result<Ok, nsresult> Key::EncodeAsString(const Span<const T> aInput,
|
||||
uint8_t aType) {
|
||||
// First measure how long the encoded string will be.
|
||||
if (NS_WARN_IF(UINT32_MAX - 2 < uintptr_t(aInput.Length()))) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return Err(IDBException(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR));
|
||||
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
}
|
||||
|
||||
// The +2 is for initial aType and trailing 0. We'll compensate for multi-byte
|
||||
|
@ -587,7 +585,7 @@ IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeAsString(
|
|||
payloadSize += char16_t(val) > TWO_BYTE_LIMIT ? 2 : 1;
|
||||
if (!payloadSize.isValid()) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return Err(IDBException(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR));
|
||||
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -600,13 +598,13 @@ IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeAsString(
|
|||
|
||||
if (!size.isValid()) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return Err(IDBException(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR));
|
||||
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
}
|
||||
|
||||
char* buffer;
|
||||
if (!mBuffer.GetMutableData(&buffer, size.value())) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return Err(IDBException(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR));
|
||||
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
}
|
||||
buffer += oldLen;
|
||||
|
||||
|
@ -651,8 +649,9 @@ IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeAsString(
|
|||
return Ok();
|
||||
}
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeLocaleString(
|
||||
const nsAString& aString, uint8_t aTypeOffset, const nsCString& aLocale) {
|
||||
Result<Ok, nsresult> Key::EncodeLocaleString(const nsAString& aString,
|
||||
uint8_t aTypeOffset,
|
||||
const nsCString& aLocale) {
|
||||
const int length = aString.Length();
|
||||
if (length == 0) {
|
||||
return Ok();
|
||||
|
@ -662,7 +661,7 @@ IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeLocaleString(
|
|||
UErrorCode uerror = U_ZERO_ERROR;
|
||||
UCollator* collator = ucol_open(aLocale.get(), &uerror);
|
||||
if (NS_WARN_IF(U_FAILURE(uerror))) {
|
||||
return Err(IDBException(NS_ERROR_FAILURE));
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
MOZ_ASSERT(collator);
|
||||
|
||||
|
@ -671,7 +670,7 @@ IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeLocaleString(
|
|||
collator, ustr, length, keyBuffer.Elements(), keyBuffer.Length());
|
||||
if (sortKeyLength > (int32_t)keyBuffer.Length()) {
|
||||
if (!keyBuffer.SetLength(sortKeyLength, fallible)) {
|
||||
return Err(IDBException(NS_ERROR_OUT_OF_MEMORY));
|
||||
return Err(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
sortKeyLength = ucol_getSortKey(collator, ustr, length,
|
||||
keyBuffer.Elements(), sortKeyLength);
|
||||
|
@ -679,7 +678,7 @@ IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeLocaleString(
|
|||
|
||||
ucol_close(collator);
|
||||
if (NS_WARN_IF(sortKeyLength == 0)) {
|
||||
return Err(IDBException(NS_ERROR_FAILURE));
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
return EncodeString(Span{keyBuffer}.AsConst().First(sortKeyLength),
|
||||
|
@ -832,9 +831,8 @@ double Key::DecodeNumber(const EncodedDataType*& aPos,
|
|||
return BitwiseCast<double>(bits);
|
||||
}
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> Key::EncodeBinary(JSObject* aObject,
|
||||
bool aIsViewObject,
|
||||
uint8_t aTypeOffset) {
|
||||
Result<Ok, nsresult> Key::EncodeBinary(JSObject* aObject, bool aIsViewObject,
|
||||
uint8_t aTypeOffset) {
|
||||
uint8_t* bufferData;
|
||||
uint32_t bufferLength;
|
||||
|
||||
|
|
|
@ -137,8 +137,7 @@ class Key {
|
|||
return res;
|
||||
}
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> SetFromString(
|
||||
const nsAString& aString);
|
||||
Result<Ok, nsresult> SetFromString(const nsAString& aString);
|
||||
|
||||
void SetFromInteger(int64_t aInt) {
|
||||
mBuffer.Truncate();
|
||||
|
@ -160,8 +159,7 @@ class Key {
|
|||
IDBResult<Ok, IDBSpecialValue::Invalid> AppendItem(
|
||||
JSContext* aCx, bool aFirstOfArray, JS::Handle<JS::Value> aVal);
|
||||
|
||||
IDBResult<Key, IDBSpecialValue::Invalid> ToLocaleAwareKey(
|
||||
const nsCString& aLocale) const;
|
||||
Result<Key, nsresult> ToLocaleAwareKey(const nsCString& aLocale) const;
|
||||
|
||||
void FinishArray() { TrimBuffer(); }
|
||||
|
||||
|
@ -217,25 +215,23 @@ class Key {
|
|||
IDBResult<Ok, IDBSpecialValue::Invalid> EncodeJSVal(
|
||||
JSContext* aCx, JS::Handle<JS::Value> aVal, uint8_t aTypeOffset);
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> EncodeString(const nsAString& aString,
|
||||
uint8_t aTypeOffset);
|
||||
Result<Ok, nsresult> EncodeString(const nsAString& aString,
|
||||
uint8_t aTypeOffset);
|
||||
|
||||
template <typename T>
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> EncodeString(Span<const T> aInput,
|
||||
uint8_t aTypeOffset);
|
||||
Result<Ok, nsresult> EncodeString(Span<const T> aInput, uint8_t aTypeOffset);
|
||||
|
||||
template <typename T>
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> EncodeAsString(Span<const T> aInput,
|
||||
uint8_t aType);
|
||||
Result<Ok, nsresult> EncodeAsString(Span<const T> aInput, uint8_t aType);
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> EncodeLocaleString(
|
||||
const nsAString& aString, uint8_t aTypeOffset, const nsCString& aLocale);
|
||||
Result<Ok, nsresult> EncodeLocaleString(const nsAString& aString,
|
||||
uint8_t aTypeOffset,
|
||||
const nsCString& aLocale);
|
||||
|
||||
void EncodeNumber(double aFloat, uint8_t aType);
|
||||
|
||||
IDBResult<Ok, IDBSpecialValue::Invalid> EncodeBinary(JSObject* aObject,
|
||||
bool aIsViewObject,
|
||||
uint8_t aTypeOffset);
|
||||
Result<Ok, nsresult> EncodeBinary(JSObject* aObject, bool aIsViewObject,
|
||||
uint8_t aTypeOffset);
|
||||
|
||||
// Decoding functions. aPos points into mBuffer and is adjusted to point
|
||||
// past the consumed value. (Note: this may be beyond aEnd).
|
||||
|
|
|
@ -1052,10 +1052,7 @@ class EncodeKeysFunction final : public mozIStorageFunction {
|
|||
aArguments->GetString(0, stringKey);
|
||||
|
||||
Key key;
|
||||
IDB_TRY(key.SetFromString(stringKey).mapErr([](auto&& err) {
|
||||
return err.ExtractNSResult(
|
||||
InvalidMapsTo<NS_ERROR_DOM_INDEXEDDB_DATA_ERR>);
|
||||
}));
|
||||
IDB_TRY(key.SetFromString(stringKey));
|
||||
|
||||
return key;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче