JDK-8067139.js revision 1173:82ae555768c7
12116Sjkh/*
22116Sjkh * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
32116Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42116Sjkh *
52116Sjkh * This code is free software; you can redistribute it and/or modify it
62116Sjkh * under the terms of the GNU General Public License version 2 only, as
72116Sjkh * published by the Free Software Foundation.
82116Sjkh *
92116Sjkh * This code is distributed in the hope that it will be useful, but WITHOUT
102116Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
118870Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
122116Sjkh * version 2 for more details (a copy is included in the LICENSE file that
132116Sjkh * accompanied this code).
142116Sjkh *
152116Sjkh * You should have received a copy of the GNU General Public License version
162116Sjkh * 2 along with this work; if not, write to the Free Software Foundation,
1750476Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
182116Sjkh *
192116Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202116Sjkh * or visit www.oracle.com if you need additional information or have any
212116Sjkh * questions.
222116Sjkh */
232116Sjkh
242116Sjkh/**
2597413Salfred * JDK-8067139: Finally blocks inlined incorrectly
2697413Salfred *
272116Sjkh * @test
282116Sjkh * @run
298870Srgrimes */
302116Sjkh
312116Sjkh// Test case for JDK-8067139
322116Sjkh// as well as for JDK-8030198 which is a duplicate.
332116Sjkh(function(){
342116Sjkh    var catchCount = 0;
352116Sjkh    try {
368870Srgrimes        (function (){
372116Sjkh            try {
382116Sjkh                return;
398870Srgrimes            } catch(x) {
402116Sjkh                ++catchCount;
412116Sjkh            } finally {
422116Sjkh                throw 0;
432116Sjkh            }
442116Sjkh        })();
452116Sjkh        Assert.fail(); // must throw
462116Sjkh    } catch(e) {
472116Sjkh        Assert.assertEquals(e, 0); // threw 0
482116Sjkh        Assert.assertEquals(catchCount, 0); // inner catch never executed
492116Sjkh    }
502116Sjkh})();
512116Sjkh
522116Sjkh// Test case for JDK-8048862 which is a duplicate of this bug
532116Sjkhvar ret = (function(o) {
542116Sjkh    try{
552116Sjkh        with(o) {
562116Sjkh            return x;
572116Sjkh        }
582116Sjkh    } finally {
592116Sjkh        try {
602116Sjkh            return x;
612116Sjkh        } catch(e) {
622116Sjkh            Assert.assertTrue(e instanceof ReferenceError);
632116Sjkh            return 2;
648870Srgrimes        }
658870Srgrimes    }
668870Srgrimes})({x: 1});
678870SrgrimesAssert.assertEquals(ret, 2); // executed the catch block
688870Srgrimes
698870Srgrimes// Test cases for JDK-8066231 that is a duplicate of this bug
702116Sjkh// Case 1
712116Sjkh(function (){ try { Object; } catch(x if x >>>=0) { throw x2; } finally { } })();
722116Sjkh// Case 2
732116Sjkhtry {
742116Sjkh    (function (){ try { return; } catch(x) { return x ^= 0; } finally { throw 0; } })();
752116Sjkh    Assert.fail();
762116Sjkh} catch(e) {
772116Sjkh    Assert.assertEquals(e, 0); // threw 0
782116Sjkh}
792116Sjkh// Case 3
802116Sjkhtry {
812116Sjkh    (function (){ try { return; } catch(x) { return x ^= Object; } finally { throw Object; } })();
822116Sjkh    Assert.fail();
832116Sjkh} catch(e) {
842116Sjkh    Assert.assertEquals(e, Object); // threw Object
852116Sjkh}
862116Sjkh// Case from comment
872116Sjkhtry {
882116Sjkh    (function () { try { Object } catch(x) { (x=y); return; } finally { throw Object; } })();
892116Sjkh    Assert.fail();
90} catch(e) {
91    Assert.assertEquals(e, Object); // threw Object
92}
93