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