sundar@1541: /* sundar@1541: * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. sundar@1541: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@1541: * sundar@1541: * This code is free software; you can redistribute it and/or modify it sundar@1541: * under the terms of the GNU General Public License version 2 only, as sundar@1541: * published by the Free Software Foundation. sundar@1541: * sundar@1541: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@1541: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@1541: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@1541: * version 2 for more details (a copy is included in the LICENSE file that sundar@1541: * accompanied this code). sundar@1541: * sundar@1541: * You should have received a copy of the GNU General Public License version sundar@1541: * 2 along with this work; if not, write to the Free Software Foundation, sundar@1541: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@1541: * sundar@1541: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@1541: * or visit www.oracle.com if you need additional information or have any sundar@1541: * questions. sundar@1541: */ sundar@1541: sundar@1541: /** sundar@1541: * JDK-8136694: Megemorphic scope access does not throw ReferenceError when property is missing sundar@1541: * sundar@1541: * @test sundar@1541: * @fork sundar@1541: * @option -Dnashorn.unstable.relink.threshold=16 sundar@1541: * @run sundar@1541: */ sundar@1541: sundar@1541: function checkFoo() { sundar@1541: try { sundar@1541: // The 'foo' access becomes megamorphic sundar@1541: foo; sundar@1541: return true; sundar@1541: } catch (e) { sundar@1541: return false; sundar@1541: } sundar@1541: } sundar@1541: sundar@1541: sundar@1541: // Similar check for 'with' blocks as well. sundar@1541: function checkFooInWith() { sundar@1541: with({}) { sundar@1541: try { sundar@1541: // The 'foo' access becomes megamorphic sundar@1541: foo; sundar@1541: return true; sundar@1541: } catch (e) { sundar@1541: return false; sundar@1541: } sundar@1541: } sundar@1541: } sundar@1541: sundar@1541: function loop(checker) { sundar@1541: // LIMIT has to be more than the megamorphic threashold sundar@1541: // set via @option in this test header! sundar@1541: var LIMIT = 20; sundar@1541: for (var i = 0; i < LIMIT; i++) { sundar@1541: // make sure global has no "foo" sundar@1541: delete foo; sundar@1541: Assert.assertFalse(checker(), "Expected false in interation " + i); sundar@1541: sundar@1541: // now add 'foo' in global sundar@1541: foo = 44; sundar@1541: Assert.assertTrue(checker(), "Expected true in interation " + i); sundar@1541: } sundar@1541: } sundar@1541: sundar@1541: sundar@1541: loop(checkFoo); sundar@1541: loop(checkFooInWith);