summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resources/test/tests/unit/IdlDictionary/get_reverse_inheritance_stack.html
blob: 418bcdec92ac22822ef73b9c4249e80cc6ace6b7 (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
47
<!DOCTYPE HTML>
<html>
<head>
<title>IdlDictionary.prototype.get_reverse_inheritance_stack()</title>
</head>
<body>
<div id="log"></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
<script src="../../../idl-helper.js"></script>
<script>
    "use strict";
    test(function() {
        var stack = dictionaryFrom('dictionary A { };').get_reverse_inheritance_stack();
        assert_array_equals(stack.map(d => d.name), ["A"]);
    }, 'should return an array that includes itself.');

    test(function() {
        var d = dictionaryFrom('dictionary A : B { };');
        assert_throws_js(Error, _ => d.get_reverse_inheritance_stack());
    }, "should throw for dictionaries which inherit from another dictionary which wasn't added to the IdlArray");

    test(function() {
        var idl = new IdlArray();
        idl.add_idls('dictionary A : B { };');
        idl.add_untested_idls('dictionary B : C { }; dictionary C { };');
        var A = idl.members["A"];
        assert_array_equals(A.get_reverse_inheritance_stack().map(d => d.name), ["C", "B", "A"]);
    }, 'should return an array of dictionaries in order of inheritance, starting with the base dictionary');

    test(function () {
      let i = new IdlArray();
      i.add_untested_idls('dictionary A : B {};');
      i.assert_throws(new IdlHarnessError('A inherits B, but B is undefined.'), i => i.test());
    }, 'A : B with B undeclared should throw IdlHarnessError');

    test(function () {
      let i = new IdlArray();
      i.add_untested_idls('dictionary A : B {};');
      i.add_untested_idls('interface B {};');
      i.assert_throws(new IdlHarnessError('A inherits B, but A is not an interface.'), i => i.test());
    }, 'dictionary A : B with B interface should throw IdlHarnessError');
</script>
</body>
</html>