1/* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16const a = 6 17assert(!delete a) 18assert(a === 6) 19 20try { 21 eval("a = 7") 22 assert(false) 23} catch (e) { 24 assert(e instanceof TypeError) 25} 26 27function check_type_error(code) { 28 try { 29 eval(code) 30 assert(false) 31 } catch (e) { 32 assert(e instanceof TypeError) 33 } 34} 35 36// Register cases 37check_type_error("{ const a = 0; a = 1 }"); 38check_type_error("{ const a = 0; a += 1 }"); 39check_type_error("{ const a = 0; a -= 1 }"); 40check_type_error("{ const a = 0; a *= 1 }"); 41check_type_error("{ const a = 0; a %= 1 }"); 42check_type_error("{ const a = 0; a /= 1 }"); 43check_type_error("{ const a = 0; a <<= 1 }"); 44check_type_error("{ const a = 0; a >>= 1 }"); 45check_type_error("{ const a = 0; a >>>= 1 }"); 46check_type_error("{ const a = 0; a &= 1 }"); 47check_type_error("{ const a = 0; a |= 1 }"); 48check_type_error("{ const a = 0; a ^= 1 }"); 49check_type_error("{ const a = 0; a++ }"); 50check_type_error("{ const a = 0; a-- }"); 51check_type_error("{ const a = 0; ++a }"); 52check_type_error("{ const a = 0; --a }"); 53check_type_error("{ const a = 0; [a] = [1] }"); 54check_type_error("{ const a = 0; ({a} = { a:1 }) }"); 55 56// Non-register cases 57check_type_error("{ const a = 0; (function (){ a = 1 })() }"); 58check_type_error("{ const a = 0; (function (){ a += 1 })() }"); 59check_type_error("{ const a = 0; (function (){ a -= 1 })() }"); 60check_type_error("{ const a = 0; (function (){ a *= 1 })() }"); 61check_type_error("{ const a = 0; (function (){ a %= 1 })() }"); 62check_type_error("{ const a = 0; (function (){ a /= 1 })() }"); 63check_type_error("{ const a = 0; (function (){ a <<= 1 })() }"); 64check_type_error("{ const a = 0; (function (){ a >>= 1 })() }"); 65check_type_error("{ const a = 0; (function (){ a >>>= 1 })() }"); 66check_type_error("{ const a = 0; (function (){ a &= 1 })() }"); 67check_type_error("{ const a = 0; (function (){ a |= 1 })() }"); 68check_type_error("{ const a = 0; (function (){ a ^= 1 })() }"); 69check_type_error("{ const a = 0; (function (){ a++ })() }"); 70check_type_error("{ const a = 0; (function (){ a-- })() }"); 71check_type_error("{ const a = 0; (function (){ ++a })() }"); 72check_type_error("{ const a = 0; (function (){ --a })() }"); 73check_type_error("{ const a = 0; (function (){ [a] = [1] })() }"); 74check_type_error("{ const a = 0; (function (){ ({a} = { a:1 }) })() }"); 75