michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 11.6.2-1.js michael@0: ECMA Section: 11.6.2 The Subtraction operator ( - ) michael@0: Description: michael@0: michael@0: The production AdditiveExpression : AdditiveExpression - michael@0: MultiplicativeExpression is evaluated as follows: michael@0: michael@0: 1. Evaluate AdditiveExpression. michael@0: 2. Call GetValue(Result(1)). michael@0: 3. Evaluate MultiplicativeExpression. michael@0: 4. Call GetValue(Result(3)). michael@0: 5. Call ToNumber(Result(2)). michael@0: 6. Call ToNumber(Result(4)). michael@0: 7. Apply the subtraction operation to Result(5) and Result(6). See the michael@0: discussion below (11.6.3). michael@0: 8. Return Result(7). michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: var SECTION = "11.6.2-1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " The subtraction operator ( - )"); michael@0: michael@0: // tests "MyValuelessObject", where the value is michael@0: // set in the object's prototype, not the object itself. michael@0: michael@0: michael@0: new TestCase( SECTION, michael@0: "var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2", michael@0: 1, michael@0: eval("var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2", michael@0: Number.NaN, michael@0: eval("var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2") ); michael@0: michael@0: // tests "MyValuelessObject", where the value is michael@0: // set in the object's prototype, not the object itself. michael@0: michael@0: new TestCase( SECTION, michael@0: "var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2", michael@0: 99, michael@0: eval("var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2") ); michael@0: /* michael@0: new TestCase( SECTION, michael@0: "var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2", michael@0: Number.NaN, michael@0: eval("var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2") ); michael@0: */ michael@0: // same thing with string! michael@0: michael@0: test(); michael@0: michael@0: function MyProtoValuelessObject() { michael@0: this.valueOf = new Function ( "" ); michael@0: this.__proto__ = null; michael@0: } michael@0: function MyProtolessObject( value ) { michael@0: this.valueOf = new Function( "return this.value" ); michael@0: this.__proto__ = null; michael@0: this.value = value; michael@0: } michael@0: function MyValuelessObject(value) { michael@0: this.__proto__ = new MyPrototypeObject(value); michael@0: } michael@0: function MyPrototypeObject(value) { michael@0: this.valueOf = new Function( "return this.value;" ); michael@0: this.toString = new Function( "return (this.value + '');" ); michael@0: this.value = value; michael@0: } michael@0: function MyObject( value ) { michael@0: this.valueOf = new Function( "return this.value" ); michael@0: this.value = value; michael@0: } michael@0: function MyOtherObject( value ) { michael@0: this.valueOf = new Function( "return this.value" ); michael@0: this.toString = new Function ( "return this.value + ''" ); michael@0: this.value = value; michael@0: }