1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/extensions/11.6.2-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 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.2-1.js 1.12 + ECMA Section: 11.6.2 The Subtraction operator ( - ) 1.13 + Description: 1.14 + 1.15 + The production AdditiveExpression : AdditiveExpression - 1.16 + MultiplicativeExpression is evaluated as follows: 1.17 + 1.18 + 1. Evaluate AdditiveExpression. 1.19 + 2. Call GetValue(Result(1)). 1.20 + 3. Evaluate MultiplicativeExpression. 1.21 + 4. Call GetValue(Result(3)). 1.22 + 5. Call ToNumber(Result(2)). 1.23 + 6. Call ToNumber(Result(4)). 1.24 + 7. Apply the subtraction operation to Result(5) and Result(6). See the 1.25 + discussion below (11.6.3). 1.26 + 8. Return Result(7). 1.27 + 1.28 + Author: christine@netscape.com 1.29 + Date: 12 november 1997 1.30 +*/ 1.31 +var SECTION = "11.6.2-1"; 1.32 +var VERSION = "ECMA_1"; 1.33 +startTest(); 1.34 + 1.35 +writeHeaderToLog( SECTION + " The subtraction operator ( - )"); 1.36 + 1.37 +// tests "MyValuelessObject", where the value is 1.38 +// set in the object's prototype, not the object itself. 1.39 + 1.40 + 1.41 +new TestCase( SECTION, 1.42 + "var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2", 1.43 + 1, 1.44 + eval("var EXP_1 = new MyValuelessObject(true); var EXP_2 = new MyValuelessObject(false); EXP_1 - EXP_2") ); 1.45 + 1.46 +new TestCase( SECTION, 1.47 + "var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2", 1.48 + Number.NaN, 1.49 + eval("var EXP_1 = new MyValuelessObject(new Boolean(true)); var EXP_2 = new MyValuelessObject(new Boolean(false)); EXP_1 - EXP_2") ); 1.50 + 1.51 +// tests "MyValuelessObject", where the value is 1.52 +// set in the object's prototype, not the object itself. 1.53 + 1.54 +new TestCase( SECTION, 1.55 + "var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2", 1.56 + 99, 1.57 + eval("var EXP_1 = new MyValuelessObject(100); var EXP_2 = new MyValuelessObject(1); EXP_1 - EXP_2") ); 1.58 +/* 1.59 + new TestCase( SECTION, 1.60 + "var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2", 1.61 + Number.NaN, 1.62 + eval("var EXP_1 = new MyValuelessObject(new Number(100)); var EXP_2 = new MyValuelessObject(new Number(1)); EXP_1 - EXP_2") ); 1.63 +*/ 1.64 +// same thing with string! 1.65 + 1.66 +test(); 1.67 + 1.68 +function MyProtoValuelessObject() { 1.69 + this.valueOf = new Function ( "" ); 1.70 + this.__proto__ = null; 1.71 +} 1.72 +function MyProtolessObject( value ) { 1.73 + this.valueOf = new Function( "return this.value" ); 1.74 + this.__proto__ = null; 1.75 + this.value = value; 1.76 +} 1.77 +function MyValuelessObject(value) { 1.78 + this.__proto__ = new MyPrototypeObject(value); 1.79 +} 1.80 +function MyPrototypeObject(value) { 1.81 + this.valueOf = new Function( "return this.value;" ); 1.82 + this.toString = new Function( "return (this.value + '');" ); 1.83 + this.value = value; 1.84 +} 1.85 +function MyObject( value ) { 1.86 + this.valueOf = new Function( "return this.value" ); 1.87 + this.value = value; 1.88 +} 1.89 +function MyOtherObject( value ) { 1.90 + this.valueOf = new Function( "return this.value" ); 1.91 + this.toString = new Function ( "return this.value + ''" ); 1.92 + this.value = value; 1.93 +}