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: 8.6.2.1-1.js michael@0: ECMA Section: 8.6.2.1 Get (Value) michael@0: Description: michael@0: michael@0: When the [[Get]] method of O is called with property name P, the following michael@0: steps are taken: michael@0: michael@0: 1. If O doesn't have a property with name P, go to step 4. michael@0: 2. Get the value of the property. michael@0: 3. Return Result(2). michael@0: 4. If the [[Prototype]] of O is null, return undefined. michael@0: 5. Call the [[Get]] method of [[Prototype]] with property name P. michael@0: 6. Return Result(5). michael@0: michael@0: This tests [[Get]] (Value). michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: var SECTION = "8.6.2.1-1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " [[Get]] (Value)"); michael@0: michael@0: new TestCase( SECTION, "var OBJ = new MyValuelessObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyValuelessObject(true); OBJ.valueOf()") ); michael@0: // new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject(true); OBJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") ); michael@0: new TestCase( SECTION, "var OBJ = new MyProtolessObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyProtolessObject(true); OBJ.valueOf()") ); michael@0: michael@0: new TestCase( SECTION, "var OBJ = new MyValuelessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()", Number.POSITIVE_INFINITY, eval("var OBJ = new MyValuelessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()") ); michael@0: // new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject(Number.POSITIVE_INFINITY); OBJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") ); michael@0: new TestCase( SECTION, "var OBJ = new MyProtolessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()", Number.POSITIVE_INFINITY, eval("var OBJ = new MyProtolessObject(Number.POSITIVE_INFINITY); OBJ.valueOf()") ); michael@0: michael@0: new TestCase( SECTION, "var OBJ = new MyValuelessObject('string'); OBJ.valueOf()", 'string', eval("var OBJ = new MyValuelessObject('string'); OBJ.valueOf()") ); michael@0: // new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject('string'); OJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") ); michael@0: new TestCase( SECTION, "var OBJ = new MyProtolessObject('string'); OBJ.valueOf()", 'string', eval("var OBJ = new MyProtolessObject('string'); OBJ.valueOf()") ); michael@0: michael@0: test(); michael@0: michael@0: function MyProtoValuelessObject(value) { michael@0: this.valueOf = new Function ( "" ); michael@0: this.__proto__ = null; michael@0: } 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: }