Bug 1395071 - Unify the key validation using Key::EncodeJSValInternal. r=baku

This commit is contained in:
Bevis Tseng 2017-09-01 13:50:14 +08:00
Родитель 439bada5bc
Коммит f5062dd073
2 изменённых файлов: 11 добавлений и 68 удалений

Просмотреть файл

@ -92,29 +92,19 @@ IDBKeyRange::FromJSVal(JSContext* aCx,
}
JS::Rooted<JSObject*> obj(aCx, aVal.isObject() ? &aVal.toObject() : nullptr);
bool isValidKey = aVal.isPrimitive();
if (!isValidKey) {
js::ESClass cls;
if (!js::GetBuiltinClass(aCx, obj, &cls)) {
return NS_ERROR_UNEXPECTED;
}
isValidKey = cls == js::ESClass::Array || cls == js::ESClass::Date;
}
if (isValidKey) {
// A valid key returns an 'only' IDBKeyRange.
keyRange = new IDBKeyRange(nullptr, false, false, true);
nsresult rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower());
if (NS_FAILED(rv)) {
return rv;
}
// Unwrap an IDBKeyRange object if possible.
if (obj && NS_SUCCEEDED(UNWRAP_OBJECT(IDBKeyRange, obj, keyRange))) {
MOZ_ASSERT(keyRange);
keyRange.forget(aKeyRange);
return NS_OK;
}
else {
MOZ_ASSERT(aVal.isObject());
// An object is not permitted unless it's another IDBKeyRange.
if (NS_FAILED(UNWRAP_OBJECT(IDBKeyRange, obj, keyRange))) {
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
}
// A valid key returns an 'only' IDBKeyRange.
keyRange = new IDBKeyRange(nullptr, false, false, true);
nsresult rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower());
if (NS_FAILED(rv)) {
return rv;
}
keyRange.forget(aKeyRange);

Просмотреть файл

@ -1,47 +0,0 @@
[idb-binary-key-roundtrip.htm]
type: testharness
[Binary keys can be supplied using the view type Uint8Array]
expected: FAIL
[Binary keys can be supplied using the view type Uint8ClampedArray]
expected: FAIL
[Binary keys can be supplied using the view type Int8Array]
expected: FAIL
[Binary keys can be supplied using the view type Uint16Array]
expected: FAIL
[Binary keys can be supplied using the view type Int16Array]
expected: FAIL
[Binary keys can be supplied using the view type Uint32Array]
expected: FAIL
[Binary keys can be supplied using the view type Int32Array]
expected: FAIL
[Binary keys can be supplied using the view type Float32Array]
expected: FAIL
[Binary keys can be supplied using the view type Float64Array]
expected: FAIL
[ArrayBuffer can be used to supply a binary key]
expected: FAIL
[DataView can be used to supply a binary key]
expected: FAIL
[DataView with explicit offset can be used to supply a binary key]
expected: FAIL
[DataView with explicit offset and length can be used to supply a binary key]
expected: FAIL
[Uint8Array with explicit offset can be used to supply a binary key]
expected: FAIL
[Uint8Array with explicit offset and length can be used to supply a binary key]
expected: FAIL