|
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/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: 11.6.2-1.js |
|
9 ECMA Section: 11.6.2 The Subtraction operator ( - ) |
|
10 Description: |
|
11 |
|
12 The production AdditiveExpression : AdditiveExpression - |
|
13 MultiplicativeExpression is evaluated as follows: |
|
14 |
|
15 1. Evaluate AdditiveExpression. |
|
16 2. Call GetValue(Result(1)). |
|
17 3. Evaluate MultiplicativeExpression. |
|
18 4. Call GetValue(Result(3)). |
|
19 5. Call ToNumber(Result(2)). |
|
20 6. Call ToNumber(Result(4)). |
|
21 7. Apply the subtraction operation to Result(5) and Result(6). See the |
|
22 discussion below (11.6.3). |
|
23 8. Return Result(7). |
|
24 |
|
25 Author: christine@netscape.com |
|
26 Date: 12 november 1997 |
|
27 */ |
|
28 var SECTION = "11.6.2-1"; |
|
29 var VERSION = "ECMA_1"; |
|
30 startTest(); |
|
31 |
|
32 writeHeaderToLog( SECTION + " The subtraction operator ( - )"); |
|
33 |
|
34 // tests "MyValuelessObject", where the value is |
|
35 // set in the object's prototype, not the object itself. |
|
36 |
|
37 |
|
38 new TestCase( SECTION, |
|
39 "var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2", |
|
40 1, |
|
41 eval("var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2") ); |
|
42 |
|
43 new TestCase( SECTION, |
|
44 "var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2", |
|
45 Number.NaN, |
|
46 eval("var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2") ); |
|
47 |
|
48 // tests "MyValuelessObject", where the value is |
|
49 // set in the object's prototype, not the object itself. |
|
50 |
|
51 new TestCase( SECTION, |
|
52 "var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2", |
|
53 99, |
|
54 eval("var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2") ); |
|
55 /* |
|
56 new TestCase( SECTION, |
|
57 "var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2", |
|
58 Number.NaN, |
|
59 eval("var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2") ); |
|
60 */ |
|
61 // same thing with string! |
|
62 |
|
63 test(); |
|
64 |
|
65 function MyProtoValuelessObject() { |
|
66 this.valueOf = new Function ( "" ); |
|
67 this.__proto__ = null; |
|
68 } |
|
69 function MyProtolessObject( value ) { |
|
70 this.valueOf = new Function( "return this.value" ); |
|
71 this.__proto__ = null; |
|
72 this.value = value; |
|
73 } |
|
74 function MyValuelessObject(value) { |
|
75 this.__proto__ = new MyPrototypeObject(value); |
|
76 } |
|
77 function MyPrototypeObject(value) { |
|
78 this.valueOf = new Function( "return this.value;" ); |
|
79 this.toString = new Function( "return (this.value + '');" ); |
|
80 this.value = value; |
|
81 } |
|
82 function MyObject( value ) { |
|
83 this.valueOf = new Function( "return this.value" ); |
|
84 this.value = value; |
|
85 } |
|
86 function MyOtherObject( value ) { |
|
87 this.valueOf = new Function( "return this.value" ); |
|
88 this.toString = new Function ( "return this.value + ''" ); |
|
89 this.value = value; |
|
90 } |