michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * Variables are created when the program is entered. Variables are initialised to "undefined" michael@0: * when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the michael@0: * VariableStatement is executed, not when the variable is created michael@0: * michael@0: * @path ch12/12.2/S12.2_A1.js michael@0: * @description Creating variables after entering the execution scope michael@0: */ michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#1 michael@0: try { michael@0: __x = __x; michael@0: __y = __x ? "good fellow" : "liar"; // __y assigned to "liar" since __x undefined michael@0: __z = __z === __x ? 1 : 0; // __z assigned to 1 since both __x and __z are undefined michael@0: } catch (e) { michael@0: $ERROR('#1: Using declarated variable before it declaration is admitted'); michael@0: } michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#2 michael@0: try{ michael@0: __something__undefined = __something__undefined; michael@0: $ERROR('#2: "__something__undefined = __something__undefined" lead to throwing exception'); michael@0: } catch(e){ michael@0: $PRINT(e.message); michael@0: } michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#3 michael@0: if ((__y !== "liar")&(__z !== 1)) { michael@0: $ERROR('#3: (__y === "liar") and (__z === 1). Actual: __y ==='+__y+' and __z ==='+__z ); michael@0: } michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: var __x, __y = true, __z = __y ? "smeagol" : "golum"; michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#4 michael@0: if (!__y&!(__z = "smeagol")) { michael@0: $ERROR('#4: A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed'); michael@0: } michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: