js/src/tests/ecma_3/Expressions/11.6.1-1.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  *
     8  * Date:    14 Mar 2003
     9  * SUMMARY: Testing left-associativity of the + operator
    10  *
    11  * See ECMA-262 Ed.3, Section 11.6.1, "The Addition operator"
    12  * See http://bugzilla.mozilla.org/show_bug.cgi?id=196290
    13  *
    14  * The upshot: |a + b + c| should always equal |(a + b) + c|
    15  *
    16  */
    17 //-----------------------------------------------------------------------------
    18 var UBound = 0;
    19 var BUGNUMBER = 196290;
    20 var summary = 'Testing left-associativity of the + operator';
    21 var status = '';
    22 var statusitems = [];
    23 var actual = '';
    24 var actualvalues = [];
    25 var expect= '';
    26 var expectedvalues = [];
    29 status = inSection(1);
    30 actual = 1 + 1 + 'px';
    31 expect = '2px';
    32 addThis();
    34 status = inSection(2);
    35 actual = 'px' + 1 + 1;
    36 expect = 'px11';
    37 addThis();
    39 status = inSection(3);
    40 actual = 1 + 1 + 1 + 'px';
    41 expect = '3px';
    42 addThis();
    44 status = inSection(4);
    45 actual = 1 + 1 + 'a' + 1 + 1 + 'b';
    46 expect = '2a11b';
    47 addThis();
    49 /*
    50  * The next sections test the + operator via eval()
    51  */
    52 status = inSection(5);
    53 actual = sumThese(1, 1, 'a', 1, 1, 'b');
    54 expect = '2a11b';
    55 addThis();
    57 status = inSection(6);
    58 actual = sumThese(new Number(1), new Number(1), 'a');
    59 expect = '2a';
    60 addThis();
    62 status = inSection(7);
    63 actual = sumThese('a', new Number(1), new Number(1));
    64 expect = 'a11';
    65 addThis();
    69 //-----------------------------------------------------------------------------
    70 test();
    71 //-----------------------------------------------------------------------------
    75 function addThis()
    76 {
    77   statusitems[UBound] = status;
    78   actualvalues[UBound] = actual;
    79   expectedvalues[UBound] = expect;
    80   UBound++;
    81 }
    83 /*
    84  * Applies the + operator to the provided arguments via eval().
    85  *
    86  * Form an eval string of the form 'arg1 + arg2 + arg3', but
    87  * remember to add double-quotes inside the eval string around
    88  * any argument that is of string type. For example, suppose the
    89  * arguments were 11, 'a', 22. Then the eval string should be
    90  *
    91  *              arg1 + quoteThis(arg2) + arg3
    92  *
    93  * If we didn't put double-quotes around the string argument,
    94  * we'd get this for an eval string:
    95  *
    96  *                     '11 + a + 22'
    97  *
    98  * If we eval() this, we get 'ReferenceError: a is not defined'.
    99  * With proper quoting, we get eval('11 + "a" + 22') as desired.
   100  */
   101 function sumThese()
   102 {
   103   var sEval = '';
   104   var arg;
   105   var i;
   107   var L = arguments.length;
   108   for (i=0; i<L; i++)
   109   {
   110     arg = arguments[i];
   111     if (typeof arg === 'string')
   112       arg = quoteThis(arg);
   114     if (i < L-1)
   115       sEval += arg + ' + ';
   116     else
   117       sEval += arg;
   118   }
   120   return eval(sEval);
   121 }
   124 function quoteThis(x)
   125 {
   126   return '"' + x + '"';
   127 }
   130 function test()
   131 {
   132   enterFunc('test');
   133   printBugNumber(BUGNUMBER);
   134   printStatus(summary);
   136   for (var i=0; i<UBound; i++)
   137   {
   138     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   139   }
   141   exitFunc ('test');
   142 }

mercurial