summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/nodes/support/NodeList-static-length-tampered.js
blob: 51167e2ddcc9f962d69a5e45c93732597414b5fb (plain)
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
"use strict";

function makeStaticNodeList(length) {
    const fooRoot = document.createElement("div");

    for (var i = 0; i < length; i++) {
        const el = document.createElement("span");
        el.className = "foo";
        fooRoot.append(el);
    }

    document.body.append(fooRoot);
    return fooRoot.querySelectorAll(".foo");
}

const indexOfNodeList = new Function("nodeList", `
    const __cacheBust = ${Math.random()};

    const el = nodeList[50];

    let index = -1;

    for (var i = 0; i < 1e5 / 2; i++) {
        for (var j = 0; j < nodeList.length; j++) {
            if (nodeList[j] === el) {
                index = j;
                break;
            }
        }
    }

    return index;
`);

const arrayIndexOfNodeList = new Function("nodeList", `
    const __cacheBust = ${Math.random()};

    const el = nodeList[50];
    const {indexOf} = Array.prototype;

    for (var i = 0; i < 1e5; i++) {
        var index = indexOf.call(nodeList, el);
    }

    return index;
`);