initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma_2 / Exceptions / expression-001.js
1 /**
2     File Name:          expression-001.js
3     Corresponds to:     ecma/Expressions/11.12-2-n.js
4     ECMA Section:       11.12
5     Description:
6
7     The grammar for a ConditionalExpression in ECMAScript is a little bit
8     different from that in C and Java, which each allow the second
9     subexpression to be an Expression but restrict the third expression to
10     be a ConditionalExpression.  The motivation for this difference in
11     ECMAScript is to allow an assignment expression to be governed by either
12     arm of a conditional and to eliminate the confusing and fairly useless
13     case of a comma expression as the center expression.
14
15     Author:             christine@netscape.com
16     Date:               09 september 1998
17 */
18     var SECTION = "expression-001";
19     var VERSION = "JS1_4";
20     var TITLE   = "Conditional operator ( ? : )"
21     startTest();
22     writeHeaderToLog( SECTION + " " + TITLE );
23
24     var tc = 0;
25     var testcases = new Array();
26
27     // the following expression should be an error in JS.
28
29     var result = "Failed"
30     var exception = "No exception was thrown";
31
32     try {
33         eval("var MY_VAR = true ? \"EXPR1\", \"EXPR2\" : \"EXPR3\"");
34     } catch ( e ) {
35         result = "Passed";
36         exception = e.toString();
37     }
38
39     testcases[tc++] = new TestCase(
40         SECTION,
41         "comma expression in a conditional statement "+
42         "(threw "+ exception +")",
43         "Passed",
44         result );
45
46
47     test();