File: idbindex_keyPath.any.js

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (74 lines) | stat: -rw-r--r-- 2,410 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// META: title=IndexedDB: IDBIndex keyPath attribute
// META: script=resources/support.js

indexeddb_test(
  (t, db) => {
    const store = db.createObjectStore('store', {keyPath: ['a', 'b']});
    store.createIndex('index', ['a', 'b']);
  },
  (t, db) => {
    const tx = db.transaction('store', 'readonly');
    const store = tx.objectStore('store');
    const index = store.index('index');
    assert_equals(typeof index.keyPath, 'object', 'keyPath is an object');
    assert_true(Array.isArray(index.keyPath), 'keyPath is an array');

    assert_equals(
      index.keyPath, index.keyPath,
      'Same object instance is returned each time keyPath is inspected');

    const tx2 = db.transaction('store', 'readonly');
    const store2 = tx2.objectStore('store');
    const index2 = store2.index('index');

    assert_not_equals(
      index.keyPath, index2.keyPath,
      'Different instances are returned from different index instances.');

    t.done();
  },
  `IDBIndex's keyPath attribute returns the same object.`);

  indexeddb_test(
  (t, db) => {
    const store = db.createObjectStore('store', {autoIncrement: true});
    store.createIndex('index', ['a']);

    store.add({a: 1, b: 2, c: 3})
  },
  (t, db) => {
    const tx = db.transaction('store', 'readonly');
    const store = tx.objectStore('store');
    const index = store.index('index');
    const cursorReq = index.openCursor();

    cursorReq.onsuccess = t.step_func_done((e) => {
      const expectedKeyValue = [1];
      const actualKeyValue = e.target.result.key;

      assert_array_equals(actualKeyValue, expectedKeyValue, "An array keypath should yield an array key");
    });
  },
  `IDBIndex's keyPath array with a single value`);

  indexeddb_test(
  (t, db) => {
    const store = db.createObjectStore('store', {autoIncrement: true});
    store.createIndex('index', ['a', 'b']);

    store.add({a: 1, b: 2, c: 3})
  },
  (t, db) => {
    const tx = db.transaction('store', 'readonly');
    const store = tx.objectStore('store');
    const index = store.index('index');
    const cursorReq = index.openCursor();

    cursorReq.onsuccess = t.step_func_done((e) => {
      const expectedKeyValue = [1, 2];
      const actualKeyValue = e.target.result.key;

      assert_array_equals(actualKeyValue, expectedKeyValue, "An array keypath should yield an array key");
    });
  },
  `IDBIndex's keyPath array with multiple values`);