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 16function check_syntax_error(code) 17{ 18 try { 19 eval(code); 20 assert(false); 21 } catch (e) { 22 assert(e instanceof SyntaxError); 23 } 24} 25 26check_syntax_error("try {} catch() {}"); 27check_syntax_error("try {} catch([a] {}"); 28check_syntax_error("try {} catch([a] = [1]) {}"); 29check_syntax_error("try {} catch({a} = {a:1}) {}"); 30check_syntax_error("try {} catch(a,) {}"); 31check_syntax_error("try {} catch(a) { function a() {} }"); 32check_syntax_error("try {} catch(a) { { function a() {} } function a() {} }"); 33check_syntax_error("try {} catch([a]) { var a }"); 34check_syntax_error("try {} catch([a]) { { var a } }"); 35check_syntax_error("try {} catch([a]) { function a() {} }"); 36 37try { 38 throw [1,2] 39 assert(false) 40} catch ([a, b]) { 41 assert(a === 1) 42 assert(b === 2) 43} 44 45try { 46 throw { x:1, y:2 } 47 assert(false) 48} catch ({x, 'y':b}) { 49 assert(x === 1) 50 assert(b === 2) 51} 52 53try { 54 throw [1,2] 55 assert(false) 56} catch ([a, b]) { 57 eval("assert(a === 1)") 58 eval("assert(b === 2)") 59} 60 61try { 62 throw { x:1, y:2 } 63 assert(false) 64} catch ({x, 'y':b}) { 65 eval("assert(x === 1)") 66 eval("assert(b === 2)") 67} 68 69try { 70 try { 71 throw [] 72 assert(false) 73 } catch ([a = b, b]) { 74 assert(false) 75 } 76} catch (e) { 77 assert(e instanceof ReferenceError) 78} 79 80try { 81 throw [{a : 5}]; 82} catch([{a}]) { 83 assert(a === 5); 84} 85 86var catchReached = false; 87try { 88 throw [{}]; 89 assert(false); 90} catch([{}]) { 91 catchReached = true; 92} 93 94assert(catchReached); 95