1 /* The contents of this file are subject to the Netscape Public 2 * License Version 1.1 (the "License"); you may not use this file 3 * except in compliance with the License. You may obtain a copy of 4 * the License at http://www.mozilla.org/NPL/ 5 * 6 * Software distributed under the License is distributed on an "AS 7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 8 * implied. See the License for the specific language governing 9 * rights and limitations under the License. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 14 * The Initial Developer of the Original Code is Netscape Communications 15 * Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22 /** 23 File Name: 11.12.js 24 ECMA Section: 11.12 Conditional Operator 25 Description: 26 Logi 27 28 calORExpression ? AssignmentExpression : AssignmentExpression 29 30 Semantics 31 32 The production ConditionalExpression : 33 LogicalORExpression ? AssignmentExpression : AssignmentExpression 34 is evaluated as follows: 35 36 1. Evaluate LogicalORExpression. 37 2. Call GetValue(Result(1)). 38 3. Call ToBoolean(Result(2)). 39 4. If Result(3) is false, go to step 8. 40 5. Evaluate the first AssignmentExpression. 41 6. Call GetValue(Result(5)). 42 7. Return Result(6). 43 8. Evaluate the second AssignmentExpression. 44 9. Call GetValue(Result(8)). 45 10. Return Result(9). 46 47 Author: christine (at) netscape.com 48 Date: 12 november 1997 49 */ 50 var SECTION = "11.12"; 51 var VERSION = "ECMA_1"; 52 startTest(); 53 var testcases = getTestCases(); 54 55 writeHeaderToLog( SECTION + " Conditional operator( ? : )"); 56 test(); 57 function getTestCases() { 58 var array = new Array(); 59 var item = 0; 60 61 array[item++] = new TestCase( SECTION, "true ? 'PASSED' : 'FAILED'", "PASSED", (true?"PASSED":"FAILED")); 62 array[item++] = new TestCase( SECTION, "false ? 'FAILED' : 'PASSED'", "PASSED", (false?"FAILED":"PASSED")); 63 64 array[item++] = new TestCase( SECTION, "1 ? 'PASSED' : 'FAILED'", "PASSED", (true?"PASSED":"FAILED")); 65 array[item++] = new TestCase( SECTION, "0 ? 'FAILED' : 'PASSED'", "PASSED", (false?"FAILED":"PASSED")); 66 array[item++] = new TestCase( SECTION, "-1 ? 'PASSED' : 'FAILED'", "PASSED", (true?"PASSED":"FAILED")); 67 68 array[item++] = new TestCase( SECTION, "NaN ? 'FAILED' : 'PASSED'", "PASSED", (Number.NaN?"FAILED":"PASSED")); 69 70 array[item++] = new TestCase( SECTION, "var VAR = true ? , : 'FAILED'", "PASSED", (VAR = true ? "PASSED" : "FAILED") ); 71 72 return ( array ); 73 } 74 function test() { 75 for ( tc=0; tc < testcases.length; tc++ ) { 76 testcases[tc].passed = writeTestCaseResult( 77 testcases[tc].expect, 78 testcases[tc].actual, 79 testcases[tc].description +" = "+ 80 testcases[tc].actual ); 81 82 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 83 } 84 stopTest(); 85 return ( testcases ); 86 } 87