Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / extensions / 11.6.2-1.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          11.6.2-1.js
42    ECMA Section:       11.6.2 The Subtraction operator ( - )
43    Description:
44
45    The production AdditiveExpression : AdditiveExpression -
46    MultiplicativeExpression is evaluated as follows:
47
48    1.  Evaluate AdditiveExpression.
49    2.  Call GetValue(Result(1)).
50    3.  Evaluate MultiplicativeExpression.
51    4.  Call GetValue(Result(3)).
52    5.  Call ToNumber(Result(2)).
53    6.  Call ToNumber(Result(4)).
54    7.  Apply the subtraction operation to Result(5) and Result(6). See the
55    discussion below (11.6.3).
56    8.  Return Result(7).
57
58    Author:             christine@netscape.com
59    Date:               12 november 1997
60 */
61 var SECTION = "11.6.2-1";
62 var VERSION = "ECMA_1";
63 startTest();
64
65 writeHeaderToLog( SECTION + " The subtraction operator ( - )");
66
67 // tests "MyValuelessObject", where the value is
68 // set in the object's prototype, not the object itself.
69
70
71 new TestCase(   SECTION,
72                 "var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2",
73                 1,
74                 eval("var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2") );
75
76 new TestCase(   SECTION,
77                 "var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2",
78                 Number.NaN,
79                 eval("var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2") );
80
81 // tests "MyValuelessObject", where the value is
82 // set in the object's prototype, not the object itself.
83
84 new TestCase(   SECTION,
85                 "var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2",
86                 99,
87                 eval("var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2") );
88 /*
89   new TestCase(   SECTION,
90   "var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2",
91   Number.NaN,
92   eval("var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2") );
93 */
94 // same thing with string!
95
96 test();
97
98 function MyProtoValuelessObject() {
99   this.valueOf = new Function ( "" );
100   this.__proto__ = null;
101 }
102 function MyProtolessObject( value ) {
103   this.valueOf = new Function( "return this.value" );
104   this.__proto__ = null;
105   this.value = value;
106 }
107 function MyValuelessObject(value) {
108   this.__proto__ = new MyPrototypeObject(value);
109 }
110 function MyPrototypeObject(value) {
111   this.valueOf = new Function( "return this.value;" );
112   this.toString = new Function( "return (this.value + '');" );
113   this.value = value;
114 }
115 function MyObject( value ) {
116   this.valueOf = new Function( "return this.value" );
117   this.value = value;
118 }
119 function MyOtherObject( value ) {
120   this.valueOf = new Function( "return this.value" );
121   this.toString = new Function ( "return this.value + ''" );
122   this.value = value;
123 }