test/script/basic/es6/const-reassign.js

Thu, 09 Mar 2017 10:25:09 -0800

author
asaha
date
Thu, 09 Mar 2017 10:25:09 -0800
changeset 2149
7355caa4e6cb
parent 1243
2b51c0b3f463
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2010, 2014, 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-8051889: Implement block scoping in symbol assignment and scope computation
    26  *
    27  * @test
    28  * @run
    29  * @option --language=es6 */
    31 "use strict";
    33 try {
    34     const x = 2;
    35     x = 1;
    36     fail("const assignment didn't throw");
    37 } catch (e) {
    38     print(e);
    39 }
    41 try {
    42     const x = 2;
    43     x++;
    44     fail("const assignment didn't throw");
    45 } catch (e) {
    46     print(e);
    47 }
    49 try {
    50     const x = 2;
    51     x--;
    52     fail("const assignment didn't throw");
    53 } catch (e) {
    54     print(e);
    55 }
    57 try {
    58     const x = 2;
    59     ++x;
    60     fail("const assignment didn't throw");
    61 } catch (e) {
    62     print(e);
    63 }
    65 try {
    66     const x = 2;
    67     --x;
    68     fail("const assignment didn't throw");
    69 } catch (e) {
    70     print(e);
    71 }
    73 try {
    74     const x = 2;
    75     x += 1;
    76     fail("const assignment didn't throw");
    77 } catch (e) {
    78     print(e);
    79 }
    81 try {
    82     const x = 2;
    83     x *= 1;
    84     fail("const assignment didn't throw");
    85 } catch (e) {
    86     print(e);
    87 }
    89 try {
    90     const x = 2;
    91     x /= 1;
    92     fail("const assignment didn't throw");
    93 } catch (e) {
    94     print(e);
    95 }
    97 try {
    98     const x = 2;
    99     x %= 1;
   100     fail("const assignment didn't throw");
   101 } catch (e) {
   102     print(e);
   103 }
   105 try {
   106     const x = 2;
   107     x |= 1;
   108     fail("const assignment didn't throw");
   109 } catch (e) {
   110     print(e);
   111 }
   113 try {
   114     const x = 2;
   115     x &= 1;
   116     fail("const assignment didn't throw");
   117 } catch (e) {
   118     print(e);
   119 }
   121 try {
   122     const x = 2;
   123     x ^= 1;
   124     fail("const assignment didn't throw");
   125 } catch (e) {
   126     print(e);
   127 }
   129 try {
   130     const x = 2;
   131     x <<= 1;
   132     fail("const assignment didn't throw");
   133 } catch (e) {
   134     print(e);
   135 }
   137 try {
   138     const x = 2;
   139     x >>= 1;
   140     fail("const assignment didn't throw");
   141 } catch (e) {
   142     print(e);
   143 }
   145 try {
   146     const x = 2;
   147     x >>>= 1;
   148     fail("const assignment didn't throw");
   149 } catch (e) {
   150     print(e);
   151 }
   153 try {
   154     const x = 2;
   155     delete x;
   156     fail("const assignment didn't throw");
   157 } catch (e) {
   158     print(e);
   159 }
   161 const c = 1;
   163 try {
   164     c = 2;
   165     fail("const assignment didn't throw");
   166 } catch (e) {
   167     print(e);
   168 }
   170 (function() {
   171     try {
   172         c = 2;
   173         fail("const assignment didn't throw");
   174     } catch (e) {
   175         print(e);
   176     }
   177 })();

mercurial