initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma / Types / 8.6.2.1-1.js
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/
5  *
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.
10  *
11  * The Original Code is Mozilla Communicator client code, released March
12  * 31, 1998.
13  *
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
17  * Rights Reserved.
18  *
19  * Contributor(s): 
20  * 
21  */
22 /**
23     File Name:          8.6.2.1-1.js
24     ECMA Section:       8.6.2.1 Get (Value)
25     Description:
26
27     When the [[Get]] method of O is called with property name P, the following
28     steps are taken:
29
30     1.  If O doesn't have a property with name P, go to step 4.
31     2.  Get the value of the property.
32     3.  Return Result(2).
33     4.  If the [[Prototype]] of O is null, return undefined.
34     5.  Call the [[Get]] method of [[Prototype]] with property name P.
35     6.  Return Result(5).
36
37     This tests [[Get]] (Value).
38
39     Author:             christine@netscape.com
40     Date:               12 november 1997
41 */
42     var SECTION = "8.6.2.1-1";
43     var VERSION = "ECMA_1";
44     startTest();
45     var testcases = getTestCases();
46
47     writeHeaderToLog( SECTION + " [[Get]] (Value)");
48     test();
49
50 function test() {
51     for ( tc=0; tc < testcases.length; tc++ ) {
52         testcases[tc].passed = writeTestCaseResult(
53                             testcases[tc].expect,
54                             testcases[tc].actual,
55                             testcases[tc].description +" = "+
56                             testcases[tc].actual );
57
58         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
59     }
60     stopTest();
61     return ( testcases );
62 }
63 function getTestCases() {
64     var array = new Array();
65     var item = 0;
66
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()") );
71
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()") );
76
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()") );
81
82     return ( array );
83 }
84 function MyProtoValuelessObject(value) {
85     this.valueOf = new Function ( "" );
86     this.__proto__ = null;
87 }
88
89 function MyProtolessObject( value ) {
90     this.valueOf = new Function( "return this.value" );
91     this.__proto__ = null;
92     this.value = value;
93 }
94 function MyValuelessObject(value) {
95     this.__proto__ = new MyPrototypeObject(value);
96 }
97 function MyPrototypeObject(value) {
98     this.valueOf = new Function( "return this.value;" );
99     this.toString = new Function( "return (this.value + '');" );
100     this.value = value;
101 }
102 function MyObject( value ) {
103     this.valueOf = new Function( "return this.value" );
104     this.value = value;
105 }