Wed, 31 Dec 2014 06:09:35 +0100
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/. */
7 /**
8 File Name: 11.6.1-2.js
9 ECMA Section: 11.6.1 The addition operator ( + )
10 Description:
12 The addition operator either performs string concatenation or numeric
13 addition.
15 The production AdditiveExpression : AdditiveExpression + MultiplicativeExpression
16 is evaluated as follows:
18 1. Evaluate AdditiveExpression.
19 2. Call GetValue(Result(1)).
20 3. Evaluate MultiplicativeExpression.
21 4. Call GetValue(Result(3)).
22 5. Call ToPrimitive(Result(2)).
23 6. Call ToPrimitive(Result(4)).
24 7. If Type(Result(5)) is String or Type(Result(6)) is String, go to step 12.
25 (Note that this step differs from step 3 in the algorithm for comparison
26 for the relational operators in using or instead of and.)
27 8. Call ToNumber(Result(5)).
28 9. Call ToNumber(Result(6)).
29 10. Apply the addition operation to Result(8) and Result(9). See the discussion below (11.6.3).
30 11. Return Result(10).
31 12. Call ToString(Result(5)).
32 13. Call ToString(Result(6)).
33 14. Concatenate Result(12) followed by Result(13).
34 15. Return Result(14).
36 Note that no hint is provided in the calls to ToPrimitive in steps 5 and 6.
37 All native ECMAScript objects except Date objects handle the absence of a
38 hint as if the hint Number were given; Date objects handle the absence of a
39 hint as if the hint String were given. Host objects may handle the absence
40 of a hint in some other manner.
42 This test does only covers cases where the Additive or Mulplicative expression
43 ToPrimitive is a string.
45 Author: christine@netscape.com
46 Date: 12 november 1997
47 */
48 var SECTION = "11.6.1-2";
49 var VERSION = "ECMA_1";
50 startTest();
52 writeHeaderToLog( SECTION + " The Addition operator ( + )");
54 // tests for "MyValuelessObject", where the value is
55 // set in the object's prototype, not the object itself.
57 new TestCase( SECTION,
58 "var EXP_1 = new MyValuelessObject('string'); var EXP_2 = new MyValuelessObject(false); EXP_1 + EXP_2",
59 "stringfalse",
60 eval("var EXP_1 = new MyValuelessObject('string'); var EXP_2 = new MyValuelessObject(false); EXP_1 + EXP_2") );
62 new TestCase( SECTION,
63 "var EXP_1 = new MyValuelessObject(new String('string')); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 + EXP_2",
64 "stringfalse",
65 eval("var EXP_1 = new MyValuelessObject(new String('string')); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 + EXP_2") );
67 // tests for "MyValuelessObject", where the value is
68 // set in the object's prototype, not the object itself.
70 new TestCase( SECTION,
71 "var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject('string'); EXP_1 + EXP_2",
72 "100string",
73 eval("var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject('string'); EXP_1 + EXP_2") );
75 new TestCase( SECTION,
76 "var EXP_1 = new MyValuelessObject(new String('string')); var EXP_2 = new MyValuelessObject(new Number(-1)); EXP_1 + EXP_2",
77 "string-1",
78 eval("var EXP_1 = new MyValuelessObject(new String('string')); var EXP_2 = new MyValuelessObject(new Number(-1)); EXP_1 + EXP_2") );
80 test();
82 function MyProtoValuelessObject() {
83 this.valueOf = new Function ( "" );
84 this.__proto__ = null;
85 }
86 function MyProtolessObject( value ) {
87 this.valueOf = new Function( "return this.value" );
88 this.__proto__ = null;
89 this.value = value;
90 }
91 function MyValuelessObject(value) {
92 this.__proto__ = new MyPrototypeObject(value);
93 }
94 function MyPrototypeObject(value) {
95 this.valueOf = new Function( "return this.value;" );
96 this.toString = new Function( "return (this.value + '');" );
97 this.value = value;
98 }
99 function MyObject( value ) {
100 this.valueOf = new Function( "return this.value" );
101 this.value = value;
102 }