| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- Submitted from TestTWF Paris --> | 2 <!-- Submitted from TestTWF Paris --> |
| 3 <meta charset="utf-8"> | 3 <meta charset="utf-8"> |
| 4 <title>Key sort order</title> | 4 <title>Key sort order</title> |
| 5 <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#
key-construct"> | 5 <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#
key-construct"> |
| 6 <link rel=assert title="For purposes of comparison, all Arrays are greater than
all DOMString, Date and float values; all DOMString values are greater than all
Date and float values; and all Date values are greater than all float values. Va
lues of type float are compared to other float values numerically. Values of typ
e Date are compared to other Date values chronologically. Values of type DOMStri
ng are compared to other values of type DOMString by using the algorithm defined
by step 4 of section 11.8.5, The Abstract Relational Comparison Algorithm, of t
he ECMAScript Language Specification [ECMA-262]. Values of type Array are compar
ed to other values of type Array as follows: | 6 <link rel=assert title="For purposes of comparison, all Arrays are greater than
all DOMString, Date and float values; all DOMString values are greater than all
Date and float values; and all Date values are greater than all float values. Va
lues of type float are compared to other float values numerically. Values of typ
e Date are compared to other Date values chronologically. Values of type DOMStri
ng are compared to other values of type DOMString by using the algorithm defined
by step 4 of section 11.8.5, The Abstract Relational Comparison Algorithm, of t
he ECMAScript Language Specification [ECMA-262]. Values of type Array are compar
ed to other values of type Array as follows: |
| 7 | 7 |
| 8 1. Let A be the first Array value and B be the second Array value. | 8 1. Let A be the first Array value and B be the second Array value. |
| 9 2. Let length be the lesser of A's length and B's length. | 9 2. Let length be the lesser of A's length and B's length. |
| 10 3. Let i be 0. | 10 3. Let i be 0. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 open_rq.onsuccess = function(e) { | 38 open_rq.onsuccess = function(e) { |
| 39 var actual_keys = [], | 39 var actual_keys = [], |
| 40 rq = db.transaction(store_name) | 40 rq = db.transaction(store_name) |
| 41 .objectStore(store_name) | 41 .objectStore(store_name) |
| 42 .openCursor(); | 42 .openCursor(); |
| 43 | 43 |
| 44 rq.onsuccess = t.step_func(function(e) { | 44 rq.onsuccess = t.step_func(function(e) { |
| 45 var cursor = e.target.result; | 45 var cursor = e.target.result; |
| 46 | 46 |
| 47 if (cursor) { | 47 if (cursor) { |
| 48 actual_keys.push(cursor.key.valueOf()); | 48 actual_keys.push(cursor.key); |
| 49 cursor.continue(); | 49 cursor.continue(); |
| 50 } | 50 } |
| 51 else { | 51 else { |
| 52 assert_object_equals(actual_keys, expected, "keyorder array"
); | 52 assert_key_equals(actual_keys, expected, "keyorder array"); |
| 53 assert_equals(actual_keys.length, expected.length, "array le
ngth"); | 53 assert_equals(actual_keys.length, expected.length, "array le
ngth"); |
| 54 | 54 |
| 55 t.done(); | 55 t.done(); |
| 56 } | 56 } |
| 57 }); | 57 }); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 // The IDBKey.cmp test | 60 // The IDBKey.cmp test |
| 61 test(function () { | 61 test(function () { |
| 62 var sorted = unsorted.slice(0).sort(function(a, b) { return indexedD
B.cmp(a, b)}); | 62 var sorted = unsorted.slice(0).sort(function(a, b) { return indexedD
B.cmp(a, b)}); |
| 63 | 63 assert_key_equals(sorted, expected, "sorted array"); |
| 64 for (var i in sorted) | |
| 65 if (typeof sorted[i] === "object" && 'valueOf' in sorted[i]) | |
| 66 sorted[i] = sorted[i].valueOf(); | |
| 67 | |
| 68 assert_object_equals(sorted, expected, "sorted array"); | |
| 69 | 64 |
| 70 }, "IDBKey.cmp sorted - " + desc); | 65 }, "IDBKey.cmp sorted - " + desc); |
| 71 } | 66 } |
| 72 | 67 |
| 73 var now = new Date(), | 68 var now = new Date(), |
| 74 one_sec_ago = new Date(now - 1000), | 69 one_sec_ago = new Date(now - 1000), |
| 75 one_min_future = new Date(now.getTime() + (1000*60)); | 70 one_min_future = new Date(now.getTime() + (1000*60)); |
| 76 | 71 |
| 77 keysort('String < Array', | 72 keysort('String < Array', |
| 78 [ [0], "yo", "", [] ], | 73 [ [0], "yo", "", [] ], |
| 79 [ "", "yo", [], [0] ]); | 74 [ "", "yo", [], [0] ]); |
| 80 | 75 |
| 81 keysort('float < String', | 76 keysort('float < String', |
| 82 [ Infinity, "yo", 0, "", 100 ], | 77 [ Infinity, "yo", 0, "", 100 ], |
| 83 [ 0, 100, Infinity, "", "yo" ]); | 78 [ 0, 100, Infinity, "", "yo" ]); |
| 84 | 79 |
| 85 keysort('float < Date', | 80 keysort('float < Date', |
| 86 [ now, 0, 9999999999999, -0.22 ], | 81 [ now, 0, 9999999999999, -0.22 ], |
| 87 [ -0.22, 0, 9999999999999, now.valueOf() ]); | 82 [ -0.22, 0, 9999999999999, now ]); |
| 88 | 83 |
| 89 keysort('float < Date < String < Array', | 84 keysort('float < Date < String < Array', |
| 90 [ [], "", now, [0], "-1", 0, 9999999999999, ], | 85 [ [], "", now, [0], "-1", 0, 9999999999999, ], |
| 91 [ 0, 9999999999999, now.valueOf(), "", "-1", [], [0] ]); | 86 [ 0, 9999999999999, now, "", "-1", [], [0] ]); |
| 92 | 87 |
| 93 | 88 |
| 94 keysort('Date(1 sec ago) < Date(now) < Date(1 minute in future)', | 89 keysort('Date(1 sec ago) < Date(now) < Date(1 minute in future)', |
| 95 [ now, one_sec_ago, one_min_future ], | 90 [ now, one_sec_ago, one_min_future ], |
| 96 [ one_sec_ago.valueOf(), now.valueOf(), one_min_future.valueOf() ]); | 91 [ one_sec_ago, now, one_min_future ]); |
| 97 | 92 |
| 98 keysort('-1.1 < 1 < 1.01337 < 1.013373 < 2', | 93 keysort('-1.1 < 1 < 1.01337 < 1.013373 < 2', |
| 99 [ 1.013373, 2, 1.01337, -1.1, 1 ], | 94 [ 1.013373, 2, 1.01337, -1.1, 1 ], |
| 100 [ -1.1, 1, 1.01337, 1.013373, 2 ]); | 95 [ -1.1, 1, 1.01337, 1.013373, 2 ]); |
| 101 | 96 |
| 102 keysort('-Infinity < -0.01 < 0 < Infinity', | 97 keysort('-Infinity < -0.01 < 0 < Infinity', |
| 103 [ 0, -0.01, -Infinity, Infinity ], | 98 [ 0, -0.01, -Infinity, Infinity ], |
| 104 [ -Infinity, -0.01, 0, Infinity ]); | 99 [ -Infinity, -0.01, 0, Infinity ]); |
| 105 | 100 |
| 106 keysort('"" < "a" < "ab" < "b" < "ba"', | 101 keysort('"" < "a" < "ab" < "b" < "ba"', |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 -Infinity, | 145 -Infinity, |
| 151 2.55, | 146 2.55, |
| 152 [ 0, now ], | 147 [ 0, now ], |
| 153 [1] | 148 [1] |
| 154 ], | 149 ], |
| 155 [ | 150 [ |
| 156 -Infinity, | 151 -Infinity, |
| 157 1, | 152 1, |
| 158 2.55, | 153 2.55, |
| 159 Infinity, | 154 Infinity, |
| 160 one_sec_ago.valueOf(), | 155 one_sec_ago, |
| 161 now.valueOf(), | 156 now, |
| 162 "test", | 157 "test", |
| 163 [], | 158 [], |
| 164 [0 ,2, "c"], | 159 [0 ,2, "c"], |
| 165 [0, now.valueOf()], | 160 [0, now], |
| 166 [0, "b", "c"], | 161 [0, "b", "c"], |
| 167 [0, []], | 162 [0, []], |
| 168 [0, [], 3], | 163 [0, [], 3], |
| 169 [1], | 164 [1], |
| 170 [1, 2], | 165 [1, 2], |
| 171 ["a", "b"], | 166 ["a", "b"], |
| 172 ["a", "b", "c"], | 167 ["a", "b", "c"], |
| 173 ["a", [1, 2]], | 168 ["a", [1, 2]], |
| 174 ["a", [1, [-1]]], | 169 ["a", [1, [-1]]], |
| 175 ["b", "a"] | 170 ["b", "a"] |
| 176 ]); | 171 ]); |
| 177 | 172 |
| 178 </script> | 173 </script> |
| 179 | 174 |
| 180 <div id="log"></div> | 175 <div id="log"></div> |
| OLD | NEW |