js/src/tests/js1_7/geniter/throw-after-close.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 //-----------------------------------------------------------------------------
     7 var BUGNUMBER     = "(none)";
     8 var summary = "gen.close(); gen.throw(ex) throws ex forever";
     9 var actual, expect;
    11 printBugNumber(BUGNUMBER);
    12 printStatus(summary);
    14 /**************
    15  * BEGIN TEST *
    16  **************/
    18 function gen()
    19 {
    20   var x = 5, y = 7;
    21   var z = x + y;
    22   yield z;
    23 }
    25 var failed = false;
    26 var it = gen();
    28 try
    29 {
    30   it.close();
    32   // throw on closed generators just rethrows
    33   var doThrow = true;
    34   var thrown = "foobar";
    35   try
    36   {
    37     it.throw(thrown);
    38   }
    39   catch (e)
    40   {
    41     if (e === thrown)
    42       doThrow = false;
    43   }
    45   if (doThrow)
    46     throw "it.throw(\"" + thrown + "\") failed";
    48   // you can throw stuff at a closed generator forever
    49   doThrow = true;
    50   thrown = "sparky";
    51   try
    52   {
    53     it.throw(thrown);
    54   }
    55   catch (e)
    56   {
    57     if (e === thrown)
    58       doThrow = false;
    59   }
    61   if (doThrow)
    62     throw "it.throw(\"" + thrown + "\") failed";
    64   // don't execute a yield -- the uncaught exception
    65   // exhausted the generator
    66   var stopPassed = false;
    67   try
    68   {
    69     it.next();
    70   }
    71   catch (e)
    72   {
    73     if (e === StopIteration)
    74       stopPassed = true;
    75   }
    77   if (!stopPassed)
    78     throw "invalid or incorrect StopIteration";
    79 }
    80 catch (e)
    81 {
    82   failed = e;
    83 }
    87 expect = false;
    88 actual = failed;
    90 reportCompare(expect, actual, summary);

mercurial