js/src/tests/ecma/extensions/11.6.1-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/extensions/11.6.1-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     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-1.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 not cover cases where the Additive or Mulplicative expression
    1.46 +   ToPrimitive is string.
    1.47 +
    1.48 +   Author:             christine@netscape.com
    1.49 +   Date:               12 november 1997
    1.50 +*/
    1.51 +var SECTION = "11.6.1-1";
    1.52 +var VERSION = "ECMA_1";
    1.53 +startTest();
    1.54 +
    1.55 +writeHeaderToLog( SECTION + " The Addition operator ( + )");
    1.56 +
    1.57 +// tests for "MyValuelessObject", where the value is
    1.58 +// set in the object's prototype, not the object itself.
    1.59 +
    1.60 +new TestCase(   SECTION,
    1.61 +		"var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 + EXP_2",
    1.62 +		1,
    1.63 +		eval("var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 + EXP_2") );
    1.64 +
    1.65 +new TestCase(   SECTION,
    1.66 +		"var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 + EXP_2",
    1.67 +		"truefalse",
    1.68 +		eval("var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 + EXP_2") );
    1.69 +
    1.70 +// tests for "MyValuelessObject", where the value is
    1.71 +// set in the object's prototype, not the object itself.
    1.72 +
    1.73 +
    1.74 +new TestCase(   SECTION,
    1.75 +		"var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(-1); EXP_1 + EXP_2",
    1.76 +		99,
    1.77 +		eval("var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(-1); EXP_1 + EXP_2") );
    1.78 +
    1.79 +new TestCase(   SECTION,
    1.80 +		"var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(-1)); EXP_1 + EXP_2",
    1.81 +		"100-1",
    1.82 +		eval("var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(-1)); EXP_1 + EXP_2") );
    1.83 +
    1.84 +new TestCase(   SECTION,
    1.85 +		"var EXP_1 = new MyValuelessObject( new MyValuelessObject( new Boolean(true) ) ); EXP_1 + EXP_1",
    1.86 +		"truetrue",
    1.87 +		eval("var EXP_1 = new MyValuelessObject( new MyValuelessObject( new Boolean(true) ) ); EXP_1 + EXP_1") );
    1.88 +
    1.89 +test();
    1.90 +
    1.91 +function MyProtoValuelessObject() {
    1.92 +  this.valueOf = new Function ( "" );
    1.93 +  this.__proto__ = null;
    1.94 +}
    1.95 +
    1.96 +function MyProtolessObject( value ) {
    1.97 +  this.valueOf = new Function( "return this.value" );
    1.98 +  this.__proto__ = null;
    1.99 +  this.value = value;
   1.100 +}
   1.101 +
   1.102 +function MyValuelessObject(value) {
   1.103 +  this.__proto__ = new MyPrototypeObject(value);
   1.104 +}
   1.105 +function MyPrototypeObject(value) {
   1.106 +  this.valueOf = new Function( "return this.value;" );
   1.107 +  this.toString = new Function( "return (this.value + '');" );
   1.108 +  this.value = value;
   1.109 +}
   1.110 +
   1.111 +function MyObject( value ) {
   1.112 +  this.valueOf = new Function( "return this.value" );
   1.113 +  this.value = value;
   1.114 +}

mercurial