1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Exceptions/expression-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: expression-001.js 1.12 + Corresponds to: ecma/Expressions/11.12-2-n.js 1.13 + ECMA Section: 11.12 1.14 + Description: 1.15 + 1.16 + The grammar for a ConditionalExpression in ECMAScript is a little bit 1.17 + different from that in C and Java, which each allow the second 1.18 + subexpression to be an Expression but restrict the third expression to 1.19 + be a ConditionalExpression. The motivation for this difference in 1.20 + ECMAScript is to allow an assignment expression to be governed by either 1.21 + arm of a conditional and to eliminate the confusing and fairly useless 1.22 + case of a comma expression as the center expression. 1.23 + 1.24 + Author: christine@netscape.com 1.25 + Date: 09 september 1998 1.26 +*/ 1.27 +var SECTION = "expression-001"; 1.28 +var VERSION = "JS1_4"; 1.29 +var TITLE = "Conditional operator ( ? : )" 1.30 + startTest(); 1.31 +writeHeaderToLog( SECTION + " " + TITLE ); 1.32 + 1.33 +// the following expression should be an error in JS. 1.34 + 1.35 +var result = "Failed" 1.36 + var exception = "No exception was thrown"; 1.37 + 1.38 +try { 1.39 + eval("var MY_VAR = true ? \"EXPR1\", \"EXPR2\" : \"EXPR3\""); 1.40 +} catch ( e ) { 1.41 + result = "Passed"; 1.42 + exception = e.toString(); 1.43 +} 1.44 + 1.45 +new TestCase( 1.46 + SECTION, 1.47 + "comma expression in a conditional statement "+ 1.48 + "(threw "+ exception +")", 1.49 + "Passed", 1.50 + result ); 1.51 + 1.52 + 1.53 +test();