| 1 |
// Copyright 2009 the Sputnik authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
info: | |
| 6 |
Variables are created when the program is entered. Variables are initialised to "undefined" |
| 7 |
when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the |
| 8 |
VariableStatement is executed, not when the variable is created |
| 9 |
es5id: 12.2_A1 |
| 10 |
description: Creating variables after entering the execution scope |
| 11 |
---*/ |
| 12 |
|
| 13 |
////////////////////////////////////////////////////////////////////////////// |
| 14 |
//CHECK#1 |
| 15 |
try { |
| 16 |
__x = __x; |
| 17 |
__y = __x ? "good fellow" : "liar"; // __y assigned to "liar" since __x undefined |
| 18 |
__z = __z === __x ? 1 : 0; // __z assigned to 1 since both __x and __z are undefined |
| 19 |
} catch (e) { |
| 20 |
throw new Test262Error('#1: Using declarated variable before it declaration is admitted'); |
| 21 |
} |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
|
| 25 |
////////////////////////////////////////////////////////////////////////////// |
| 26 |
//CHECK#2 |
| 27 |
assert.throws(ReferenceError, function() { |
| 28 |
__something__undefined = __something__undefined; |
| 29 |
}); |
| 30 |
// |
| 31 |
////////////////////////////////////////////////////////////////////////////// |
| 32 |
|
| 33 |
////////////////////////////////////////////////////////////////////////////// |
| 34 |
//CHECK#3 |
| 35 |
if ((__y !== "liar")&(__z !== 1)) { |
| 36 |
throw new Test262Error('#3: (__y === "liar") and (__z === 1). Actual: __y ==='+__y+' and __z ==='+__z ); |
| 37 |
} |
| 38 |
// |
| 39 |
////////////////////////////////////////////////////////////////////////////// |
| 40 |
|
| 41 |
var __x, __y = true, __z = __y ? "smeagol" : "golum"; |
| 42 |
|
| 43 |
////////////////////////////////////////////////////////////////////////////// |
| 44 |
//CHECK#4 |
| 45 |
if (!__y&!(__z = "smeagol")) { |
| 46 |
throw new Test262Error('#4: A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed'); |
| 47 |
} |
| 48 |
// |
| 49 |
////////////////////////////////////////////////////////////////////////////// |
| 50 |
|
| 51 |
reportCompare(0, 0); |