]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_3/inherit/proto_6.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_3 / inherit / proto_6.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: proto_6.js
24 Section:
25 Description: Logical OR || in constructors
26
27 This tests Object Hierarchy and Inheritance, as described in the document
28 Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
29 15:19:34 on http://devedge.netscape.com/. Current URL:
30 http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
31
32 This tests the syntax ObjectName.prototype = new PrototypeObject using the
33 Employee example in the document referenced above.
34
35 This tests the logical OR opererator || syntax in constructors.
36
37 Author: christine@netscape.com
38 Date: 12 november 1997
39 */
40
41 var SECTION = "proto_6";
42 var VERSION = "JS1_3";
43 var TITLE = "Logical OR || in constructors";
44
45 startTest();
46 writeHeaderToLog( SECTION + " "+ TITLE);
47
48 var testcases = new Array();
49
50 function Employee ( name, dept ) {
51 this.name = name || "";
52 this.dept = dept || "general";
53 }
54 function Manager () {
55 this.reports = [];
56 }
57 Manager.prototype = new Employee();
58
59 function WorkerBee ( name, dept, projs ) {
60 this.base = Employee;
61 this.base( name, dept)
62 this.projects = projs || new Array();
63 }
64
65 WorkerBee.prototype = new Employee();
66
67 function SalesPerson () {
68 this.dept = "sales";
69 this.quota = 100;
70 }
71 SalesPerson.prototype = new WorkerBee();
72
73 function Engineer ( name, projs, machine ) {
74 this.base = WorkerBee;
75 this.base( name, "engineering", projs )
76 this.machine = machine || "";
77 }
78 Engineer.prototype = new WorkerBee();
79
80 function test() {
81 for ( tc=0; tc < testcases.length; tc++ ) {
82 testcases[tc].passed = writeTestCaseResult(
83 testcases[tc].expect,
84 testcases[tc].actual,
85 testcases[tc].description +" = "+
86 testcases[tc].actual );
87
88 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
89 }
90 stopTest();
91 return ( testcases );
92 }
93
94 var pat = new Engineer( "Toonces, Pat",
95 ["SpiderMonkey", "Rhino"],
96 "indy" );
97
98 var les = new WorkerBee( "Morris, Les",
99 "Training",
100 ["Hippo"] )
101
102 var terry = new Employee( "Boomberi, Terry",
103 "Marketing" );
104
105 // Pat, the Engineer
106
107 testcases[tc++] = new TestCase( SECTION,
108 "pat.name",
109 "Toonces, Pat",
110 pat.name );
111
112 testcases[tc++] = new TestCase( SECTION,
113 "pat.dept",
114 "engineering",
115 pat.dept );
116
117 testcases[tc++] = new TestCase( SECTION,
118 "pat.projects.length",
119 2,
120 pat.projects.length );
121
122 testcases[tc++] = new TestCase( SECTION,
123 "pat.projects[0]",
124 "SpiderMonkey",
125 pat.projects[0] );
126
127 testcases[tc++] = new TestCase( SECTION,
128 "pat.projects[1]",
129 "Rhino",
130 pat.projects[1] );
131
132 testcases[tc++] = new TestCase( SECTION,
133 "pat.machine",
134 "indy",
135 pat.machine );
136
137
138 // Les, the WorkerBee
139
140 testcases[tc++] = new TestCase( SECTION,
141 "les.name",
142 "Morris, Les",
143 les.name );
144
145 testcases[tc++] = new TestCase( SECTION,
146 "les.dept",
147 "Training",
148 les.dept );
149
150 testcases[tc++] = new TestCase( SECTION,
151 "les.projects.length",
152 1,
153 les.projects.length );
154
155 testcases[tc++] = new TestCase( SECTION,
156 "les.projects[0]",
157 "Hippo",
158 les.projects[0] );
159
160 // Terry, the Employee
161 testcases[tc++] = new TestCase( SECTION,
162 "terry.name",
163 "Boomberi, Terry",
164 terry.name );
165
166 testcases[tc++] = new TestCase( SECTION,
167 "terry.dept",
168 "Marketing",
169 terry.dept );
170 test();
171