nashorn/test/script/basic/JDK-8067139.js
changeset 28690 78317797ab62
child 31925 85c87bc2f1f3
equal deleted inserted replaced
28597:b2f9702efbe9 28690:78317797ab62
       
     1 /*
       
     2  * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  * 
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  * 
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  * 
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  * 
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /**
       
    25  * JDK-8067139: Finally blocks inlined incorrectly
       
    26  *
       
    27  * @test
       
    28  * @run
       
    29  */
       
    30 
       
    31 // Test case for JDK-8067139
       
    32 // as well as for JDK-8030198 which is a duplicate.
       
    33 (function(){
       
    34     var catchCount = 0; 
       
    35     try {
       
    36         (function (){
       
    37             try { 
       
    38                 return; 
       
    39             } catch(x) { 
       
    40                 ++catchCount;
       
    41             } finally { 
       
    42                 throw 0; 
       
    43             } 
       
    44         })();
       
    45         Assert.fail(); // must throw
       
    46     } catch(e) {
       
    47         Assert.assertEquals(e, 0); // threw 0
       
    48         Assert.assertEquals(catchCount, 0); // inner catch never executed
       
    49     }
       
    50 })();
       
    51 
       
    52 // Test case for JDK-8048862 which is a duplicate of this bug
       
    53 var ret = (function(o) { 
       
    54     try{
       
    55         with(o) {
       
    56             return x;
       
    57         }
       
    58     } finally {
       
    59         try { 
       
    60             return x;
       
    61         } catch(e) {
       
    62             Assert.assertTrue(e instanceof ReferenceError);
       
    63             return 2;
       
    64         }
       
    65     }
       
    66 })({x: 1});
       
    67 Assert.assertEquals(ret, 2); // executed the catch block
       
    68 
       
    69 // Test cases for JDK-8066231 that is a duplicate of this bug
       
    70 // Case 1
       
    71 (function (){ try { Object; } catch(x if x >>>=0) { throw x2; } finally { } })();
       
    72 // Case 2
       
    73 try {
       
    74     (function (){ try { return; } catch(x) { return x ^= 0; } finally { throw 0; } })();
       
    75     Assert.fail();
       
    76 } catch(e) {
       
    77     Assert.assertEquals(e, 0); // threw 0
       
    78 }
       
    79 // Case 3
       
    80 try {
       
    81     (function (){ try { return; } catch(x) { return x ^= Object; } finally { throw Object; } })();
       
    82     Assert.fail();
       
    83 } catch(e) {
       
    84     Assert.assertEquals(e, Object); // threw Object
       
    85 }
       
    86 // Case from comment
       
    87 try {
       
    88     (function () { try { Object } catch(x) { (x=y); return; } finally { throw Object; } })();
       
    89     Assert.fail();
       
    90 } catch(e) {
       
    91     Assert.assertEquals(e, Object); // threw Object
       
    92 }