keypath-special-identifiers.any.js (1665B)
1 // META: global=window,worker 2 // META: title=IndexedDB: Special-cased identifiers in extracting keys from values (ES bindings) 3 // META: script=resources/support.js 4 5 // Spec: https://w3c.github.io/IndexedDB/#extract-key-from-value 6 7 'use strict'; 8 9 [{ 10 type: 'String', 11 property: 'length', 12 instance: 'abc', 13 }, 14 { 15 type: 'Array', 16 property: 'length', 17 instance: ['a', 'b', 'c'], 18 }, 19 { 20 type: 'Blob', 21 property: 'size', 22 instance: new Blob(['abc']), 23 }, 24 { 25 type: 'Blob', 26 property: 'type', 27 instance: new Blob([''], {type: 'foo/bar'}), 28 }, 29 { 30 type: 'File', 31 property: 'name', 32 instance: new File([''], 'foo'), 33 }, 34 { 35 type: 'File', 36 property: 'lastModified', 37 instance: new File([''], '', {lastModified: 123}), 38 }, 39 ].forEach(function(testcase) { 40 indexeddb_test( 41 (t, db) => { 42 db.createObjectStore( 43 'store', {autoIncrement: true, keyPath: testcase.property}); 44 }, 45 (t, db) => { 46 const key = testcase.instance[testcase.property]; 47 const tx = 48 db.transaction('store', 'readwrite', {durability: 'relaxed'}); 49 tx.objectStore('store').put(testcase.instance); 50 const request = tx.objectStore('store').get(key); 51 request.onerror = t.unreached_func('request should not fail'); 52 request.onsuccess = t.step_func(function() { 53 const result = request.result; 54 assert_key_equals( 55 result[testcase.property], key, 'Property should be used as key'); 56 }); 57 tx.oncomplete = t.step_func(function() { 58 t.done(); 59 }); 60 }, 61 'Type: ' + testcase.type + ', identifier: ' + testcase.property); 62 });