1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Expressions/11.6.1-3.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 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: 11.6.1-3.js 1.12 + ECMA Section: 11.6.1 The addition operator ( + ) 1.13 + Description: 1.14 + 1.15 + The addition operator either performs string concatenation or numeric 1.16 + addition. 1.17 + 1.18 + The production AdditiveExpression : AdditiveExpression + MultiplicativeExpression 1.19 + is evaluated as follows: 1.20 + 1.21 + 1. Evaluate AdditiveExpression. 1.22 + 2. Call GetValue(Result(1)). 1.23 + 3. Evaluate MultiplicativeExpression. 1.24 + 4. Call GetValue(Result(3)). 1.25 + 5. Call ToPrimitive(Result(2)). 1.26 + 6. Call ToPrimitive(Result(4)). 1.27 + 7. If Type(Result(5)) is String or Type(Result(6)) is String, go to step 12. 1.28 + (Note that this step differs from step 3 in the algorithm for comparison 1.29 + for the relational operators in using or instead of and.) 1.30 + 8. Call ToNumber(Result(5)). 1.31 + 9. Call ToNumber(Result(6)). 1.32 + 10. Apply the addition operation to Result(8) and Result(9). See the discussion below (11.6.3). 1.33 + 11. Return Result(10). 1.34 + 12. Call ToString(Result(5)). 1.35 + 13. Call ToString(Result(6)). 1.36 + 14. Concatenate Result(12) followed by Result(13). 1.37 + 15. Return Result(14). 1.38 + 1.39 + Note that no hint is provided in the calls to ToPrimitive in steps 5 and 6. 1.40 + All native ECMAScript objects except Date objects handle the absence of a 1.41 + hint as if the hint Number were given; Date objects handle the absence of a 1.42 + hint as if the hint String were given. Host objects may handle the absence 1.43 + of a hint in some other manner. 1.44 + 1.45 + This test does only covers cases where the Additive or Mulplicative expression 1.46 + is a Date. 1.47 + 1.48 + Author: christine@netscape.com 1.49 + Date: 12 november 1997 1.50 +*/ 1.51 +var SECTION = "11.6.1-3"; 1.52 +var VERSION = "ECMA_1"; 1.53 +startTest(); 1.54 + 1.55 +writeHeaderToLog( SECTION + " The Addition operator ( + )"); 1.56 + 1.57 +// tests for boolean primitive, boolean object, Object object, a "MyObject" whose value is 1.58 +// a boolean primitive and a boolean object. 1.59 + 1.60 +var DATE1 = new Date(); 1.61 + 1.62 +new TestCase( SECTION, 1.63 + "var DATE1 = new Date(); DATE1 + DATE1", 1.64 + DATE1.toString() + DATE1.toString(), 1.65 + DATE1 + DATE1 ); 1.66 + 1.67 +new TestCase( SECTION, 1.68 + "var DATE1 = new Date(); DATE1 + 0", 1.69 + DATE1.toString() + 0, 1.70 + DATE1 + 0 ); 1.71 + 1.72 +new TestCase( SECTION, 1.73 + "var DATE1 = new Date(); DATE1 + new Number(0)", 1.74 + DATE1.toString() + 0, 1.75 + DATE1 + new Number(0) ); 1.76 + 1.77 +new TestCase( SECTION, 1.78 + "var DATE1 = new Date(); DATE1 + true", 1.79 + DATE1.toString() + "true", 1.80 + DATE1 + true ); 1.81 + 1.82 +new TestCase( SECTION, 1.83 + "var DATE1 = new Date(); DATE1 + new Boolean(true)", 1.84 + DATE1.toString() + "true", 1.85 + DATE1 + new Boolean(true) ); 1.86 + 1.87 +new TestCase( SECTION, 1.88 + "var DATE1 = new Date(); DATE1 + new Boolean(true)", 1.89 + DATE1.toString() + "true", 1.90 + DATE1 + new Boolean(true) ); 1.91 + 1.92 +var MYOB1 = new MyObject( DATE1 ); 1.93 + 1.94 +new TestCase( SECTION, 1.95 + "MYOB1 = new MyObject(DATE1); MYOB1 + new Number(1)", 1.96 + "[object Object]1", 1.97 + MYOB1 + new Number(1) ); 1.98 + 1.99 +new TestCase( SECTION, 1.100 + "MYOB1 = new MyObject(DATE1); MYOB1 + 1", 1.101 + "[object Object]1", 1.102 + MYOB1 + 1 ); 1.103 + 1.104 +new TestCase( SECTION, 1.105 + "MYOB1 = new MyObject(DATE1); MYOB1 + true", 1.106 + "[object Object]true", 1.107 + MYOB1 + true ); 1.108 + 1.109 +test(); 1.110 + 1.111 +function MyPrototypeObject(value) { 1.112 + this.valueOf = new Function( "return this.value;" ); 1.113 + this.toString = new Function( "return (this.value + '');" ); 1.114 + this.value = value; 1.115 +} 1.116 +function MyObject( value ) { 1.117 + this.valueOf = new Function( "return this.value" ); 1.118 + this.value = value; 1.119 +}