tor-browser

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

test_promise.py (4151B)


      1 import WebIDL
      2 
      3 
      4 def WebIDLTest(parser, harness):
      5    threw = False
      6    try:
      7        parser.parse(
      8            """
      9            interface A {
     10              legacycaller Promise<any> foo();
     11            };
     12        """
     13        )
     14        parser.finish()
     15 
     16    except WebIDL.WebIDLError:
     17        threw = True
     18    harness.ok(threw, "Should not allow Promise return values for legacycaller.")
     19 
     20    parser = parser.reset()
     21    threw = False
     22    try:
     23        parser.parse(
     24            """
     25            interface A {
     26              Promise<any> foo();
     27              long foo(long arg);
     28            };
     29        """
     30        )
     31        parser.finish()
     32    except WebIDL.WebIDLError:
     33        threw = True
     34    harness.ok(
     35        threw,
     36        "Should not allow overloads which have both Promise and "
     37        "non-Promise return types.",
     38    )
     39 
     40    parser = parser.reset()
     41    threw = False
     42    try:
     43        parser.parse(
     44            """
     45            interface A {
     46              long foo(long arg);
     47              Promise<any> foo();
     48            };
     49        """
     50        )
     51        parser.finish()
     52    except WebIDL.WebIDLError:
     53        threw = True
     54    harness.ok(
     55        threw,
     56        "Should not allow overloads which have both Promise and "
     57        "non-Promise return types.",
     58    )
     59 
     60    parser = parser.reset()
     61    threw = False
     62    try:
     63        parser.parse(
     64            """
     65            interface A {
     66              Promise<any>? foo();
     67            };
     68        """
     69        )
     70        parser.finish()
     71    except WebIDL.WebIDLError:
     72        threw = True
     73    harness.ok(threw, "Should not allow nullable Promise return values.")
     74 
     75    parser = parser.reset()
     76    threw = False
     77    try:
     78        parser.parse(
     79            """
     80            interface A {
     81              undefined foo(Promise<any>? arg);
     82            };
     83        """
     84        )
     85        parser.finish()
     86    except WebIDL.WebIDLError:
     87        threw = True
     88    harness.ok(threw, "Should not allow nullable Promise arguments.")
     89 
     90    parser = parser.reset()
     91    parser.parse(
     92        """
     93        interface A {
     94          Promise<any> foo();
     95          Promise<any> foo(long arg);
     96        };
     97    """
     98    )
     99    parser.finish()
    100 
    101    harness.ok(True, "Should allow overloads which only have Promise and return types.")
    102 
    103    parser = parser.reset()
    104    threw = False
    105    try:
    106        parser.parse(
    107            """
    108            interface A {
    109              attribute Promise<any> attr;
    110            };
    111        """
    112        )
    113        parser.finish()
    114    except WebIDL.WebIDLError:
    115        threw = True
    116    harness.ok(threw, "Should not allow writable Promise-typed attributes.")
    117 
    118    parser = parser.reset()
    119    threw = False
    120    try:
    121        parser.parse(
    122            """
    123            interface A {
    124              [LegacyLenientSetter] readonly attribute Promise<any> attr;
    125            };
    126        """
    127        )
    128        parser.finish()
    129    except WebIDL.WebIDLError:
    130        threw = True
    131    harness.ok(
    132        threw, "Should not allow [LegacyLenientSetter] Promise-typed attributes."
    133    )
    134 
    135    parser = parser.reset()
    136    threw = False
    137    try:
    138        parser.parse(
    139            """
    140            interface A {
    141              [PutForwards=bar] readonly attribute Promise<any> attr;
    142            };
    143        """
    144        )
    145        parser.finish()
    146    except WebIDL.WebIDLError:
    147        threw = True
    148    harness.ok(threw, "Should not allow [PutForwards] Promise-typed attributes.")
    149 
    150    parser = parser.reset()
    151    threw = False
    152    try:
    153        parser.parse(
    154            """
    155            interface A {
    156              [Replaceable] readonly attribute Promise<any> attr;
    157            };
    158        """
    159        )
    160        parser.finish()
    161    except WebIDL.WebIDLError:
    162        threw = True
    163    harness.ok(threw, "Should not allow [Replaceable] Promise-typed attributes.")
    164 
    165    parser = parser.reset()
    166    threw = False
    167    try:
    168        parser.parse(
    169            """
    170            interface A {
    171              [SameObject] readonly attribute Promise<any> attr;
    172            };
    173        """
    174        )
    175        parser.finish()
    176    except WebIDL.WebIDLError:
    177        threw = True
    178    harness.ok(threw, "Should not allow [SameObject] Promise-typed attributes.")