Mon, 07 Mar 2016 10:53:05 -0800
Added tag jdk8u76-b11 for changeset 0608b63feb60
hannesw@991 | 1 | /* |
hannesw@991 | 2 | * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. |
hannesw@991 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
hannesw@991 | 4 | * |
hannesw@991 | 5 | * This code is free software; you can redistribute it and/or modify it |
hannesw@991 | 6 | * under the terms of the GNU General Public License version 2 only, as |
hannesw@991 | 7 | * published by the Free Software Foundation. |
hannesw@991 | 8 | * |
hannesw@991 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
hannesw@991 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
hannesw@991 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
hannesw@991 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
hannesw@991 | 13 | * accompanied this code). |
hannesw@991 | 14 | * |
hannesw@991 | 15 | * You should have received a copy of the GNU General Public License version |
hannesw@991 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
hannesw@991 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
hannesw@991 | 18 | * |
hannesw@991 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
hannesw@991 | 20 | * or visit www.oracle.com if you need additional information or have any |
hannesw@991 | 21 | * questions. |
hannesw@991 | 22 | */ |
hannesw@991 | 23 | |
hannesw@991 | 24 | /** |
hannesw@991 | 25 | * JDK-8051889: Implement block scoping in symbol assignment and scope computation |
hannesw@991 | 26 | * |
hannesw@991 | 27 | * @test |
hannesw@991 | 28 | * @run |
hannesw@991 | 29 | * @option --language=es6 */ |
hannesw@991 | 30 | |
hannesw@991 | 31 | "use strict"; |
hannesw@991 | 32 | |
hannesw@991 | 33 | function f() { |
hannesw@991 | 34 | var a; |
hannesw@991 | 35 | let b; |
hannesw@991 | 36 | const c = 0; |
hannesw@991 | 37 | |
hannesw@991 | 38 | print(a, b, c); |
hannesw@991 | 39 | |
hannesw@991 | 40 | try { |
hannesw@991 | 41 | eval("x = 1; print('x: ' + x);"); |
hannesw@991 | 42 | print("assignment to x succeeded"); |
hannesw@991 | 43 | } catch (e) { |
hannesw@991 | 44 | print(e); |
hannesw@991 | 45 | } |
hannesw@991 | 46 | try { |
hannesw@991 | 47 | eval("'use strict'; let z = 1; print('z: ' + z);"); |
hannesw@991 | 48 | print("assignment to z succeeded"); |
hannesw@991 | 49 | eval("print('z: ' + z);"); |
hannesw@991 | 50 | } catch (e) { |
hannesw@991 | 51 | print(e); |
hannesw@991 | 52 | } |
hannesw@991 | 53 | |
hannesw@991 | 54 | try { |
hannesw@991 | 55 | eval("a = 1; print(a);"); |
hannesw@991 | 56 | print("assignment to a succeeded"); |
hannesw@991 | 57 | } catch (e) { |
hannesw@991 | 58 | print(e); |
hannesw@991 | 59 | } |
hannesw@991 | 60 | print("a: " + a); |
hannesw@991 | 61 | |
hannesw@991 | 62 | try { |
hannesw@991 | 63 | eval("b = 1; print('b: ' + b);"); |
hannesw@991 | 64 | print("assignment to b succeeded"); |
hannesw@991 | 65 | } catch (e) { |
hannesw@991 | 66 | print(e); |
hannesw@991 | 67 | } |
hannesw@991 | 68 | print("b: " + b); |
hannesw@991 | 69 | |
hannesw@991 | 70 | try { |
hannesw@991 | 71 | eval("c = 1; print('c: ' + c);"); |
hannesw@991 | 72 | print("assignment to c succeeded"); |
hannesw@991 | 73 | } catch (e) { |
hannesw@991 | 74 | print(e); |
hannesw@991 | 75 | } |
hannesw@991 | 76 | print("c: " + c); |
hannesw@991 | 77 | |
hannesw@991 | 78 | eval("a = 2; let b = 3;"); |
hannesw@991 | 79 | |
hannesw@991 | 80 | try { |
hannesw@991 | 81 | print(a, b, c); |
hannesw@991 | 82 | } catch (e) { |
hannesw@991 | 83 | print(e); |
hannesw@991 | 84 | } |
hannesw@991 | 85 | |
hannesw@991 | 86 | let x; |
hannesw@991 | 87 | |
hannesw@991 | 88 | try { |
hannesw@991 | 89 | print(a, b, c, x); |
hannesw@991 | 90 | } catch (e) { |
hannesw@991 | 91 | print(e); |
hannesw@991 | 92 | } |
hannesw@991 | 93 | |
hannesw@991 | 94 | } |
hannesw@991 | 95 | |
hannesw@991 | 96 | f(); |
hannesw@991 | 97 | |
hannesw@991 | 98 | print(typeof a, typeof b, typeof c, typeof x, typeof z); |
hannesw@1271 | 99 | |
hannesw@1271 | 100 | let v = 1; |
hannesw@1271 | 101 | eval("print('v: ' + v); v = 2; print ('v: ' + v);"); |
hannesw@1271 | 102 | print("this.v: " + this.v); |
hannesw@1271 | 103 | print("v: " + v); |
hannesw@1271 | 104 |