1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is JavaScript Engine testing utilities.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corp.
18 * Portions created by the Initial Developer are Copyright (C) 2003
19 * the Initial Developer. All Rights Reserved.
22 * bzbarsky@mit.edu, pschwartau@netscape.com
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK *****
40 * SUMMARY: Testing left-associativity of the + operator
42 * See ECMA-262 Ed.3, Section 11.6.1, "The Addition operator"
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=196290
45 * The upshot: |a + b + c| should always equal |(a + b) + c|
48 //-----------------------------------------------------------------------------
51 var summary = 'Testing left-associativity of the + operator';
55 var actualvalues = [];
57 var expectedvalues = [];
60 status = inSection(1);
61 actual = 1 + 1 + 'px';
65 status = inSection(2);
66 actual = 'px' + 1 + 1;
70 status = inSection(3);
71 actual = 1 + 1 + 1 + 'px';
75 status = inSection(4);
76 actual = 1 + 1 + 'a' + 1 + 1 + 'b';
81 * The next sections test the + operator via eval()
83 status = inSection(5);
84 actual = sumThese(1, 1, 'a', 1, 1, 'b');
88 status = inSection(6);
89 actual = sumThese(new Number(1), new Number(1), 'a');
93 status = inSection(7);
94 actual = sumThese('a', new Number(1), new Number(1));
100 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
108 statusitems[UBound] = status;
109 actualvalues[UBound] = actual;
110 expectedvalues[UBound] = expect;
115 * Applies the + operator to the provided arguments via eval().
117 * Form an eval string of the form 'arg1 + arg2 + arg3', but
118 * remember to add double-quotes inside the eval string around
119 * any argument that is of string type. For example, suppose the
120 * arguments were 11, 'a', 22. Then the eval string should be
122 * arg1 + quoteThis(arg2) + arg3
124 * If we didn't put double-quotes around the string argument,
125 * we'd get this for an eval string:
129 * If we eval() this, we get 'ReferenceError: a is not defined'.
130 * With proper quoting, we get eval('11 + "a" + 22') as desired.
138 var L = arguments.length;
142 if (typeof arg === 'string')
143 arg = quoteThis(arg);
146 sEval += arg + ' + ';
155 function quoteThis(x)
157 return '"' + x + '"';
165 printStatus(summary);
167 for (var i=0; i<UBound; i++)
169 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);