mirror of https://github.com/tc39/test262.git
137 lines
13 KiB
JSON
137 lines
13 KiB
JSON
{
|
|
"testCollection": {
|
|
"name": "12.2_Variable_Statement",
|
|
"numTests": 20,
|
|
"tests": [
|
|
{
|
|
"section": "12.2",
|
|
"description": "Creating variables after entering the execution scope",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry {\n\t__x = __x;\n __y = __x ? \"good fellow\" : \"liar\"; // __y assigned to \"liar\" since __x undefined\n __z = __z === __x ? 1 : 0; // __z assigned to 1 since both __x and __z are undefined\n} catch (e) {\n\t$ERROR('#1: Using declarated variable before it declaration is admitted');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#2\ntry{\n __something__undefined = __something__undefined;\n $ERROR('#2: \"__something__undefined = __something__undefined\" lead to throwing exception');\n} catch(e){\n $PRINT(e.message);\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#3\nif ((__y !== \"liar\")&(__z !== 1)) {\n\t$ERROR('#3: (__y === \"liar\") and (__z === 1). Actual: __y ==='+__y+' and __z ==='+__z );\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\nvar __x, __y = true, __z = __y ? \"smeagol\" : \"golum\";\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#4\nif (!__y&!(__z = \"smeagol\")) {\n\t$ERROR('#4: A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A1"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Declaring variable within a \"for\" IterationStatement",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry {\n\t__ind=__ind;\n} catch (e) {\n $ERROR('#1: var inside \"for\" is admitted '+e.message);\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\nfor (var __ind;;){\n break;\n}\n",
|
|
"id": "S12.2_A10"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Changing variable value using property attributes",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nthis['__declared__var'] = \"baloon\";\nif (this['__declared__var'] !== \"baloon\") {\n\t$ERROR('#1: this[\\'__declared__var\\'] === \"baloon\". Actual: this[\\'__declared__var\\'] ==='+ this['__declared__var'] );\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#2\nif (__declared__var !== \"baloon\") {\n\t$ERROR('#2: __declared__var === \"baloon\". Actual: __declared__var ==='+ __declared__var );\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\nvar __declared__var;\n",
|
|
"id": "S12.2_A11"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Declaring variable within \"do-while\" statement",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry {\n\tx=x;\n} catch (e) {\n\t$ERROR('#1: Declaration variable inside \"do-while\" statement is admitted');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\ndo var x; while (false);\n",
|
|
"id": "S12.2_A12"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if deleting global variables that have the attributes {DontDelete} fails",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nif (delete(__variable)) {\n\t$ERROR('#1: delete(__variable)===false');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#2\nif (delete(this[\"__variable\"])) {\n\t$ERROR('#2: delete(this[\"__variable\"])===false');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n\nvar __variable;\nvar __variable = \"defined\";\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#3\nif (delete(__variable) | delete(this[\"__variable\"])) {\n\t$ERROR('#3: (delete(__variable) | delete(this[\"__variable\"]))===false' );\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#4\nif ((__variable !== \"defined\")|(this[\"__variable\"] !==\"defined\")) {\n\t$ERROR('#4: __variable === \"defined\" and this[\"__variable\"] ===\"defined\"');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n",
|
|
"id": "S12.2_A2"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Using Global scope and Function scope together",
|
|
"test": "var __var = \"OUT\";\n\n(function(){\n var __var =\"IN\";\n\t(function(){__var = \"INNER_SPACE\";})();\n\t(function(){var __var = \"INNER_SUN\";})();\n\t//////////////////////////////////////////////////////////////////////////////\n\t//CHECK#1\n if (__var !== \"INNER_SPACE\") {\n \t$ERROR('#1: __var === \"INNER_SPACE\". Actual: __var ==='+ __var );\n }\n\t//\n\t//////////////////////////////////////////////////////////////////////////////\n})();\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#2\nif (__var !== \"OUT\") {\n\t$ERROR('#2: __var === \"OUT\". Actual: __var ==='+ __var );\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\n\n(function(){\n __var =\"IN\";\n\t(function(){__var = \"INNERED\"})();\n\t(function(){var __var = \"INNAGER\"})();\n\t//////////////////////////////////////////////////////////////////////////////\n\t//CHECK#3\n if (__var!==\"INNERED\") {\n \t$ERROR('#3: __var===\"INNERED\". Actual: __var==='+ __var );\n }\n\t//\n\t//////////////////////////////////////////////////////////////////////////////\n})();\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#4\nif (__var!==\"INNERED\") {\n\t$ERROR('#4: __var===\"INNERED\". Actual: __var==='+ __var );\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A3"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Create and use unicode characters in variable Identifier",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry {\n\t__var=__var;\n} catch (e) {\n\t$ERROR('#1: Unicode characters in variable Identifier allowed');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\nvar \\u005f\\u005f\\u0076\\u0061\\u0072 = 1;\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#2\nif (__var !== 1) {\n\t$ERROR('#2: __var === 1. Actual: __var ==='+ __var );\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A4"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Executing eval(\"var x\")",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry{\n\tx=x;\n\t$ERROR('#1: \"x=x\" lead to throwing exception');\n}catch(e){\n\t$PRINT(e.message);\n};\n//\n//////////////////////////////////////////////////////////////////////////////\n\neval(\"var x\");\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#2\ntry{\n\tx=x;\n}catch(e){\n\t$ERROR('#2: VariableDeclaration inside Eval statement is initialized when program reaches the eval statement '+e.message);\n};\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A5"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Declaring variable within \"try-catch\" statement",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry{\n\tintry__var=intry__var;\n}catch(e){\n\t$ERROR('#1: Variable declaration inside \"try\" block is admitted');\n};\n//\n//////////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#2\ntry{\n\tincatch__var=incatch__var;\n}catch(e){\n\t$ERROR('#2: Variable declaration inside \"catch\" block is admitted');\n};\n//\n//////////////////////////////////////////////////////////////////////////////\n\ntry{\n var intry__var;\n}catch(e){\n var incatch__var;\n};\n",
|
|
"id": "S12.2_A6_T1"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Declaring variables within \"try-catch\" statement",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry{\n\tintry__intry__var=intry__intry__var;\n\tintry__incatch__var=intry__incatch__var;\n\tincatch__intry__var=incatch__intry__var;\n\tincatch__incatch__var=incatch__incatch__var;\n}catch(e){\n\t$ERROR('#1: Variable declaration inside \"try-catch\" block is admitted');\n};\n//\n//////////////////////////////////////////////////////////////////////////////\n\ntry{\n try {\n \tvar intry__intry__var;\n } catch (e) {\n \tvar intry__incatch__var;\n }\n}catch(e){\n try {\n \tvar incatch__intry__var;\n } catch (e) {\n var incatch__incatch__var;\n }\n \n};\n",
|
|
"id": "S12.2_A6_T2"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Declaring variable within \"for\" statement",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\ntry{\n\tinfor_var = infor_var;\n}catch(e){\n\t$ERROR('#1: Variable declaration inside \"for\" loop is admitted');\n};\n//\n//////////////////////////////////////////////////////////////////////////////\n\nfor (;;){\n break;\n var infor_var;\n}\n",
|
|
"id": "S12.2_A7"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var x += 1\" fails",
|
|
"negative": "",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar x += 1;\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A8_T1"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var x | true\" fails",
|
|
"negative": "",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar x | true;\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A8_T2"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var x && 1\" fails",
|
|
"negative": "",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar x && 1;\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A8_T3"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var x++\" fails",
|
|
"negative": "",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar x++;\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A8_T4"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var --x\" fails",
|
|
"negative": "",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar --x;\n//\n//////////////////////////////////////////////////////////////////////////////\n",
|
|
"id": "S12.2_A8_T5"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var x*1\" fails",
|
|
"negative": "",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar x*1;\n//\n//////////////////////////////////////////////////////////////////////////////\n\n",
|
|
"id": "S12.2_A8_T6"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var x>>1\" fails",
|
|
"negative": "",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar x>>1;\n//\n//////////////////////////////////////////////////////////////////////////////\n\n",
|
|
"id": "S12.2_A8_T7"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Checking if execution of \"var x in __arr\" fails",
|
|
"negative": "",
|
|
"test": "__arr = [];\n\n//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nvar x in __arr;\n//\n//////////////////////////////////////////////////////////////////////////////\n\n",
|
|
"id": "S12.2_A8_T8"
|
|
},
|
|
{
|
|
"section": "12.2",
|
|
"description": "Enumerating property attributes of \"this\" and then searching for the declared variable",
|
|
"test": "//////////////////////////////////////////////////////////////////////////////\n//CHECK#1\nfor (__prop in this){\n if (__prop === \"__declared__var\")\n enumed=true;\n}\nif (!(enumed)) {\n\t$ERROR('#1: When using property attributes, {DontEnum} not used');\n}\n//\n//////////////////////////////////////////////////////////////////////////////\n\nvar __declared__var;\n",
|
|
"id": "S12.2_A9"
|
|
}
|
|
]
|
|
}
|
|
}
|