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