mirror of https://github.com/tc39/test262.git
94 lines
9.9 KiB
JSON
94 lines
9.9 KiB
JSON
{
|
|
"testCollection": {
|
|
"name": "12.13_The_throw_statement",
|
|
"numTests": 14,
|
|
"tests": [
|
|
{
|
|
"section": "12.13",
|
|
"description": "Trying to throw exception with \"throw\"",
|
|
"negative": "",
|
|
"test": "throw \"error\";\n",
|
|
"id": "S12.13_A1"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Throwing undefined",
|
|
"test": "// CHECK#1\ntry{\n throw undefined;\n}\ncatch(e){\n if (e!==undefined) $ERROR('#1: Exception === undefined. Actual: Exception ==='+ e );\n}\n",
|
|
"id": "S12.13_A2_T1"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Throwing null",
|
|
"test": "// CHECK#1\ntry{\n throw null;\n}\ncatch(e){\n if (e!==null) $ERROR('#1: Exception === null. Actual: Exception ==='+ e );\n}\n",
|
|
"id": "S12.13_A2_T2"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Throwing boolean",
|
|
"test": "// CHECK#1\ntry{\n throw true;\n}\ncatch(e){\n if (e!==true) $ERROR('#1: Exception ===true. Actual: Exception ==='+ e );\n}\n\n// CHECK#2\ntry{\n throw false;\n}\ncatch(e){\n if (e!==false) $ERROR('#2: Exception ===false. Actual: Exception ==='+ e );\n}\n\n// CHECK#3\nvar b=false;\ntry{\n throw b;\n}\ncatch(e){\n if (e!==false) $ERROR('#3: Exception ===false. Actual: Exception ==='+ e );\n}\n\n// CHECK#4\nvar b=true;\ntry{\n throw b;\n}\ncatch(e){\n if (e!==true) $ERROR('#4: Exception ===true. Actual: Exception ==='+ e );\n}\n",
|
|
"id": "S12.13_A2_T3"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Throwing string",
|
|
"test": "// CHECK#1\ntry{\n throw \"exception #1\";\n}\ncatch(e){\n if (e!==\"exception #1\") $ERROR('#1: Exception ===\"exception #1\". Actual: Exception ==='+ e );\n}\n\n// CHECK#2\nvar b=\"exception #1\";\ntry{\n throw b;\n}\ncatch(e){\n if (e!==\"exception #1\") $ERROR('#2: Exception ===\"exception #1\". Actual: Exception ==='+ e );\n}\n",
|
|
"id": "S12.13_A2_T4"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Throwing number",
|
|
"test": "// CHECK#1\ntry{\n throw 13;\n}\ncatch(e){\n if (e!==13) $ERROR('#1: Exception ===13. Actual: Exception ==='+ e );\n}\n\n// CHECK#2\nvar b=13;\ntry{\n throw b;\n}\ncatch(e){\n if (e!==13) $ERROR('#2: Exception ===13. Actual: Exception ==='+ e );\n}\n\n// CHECK#3\ntry{\n throw 2.13;\n}\ncatch(e){\n if (e!==2.13) $ERROR('#3: Exception ===2.13. Actual: Exception ==='+ e );\n}\n\n// CHECK#4\ntry{\n throw NaN;\n}\ncatch(e){\n if (!isNaN(e)) $ERROR('#4: Exception is NaN');\n}\n\n// CHECK#5\ntry{\n throw +Infinity;\n}\ncatch(e){\n if (e!==+Infinity) $ERROR('#5: Exception ===+Infinity. Actual: Exception ==='+ e );\n}\n\n// CHECK#6\ntry{\n throw -Infinity;\n}\ncatch(e){\n if (e!==-Infinity) $ERROR('#6: Exception ===-Infinity. Actual: Exception ==='+ e );\n}\n\n// CHECK#7\ntry{\n throw +0;\n}\ncatch(e){\n if (e!==+0) $ERROR('#7: Exception ===+0. Actual: Exception ==='+ e );\n}\n\n// CHECK#8\ntry{\n throw -0;\n}\ncatch(e){\n if (e!==-0) $ERROR('#8: Exception ===-0. Actual: Exception ==='+ e );\n}\n",
|
|
"id": "S12.13_A2_T5"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Throwing object",
|
|
"test": "var myObj = {p1: 'a', \n p2: 'b', \n p3: 'c',\n value: 'myObj_value',\n valueOf : function(){return 'obj_valueOf';},\n parseInt : function(){return 'obj_parseInt';},\n NaN : 'obj_NaN',\n Infinity : 'obj_Infinity',\n eval : function(){return 'obj_eval';},\n parseFloat : function(){return 'obj_parseFloat';},\n isNaN : function(){return 'obj_isNaN';},\n isFinite : function(){return 'obj_isFinite';},\n i:7\n}\n\ntry{\n throw myObj;\n}\ncatch(e){\t\n// CHECK#1\n if (e.p1!==\"a\") $ERROR('#1: e.p1 === \"a\". Actual: e.p1 ==='+ e.p1 );\n// CHECK#2\n if (e.value!=='myObj_value') $ERROR('#2: e.p1 === \\'myObj_value\\'. Actual: e.p1 ==='+ e.p1 );\n// CHECK#3\n if (e.eval()!=='obj_eval') $ERROR('#3: e.p1 === \\'obj_eval\\'. Actual: e.p1 ==='+ e.p1 );\n}\n\n// CHECK#4\nmyObj.i=6\ntry{\n throw myObj;\n}\ncatch(e){}\nif (myObj.i!==6) $ERROR('#4: Handling of catch must be correct');\n",
|
|
"id": "S12.13_A2_T6"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Throwing Array",
|
|
"test": "var mycars = new Array();\nmycars[0] = \"Saab\";\nmycars[1] = \"Volvo\";\nmycars[2] = \"BMW\";\n\nvar mycars2 = new Array();\nmycars2[0] = \"Mercedes\";\nmycars2[1] = \"Jeep\";\nmycars2[2] = \"Suzuki\";\n\n// CHECK#1\ntry{\n throw mycars;\n}\ncatch(e){\n for (var i=0;i<3;i++){\n if (e[i]!==mycars[i]) $ERROR('#1.'+i+': Exception['+i+'] === mycars['+i+']. Actual: Exception['+i+'] ==='+ e[i] );\n }\n}\n",
|
|
"id": "S12.13_A2_T7"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Evaluating boolean expression",
|
|
"test": "// CHECK#1\nvar b=true;\ntry{\n throw b&&false;\n}\ncatch(e){\n if (e!==false) $ERROR('#1: Exception === false(operaton &&). Actual: Exception ==='+ e );\n}\n\n// CHECK#2\nvar b=true;\ntry{\n throw b||false;\n}\ncatch(e){\n if (e!==true) $ERROR('#2: Exception === true(operaton ||). Actual: Exception ==='+ e );\n}\n\n// CHECK#3\ntry{\n throw !false;\n}\ncatch(e){\n if (e!==true) $ERROR('#3: Exception === true(operaton !). Actual: Exception ==='+ e );\n}\n\n// CHECK#4\nvar b=true;\ntry{\n throw !(b&&false);\n}\ncatch(e){\n if (e!==true) $ERROR('#4: Exception === true(operaton &&). Actual: Exception ==='+ e );\n}\n",
|
|
"id": "S12.13_A3_T1"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Evaluating string expression",
|
|
"test": "// CHECK#1\ntry{\n throw \"exception\"+\" #1\";\n}\ncatch(e){\n if (e!==\"exception #1\") $ERROR('#1: Exception === \"exception #1\"(operaton +). Actual: Exception ==='+ e );\n}\n\n// CHECK#2\nvar b=\"exception\"\nvar a=\" #1\";\ntry{\n throw b+a;\n}\ncatch(e){\n if (e!==\"exception #1\") $ERROR('#2: Exception === \"exception #1\"(operaton +). Actual: Exception ==='+ e );\n}\n",
|
|
"id": "S12.13_A3_T2"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Evaluating number expression",
|
|
"test": "// CHECK#1\ntry{\n throw 10+3;\n}\ncatch(e){\n if (e!==13) $ERROR('#1: Exception ===13(operaton +). Actual: Exception ==='+ e);\n}\n\n// CHECK#2\nvar b=10;\nvar a=3;\ntry{\n throw a+b;\n}\ncatch(e){\n if (e!==13) $ERROR('#2: Exception ===13(operaton +). Actual: Exception ==='+ e);\n}\n\n// CHECK#3\ntry{\n throw 3.15-1.02;\n}\ncatch(e){\n if (e!==2.13) $ERROR('#3: Exception ===2.13(operaton -). Actual: Exception ==='+ e);\n}\n\n// CHECK#4\ntry{\n throw 2*2;\n}\ncatch(e){\n if (e!==4) $ERROR('#4: Exception ===4(operaton *). Actual: Exception ==='+ e);\n}\n\n// CHECK#5\ntry{\n throw 1+Infinity;\n}\ncatch(e){\n if (e!==+Infinity) $ERROR('#5: Exception ===+Infinity(operaton +). Actual: Exception ==='+ e);\n}\n\n// CHECK#6\ntry{\n throw 1-Infinity;\n}\ncatch(e){\n if (e!==-Infinity) $ERROR('#6: Exception ===-Infinity(operaton -). Actual: Exception ==='+ e);\n}\n\n// CHECK#7\ntry{\n throw 10/5;\n}\ncatch(e){\n if (e!==2) $ERROR('#7: Exception ===2(operaton /). Actual: Exception ==='+ e);\n}\n\n// CHECK#8\ntry{\n throw 8>>2;\n}\ncatch(e){\n if (e!==2) $ERROR('#8: Exception ===2(operaton >>). Actual: Exception ==='+ e);\n}\n\n// CHECK#9\ntry{\n throw 2<<2;\n}\ncatch(e){\n if (e!==8) $ERROR('#9: Exception ===8(operaton <<). Actual: Exception ==='+ e);\n}\n\n// CHECK#10\ntry{\n throw 123%100;\n}\ncatch(e){\n if (e!==23) $ERROR('#10: Exception ===23(operaton %). Actual: Exception ==='+ e);\n}\n",
|
|
"id": "S12.13_A3_T3"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Evaluating array expression",
|
|
"test": "var mycars = new Array();\nmycars[0] = \"Saab\";\nmycars[1] = \"Volvo\";\nmycars[2] = \"BMW\";\n\nvar mycars2 = new Array();\nmycars2[0] = \"Mercedes\";\nmycars2[1] = \"Jeep\";\nmycars2[2] = \"Suzuki\";\n\n// CHECK#1\ntry{\n throw mycars.concat(mycars2);\n}\ncatch(e){\n for (var i=0;i<3;i++){\n if (e[i]!==mycars[i]) $ERROR('#1.'+i+': Exception['+i+']===mycars['+i+'](operation .concat). Actual: Exception['+i+']==='+ e[i] );\n }\n for (var i=3;i<6;i++){\n if (e[i]!==mycars2[i-3]) $ERROR('#1.'+i+': Exception['+i+']===mycars2['+(i-3)+'](operation .concat). Actual: Exception['+i+']==='+ e[i] );\n }\n}\n\n// CHECK#2\ntry{\n throw new Array(\"Mercedes\",\"Jeep\",\"Suzuki\");\n}\ncatch(e){\n for (var i=0;i<3;i++){\n if (e[i]!==mycars2[i]) $ERROR('#2.'+i+': Exception['+i+']===mycars2['+i+'](operation new). Actual: Exception['+i+']==='+ e[i] );\n }\n}\n\n// CHECK#3\ntry{\n throw mycars.concat(new Array(\"Mercedes\",\"Jeep\",\"Suzuki\"));\n}\ncatch(e){\n for (var i=0;i<3;i++){\n if (e[i]!==mycars[i]) $ERROR('#3.'+i+': Exception['+i+']===mycars['+i+'](operation .concat(new)). Actual: Exception['+i+']==='+ e[i] );\n }\n for (var i=3;i<6;i++){\n if (e[i]!==mycars2[i-3]) $ERROR('#3.'+i+': Exception['+i+']===mycars2['+(i-3)+'](operation .concat(new)). Actual: Exception['+i+']==='+ e[i] );\n }\n}\n",
|
|
"id": "S12.13_A3_T4"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Evaluating equation expression",
|
|
"test": "// CHECK#1\nvar a=true;\nvar b=false;\ntry{\n throw ((a&&(!b))?\"exception\":\" #1\");\n}\ncatch(e){\n if (e!==\"exception\") $ERROR('#1: Exception ===\"exception\"(operaton ? , ). Actual: Exception ==='+e );\n}\n",
|
|
"id": "S12.13_A3_T5"
|
|
},
|
|
{
|
|
"section": "12.13",
|
|
"description": "Evaluating functions",
|
|
"test": "// CHECK#1\nvar i=0;\nfunction adding1(){\n i++;\n return 1;\n}\ntry{\n throw (adding1());\n}\ncatch(e){\n if (e!==1) $ERROR('#1: Exception ===1. Actual: Exception ==='+ e);\n}\n\n// CHECK#2\nvar i=0;\nfunction adding2(){\n i++;\n return i;\n}\ntry{\n throw adding2();\n}\ncatch(e){}\nif (i!==1) $ERROR('#2: i===1. Actual: i==='+ i);\n\n// CHECK#3\nvar i=0;\nfunction adding3(){\n i++;\n}\ntry{\n throw adding3();\n}\ncatch(e){}\nif (i!==1) $ERROR('#3: i===1. Actual: i==='+i);\n\n// CHECK#4\nfunction adding4(i){\n i++;\n return i;\n}\ntry{\n throw (adding4(1));\n}\ncatch(e){\n if (e!==2) $ERROR('#4: Exception ===2. Actual: Exception ==='+ e);\n}\n",
|
|
"id": "S12.13_A3_T6"
|
|
}
|
|
]
|
|
}
|
|
}
|