| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <!-- Submitted from TestTWF Paris --> | |
| 3 <meta charset=utf-8"> | |
| 4 <meta name="timeout" content="long"> | |
| 5 <title>Valid key</title> | |
| 6 <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#
key-construct"> | |
| 7 <link rel=assert title="A value is said to be a valid key if it is one of the fo
llowing types: Array JavaScript objects [ECMA-262], DOMString [WEBIDL], Date [EC
MA-262] or float [WEBIDL]. However Arrays are only valid keys if every item in t
he array is defined and is a valid key (i.e. sparse arrays can not be valid keys
) and if the Array doesn't directly or indirectly contain itself. Any non-numeri
c properties are ignored, and thus does not affect whether the Array is a valid
key. Additionally, if the value is of type float, it is only a valid key if it i
s not NaN, and if the value is of type Date it is only a valid key if its [[Prim
itiveValue]] internal property, as defined by [ECMA-262], is not NaN. Conforming
user agents must support all valid keys as keys."> | |
| 8 <link rel=author href="mailto:batifon@yahoo.fr" title="Baptiste Fontaine"> | |
| 9 <script src=../../../resources/testharness.js></script> | |
| 10 <script src=../../../resources/testharnessreport.js></script> | |
| 11 <script src=support.js></script> | |
| 12 | |
| 13 <script> | |
| 14 function valid_key(desc, key) { | |
| 15 var db; | |
| 16 var t = async_test(document.title + " - " + desc); | |
| 17 var open_rq = createdb(t); | |
| 18 | |
| 19 open_rq.onupgradeneeded = function(e) { | |
| 20 db = e.target.result; | |
| 21 | |
| 22 store = db.createObjectStore("store"); | |
| 23 assert_true(store.add('value', key) instanceof IDBRequest); | |
| 24 | |
| 25 store2 = db.createObjectStore("store2", { keyPath: ["x", "keypath"]
}); | |
| 26 assert_true(store2.add({ x: 'v', keypath: key }) instanceof IDBReque
st); | |
| 27 }; | |
| 28 open_rq.onsuccess = function(e) { | |
| 29 var rq = db.transaction("store") | |
| 30 .objectStore("store") | |
| 31 .get(key) | |
| 32 rq.onsuccess = t.step_func(function(e) { | |
| 33 assert_equals(e.target.result, 'value') | |
| 34 var rq = db.transaction("store2") | |
| 35 .objectStore("store2") | |
| 36 .get(['v', key]) | |
| 37 rq.onsuccess = t.step_func(function(e) { | |
| 38 assert_equals(e.target.result.x, 'v'); | |
| 39 assert_key_equals(e.target.result.keypath, key); | |
| 40 t.done() | |
| 41 }) | |
| 42 }) | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 // Date | |
| 47 valid_key( 'new Date()' , new Date() ); | |
| 48 valid_key( 'new Date(0)' , new Date(0) ); | |
| 49 | |
| 50 // Array | |
| 51 valid_key( '[]' , [] ); | |
| 52 valid_key( 'new Array()' , new Array() ); | |
| 53 | |
| 54 valid_key( '["undefined"]' , ['undefined'] ); | |
| 55 | |
| 56 // Float | |
| 57 valid_key( 'Infinity' , Infinity ); | |
| 58 valid_key( '-Infinity' , -Infinity ); | |
| 59 valid_key( '0' , 0 ); | |
| 60 valid_key( '1.5' , 1.5 ); | |
| 61 valid_key( '3e38' , 3e38 ); | |
| 62 valid_key( '3e-38' , 3e38 ); | |
| 63 | |
| 64 // String | |
| 65 valid_key( '"foo"' , "foo" ); | |
| 66 valid_key( '"\\n"' , "\n" ); | |
| 67 valid_key( '""' , "" ); | |
| 68 valid_key( '"\\""' , "\"" ); | |
| 69 valid_key( '"\\u1234"' , "\u1234" ); | |
| 70 valid_key( '"\\u0000"' , "\u0000" ); | |
| 71 valid_key( '"NaN"' , "NaN" ); | |
| 72 | |
| 73 </script> | |
| 74 | |
| 75 <div id=log></div> | |
| OLD | NEW |