1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: 8.6.2.1-1.js
24 ECMA Section: 8.6.2.1 Get (Value)
27 When the [[Get]] method of O is called with property name P, the following
30 1. If O doesn't have a property with name P, go to step 4.
31 2. Get the value of the property.
33 4. If the [[Prototype]] of O is null, return undefined.
34 5. Call the [[Get]] method of [[Prototype]] with property name P.
37 This tests [[Get]] (Value).
39 Author: christine@netscape.com
40 Date: 12 november 1997
42 var SECTION = "8.6.2.1-1";
43 var VERSION = "ECMA_1";
45 var testcases = getTestCases();
47 writeHeaderToLog( SECTION + " [[Get]] (Value)");
51 for ( tc=0; tc < testcases.length; tc++ ) {
52 testcases[tc].passed = writeTestCaseResult(
55 testcases[tc].description +" = "+
56 testcases[tc].actual );
58 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
63 function getTestCases() {
64 var array = new Array();
67 array[item++] = new TestCase( SECTION, "var OBJ = new MyValuelessObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyValuelessObject(true); OBJ.valueOf()") );
68 // array[item++] = new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject(true); OBJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") );
69 array[item++] = new TestCase( SECTION, "var OBJ = new MyProtolessObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyProtolessObject(true); OBJ.valueOf()") );
70 array[item++] = new TestCase( SECTION, "var OBJ = new MyObject(true); OBJ.valueOf()", true, eval("var OBJ = new MyObject(true); OBJ.valueOf()") );
72 array[item++] = 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()") );
73 // array[item++] = new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject(Number.POSITIVE_INFINITY); OBJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") );
74 array[item++] = 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()") );
75 array[item++] = new TestCase( SECTION, "var OBJ = new MyObject(Number.POSITIVE_INFINITY); OBJ.valueOf()", Number.POSITIVE_INFINITY, eval("var OBJ = new MyObject(Number.POSITIVE_INFINITY); OBJ.valueOf()") );
77 array[item++] = new TestCase( SECTION, "var OBJ = new MyValuelessObject('string'); OBJ.valueOf()", 'string', eval("var OBJ = new MyValuelessObject('string'); OBJ.valueOf()") );
78 // array[item++] = new TestCase( SECTION, "var OBJ = new MyProtoValuelessObject('string'); OJ + ''", "undefined", eval("var OBJ = new MyProtoValuelessObject(); OBJ + ''") );
79 array[item++] = new TestCase( SECTION, "var OBJ = new MyProtolessObject('string'); OBJ.valueOf()", 'string', eval("var OBJ = new MyProtolessObject('string'); OBJ.valueOf()") );
80 array[item++] = new TestCase( SECTION, "var OBJ = new MyObject('string'); OBJ.valueOf()", 'string', eval("var OBJ = new MyObject('string'); OBJ.valueOf()") );
84 function MyProtoValuelessObject(value) {
85 this.valueOf = new Function ( "" );
86 this.__proto__ = null;
89 function MyProtolessObject( value ) {
90 this.valueOf = new Function( "return this.value" );
91 this.__proto__ = null;
94 function MyValuelessObject(value) {
95 this.__proto__ = new MyPrototypeObject(value);
97 function MyPrototypeObject(value) {
98 this.valueOf = new Function( "return this.value;" );
99 this.toString = new Function( "return (this.value + '');" );
102 function MyObject( value ) {
103 this.valueOf = new Function( "return this.value" );