1 /*
   2  * Copyright (c) 2015, 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-8136694: Megemorphic scope access does not throw ReferenceError when property is missing
  26  *
  27  * @test
  28  * @option --unstable-relink-threshold=16
  29  * @run
  30  */
  31 
  32 function checkFoo() {
  33     try {
  34         // The 'foo' access becomes megamorphic
  35         foo;
  36         return true;
  37     } catch (e) {
  38         return false;
  39     }
  40 }
  41 
  42 
  43 // Similar check for 'with' blocks as well.
  44 function checkFooInWith() {
  45     with({}) {
  46         try {
  47             // The 'foo' access becomes megamorphic
  48             foo;
  49             return true;
  50         } catch (e) {
  51             return false;
  52         }
  53     }
  54 }
  55 
  56 function loop(checker) {
  57     // LIMIT has to be more than the megamorphic threashold
  58     // set via @option in this test header!
  59     var LIMIT = 20;
  60     for (var i = 0; i < LIMIT; i++) {
  61         // make sure global has no "foo"
  62         delete foo;
  63         Assert.assertFalse(checker(), "Expected false in interation " + i);
  64 
  65         // now add 'foo' in global
  66         foo = 44;
  67         Assert.assertTrue(checker(), "Expected true in interation " + i);
  68     }
  69 }
  70 
  71 
  72 loop(checkFoo);
  73 loop(checkFooInWith);