test/script/basic/es6/let-const-switch.js

Thu, 27 Nov 2014 18:02:28 +0100

author
hannesw
date
Thu, 27 Nov 2014 18:02:28 +0100
changeset 1109
f39081a16f71
permissions
-rw-r--r--

8057980: let & const: remaining issues with lexical scoping
Reviewed-by: lagergren, attila

hannesw@1109 1 /*
hannesw@1109 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
hannesw@1109 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
hannesw@1109 4 *
hannesw@1109 5 * This code is free software; you can redistribute it and/or modify it
hannesw@1109 6 * under the terms of the GNU General Public License version 2 only, as
hannesw@1109 7 * published by the Free Software Foundation.
hannesw@1109 8 *
hannesw@1109 9 * This code is distributed in the hope that it will be useful, but WITHOUT
hannesw@1109 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
hannesw@1109 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
hannesw@1109 12 * version 2 for more details (a copy is included in the LICENSE file that
hannesw@1109 13 * accompanied this code).
hannesw@1109 14 *
hannesw@1109 15 * You should have received a copy of the GNU General Public License version
hannesw@1109 16 * 2 along with this work; if not, write to the Free Software Foundation,
hannesw@1109 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
hannesw@1109 18 *
hannesw@1109 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
hannesw@1109 20 * or visit www.oracle.com if you need additional information or have any
hannesw@1109 21 * questions.
hannesw@1109 22 */
hannesw@1109 23
hannesw@1109 24 /**
hannesw@1109 25 * JDK-8057980: let & const: remaining issues with lexical scoping
hannesw@1109 26 *
hannesw@1109 27 * @test
hannesw@1109 28 * @run
hannesw@1109 29 * @option --language=es6
hannesw@1109 30 */
hannesw@1109 31
hannesw@1109 32 function tryEval(s) {
hannesw@1109 33 try {
hannesw@1109 34 eval(s);
hannesw@1109 35 } catch (e) {
hannesw@1109 36 print(String(e).replace(/\\/g, "/"));
hannesw@1109 37 }
hannesw@1109 38 }
hannesw@1109 39
hannesw@1109 40 tryEval('var x = 0; switch (x) { case 0: { let x = 1; print(x); } case 1: { let x = 2; print(x); }} print(x);');
hannesw@1109 41 tryEval('var x = 0; switch (x) { case 0: { const x = 1; print(x); } case 1: { const x = 2; print(x); }} print(x);');
hannesw@1109 42
hannesw@1109 43 // TODO: the following should not throw
hannesw@1109 44 tryEval('switch (x) { case 0: let x = 1; }');
hannesw@1109 45 tryEval('switch (x) { case 0: const x = 1; }');

mercurial