blob: 1a53da06644a7bdc4533c10aae7f5b35e2511df6 [file] [log] [blame]
keith_miller@apple.combcc77f22016-07-15 06:03:25 +00001// Copyright 2009 the Sputnik authors. All rights reserved.
2// This code is governed by the BSD license found in the LICENSE file.
3
4/*---
5info: >
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
9es5id: 12.2_A1
10description: Creating variables after entering the execution scope
11---*/
12
13//////////////////////////////////////////////////////////////////////////////
14//CHECK#1
15try {
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 $ERROR('#1: Using declarated variable before it declaration is admitted');
21}
22//
23//////////////////////////////////////////////////////////////////////////////
24
25//////////////////////////////////////////////////////////////////////////////
26//CHECK#2
27assert.throws(ReferenceError, function() {
28 __something__undefined = __something__undefined;
29});
30//
31//////////////////////////////////////////////////////////////////////////////
32
33//////////////////////////////////////////////////////////////////////////////
34//CHECK#3
35if ((__y !== "liar")&(__z !== 1)) {
36 $ERROR('#3: (__y === "liar") and (__z === 1). Actual: __y ==='+__y+' and __z ==='+__z );
37}
38//
39//////////////////////////////////////////////////////////////////////////////
40
41var __x, __y = true, __z = __y ? "smeagol" : "golum";
42
43//////////////////////////////////////////////////////////////////////////////
44//CHECK#4
45if (!__y&!(__z = "smeagol")) {
46 $ERROR('#4: A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed');
47}
48//
49//////////////////////////////////////////////////////////////////////////////