tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_undefined.py (5317B)


      1 import WebIDL
      2 
      3 
      4 def WebIDLTest(parser, harness):
      5    try:
      6        parser.parse(
      7            """
      8            dictionary Dict {
      9              undefined undefinedMember;
     10              double bar;
     11            };
     12            """
     13        )
     14        parser.finish()
     15    except WebIDL.WebIDLError:
     16        threw = True
     17 
     18    harness.ok(threw, "undefined must not be used as the type of a dictionary member")
     19 
     20    parser = parser.reset()
     21    threw = False
     22 
     23    try:
     24        parser.parse(
     25            """
     26            dictionary Dict {
     27              (undefined or double) undefinedMemberOfUnionInDict;
     28            };
     29            """
     30        )
     31        parser.finish()
     32    except WebIDL.WebIDLError:
     33        threw = True
     34 
     35    harness.ok(
     36        threw,
     37        "undefined must not be used as the type of a dictionary member, "
     38        "whether directly or in a union",
     39    )
     40 
     41    parser = parser.reset()
     42    threw = False
     43 
     44    try:
     45        parser.parse(
     46            """
     47            interface Foo {
     48              double bar(undefined foo);
     49            };
     50            """
     51        )
     52        parser.finish()
     53    except WebIDL.WebIDLError:
     54        threw = True
     55 
     56    harness.ok(
     57        threw,
     58        "undefined must not be used as the type of an argument in any "
     59        "circumstance (so not as the argument of a regular operation)",
     60    )
     61 
     62    parser = parser.reset()
     63    threw = False
     64 
     65    try:
     66        parser.parse(
     67            """
     68            interface Foo {
     69              getter double(undefined name);
     70            };
     71            """
     72        )
     73        parser.finish()
     74    except WebIDL.WebIDLError:
     75        threw = True
     76 
     77    harness.ok(
     78        threw,
     79        "undefined must not be used as the type of an argument in any "
     80        "circumstance (so not as the argument of a getter)",
     81    )
     82 
     83    parser = parser.reset()
     84    threw = False
     85 
     86    try:
     87        parser.parse(
     88            """
     89            interface Foo {
     90              setter undefined(DOMString name, undefined value);
     91            };
     92            """
     93        )
     94        parser.finish()
     95    except WebIDL.WebIDLError:
     96        threw = True
     97 
     98    harness.ok(
     99        threw,
    100        "undefined must not be used as the type of an argument in any "
    101        "circumstance (so not as the argument of a setter)",
    102    )
    103 
    104    parser = parser.reset()
    105    threw = False
    106 
    107    try:
    108        parser.parse(
    109            """
    110            interface Foo {
    111              deleter undefined (undefined name);
    112            };
    113            """
    114        )
    115        parser.finish()
    116    except WebIDL.WebIDLError:
    117        threw = True
    118 
    119    harness.ok(
    120        threw,
    121        "undefined must not be used as the type of an argument in any "
    122        "circumstance (so not as the argument of a deleter)",
    123    )
    124 
    125    parser = parser.reset()
    126    threw = False
    127 
    128    try:
    129        parser.parse(
    130            """
    131            interface Foo {
    132              constructor (undefined foo);
    133            };
    134            """
    135        )
    136        parser.finish()
    137    except WebIDL.WebIDLError:
    138        threw = True
    139 
    140    harness.ok(
    141        threw,
    142        "undefined must not be used as the type of an argument in any "
    143        "circumstance (so not as the argument of a constructor)",
    144    )
    145 
    146    parser = parser.reset()
    147    threw = False
    148 
    149    try:
    150        parser.parse(
    151            """
    152            callback Callback = undefined (undefined foo);
    153            """
    154        )
    155        parser.finish()
    156    except WebIDL.WebIDLError:
    157        threw = True
    158 
    159    harness.ok(
    160        threw,
    161        "undefined must not be used as the type of an argument in any "
    162        "circumstance (so not as the argument of a callback)",
    163    )
    164 
    165    parser = parser.reset()
    166    threw = False
    167 
    168    try:
    169        parser.parse(
    170            """
    171            interface Foo {
    172              async_iterable(undefined name);
    173            };
    174            """
    175        )
    176        parser.finish()
    177    except WebIDL.WebIDLError:
    178        threw = True
    179 
    180    harness.ok(
    181        threw,
    182        "undefined must not be used as the type of an argument in any "
    183        "circumstance (so not as the argument of an async_iterable "
    184        "iterator)",
    185    )
    186 
    187    parser = parser.reset()
    188    threw = False
    189 
    190    try:
    191        parser.parse(
    192            """
    193            interface Foo {
    194              static double bar(undefined foo);
    195            };
    196            """
    197        )
    198        parser.finish()
    199    except WebIDL.WebIDLError:
    200        threw = True
    201 
    202    harness.ok(
    203        threw,
    204        "undefined must not be used as the type of an argument in any "
    205        "circumstance (so not as the argument of a static operation)",
    206    )
    207 
    208    parser = parser.reset()
    209    threw = False
    210 
    211    try:
    212        parser.parse(
    213            """
    214            interface Foo {
    215              const undefined FOO = undefined;
    216            };
    217            """
    218        )
    219        parser.finish()
    220    except WebIDL.WebIDLError:
    221        threw = True
    222 
    223    harness.ok(
    224        threw,
    225        "undefined is not a valid type for a constant",
    226    )
    227 
    228    parser = parser.reset()
    229    threw = False
    230 
    231    try:
    232        parser.parse(
    233            """
    234            interface Foo {
    235              const any FOO = undefined;
    236            };
    237            """
    238        )
    239        parser.finish()
    240    except WebIDL.WebIDLError:
    241        threw = True
    242 
    243    harness.ok(
    244        threw,
    245        "undefined is not a valid value for a constant",
    246    )