Bug 1395071 - Unify the key validation using Key::EncodeJSValInternal. r=baku
authorBevis Tseng <btseng@mozilla.com>
Fri, 01 Sep 2017 13:50:14 +0800
changeset 428320 90691dd0694f25f0ce5569b5b4a323b502a97671
parent 428319 59a2c3461e78c3c455c5f32950a4d2ca23402c02
child 428321 ac433313dbd24b2c63c8e0d812297e3677f0a6ef
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1395071
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1395071 - Unify the key validation using Key::EncodeJSValInternal. r=baku
dom/indexedDB/IDBKeyRange.cpp
testing/web-platform/meta/IndexedDB/idb-binary-key-roundtrip.htm.ini
--- a/dom/indexedDB/IDBKeyRange.cpp
+++ b/dom/indexedDB/IDBKeyRange.cpp
@@ -87,39 +87,29 @@ IDBKeyRange::FromJSVal(JSContext* aCx,
 
   if (aVal.isNullOrUndefined()) {
     // undefined and null returns no IDBKeyRange.
     keyRange.forget(aKeyRange);
     return NS_OK;
   }
 
   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);
   return NS_OK;
 }
 
 // static
 already_AddRefed<IDBKeyRange>
deleted file mode 100644
--- a/testing/web-platform/meta/IndexedDB/idb-binary-key-roundtrip.htm.ini
+++ /dev/null
@@ -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
-