]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_3/inherit/proto_4.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/
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
25 Description: new PrototypeObject
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
32 This tests the syntax ObjectName.prototype = new PrototypeObject using the
33 Employee example in the document referenced above.
35 If you add a property to an object in the prototype chain, instances of
36 objects that derive from that prototype should inherit that property, even
37 if they were instatiated after the property was added to the prototype object.
40 Author: christine@netscape.com
41 Date: 12 november 1997
44 var SECTION
= "proto_3";
45 var VERSION
= "JS1_3";
46 var TITLE
= "Adding properties to the prototype";
49 writeHeaderToLog( SECTION
+ " "+ TITLE
);
51 var testcases
= new Array();
53 function Employee () {
55 this.dept
= "general";
60 Manager
.prototype = new Employee();
62 function WorkerBee () {
63 this.projects
= new Array();
66 WorkerBee
.prototype = new Employee();
68 function SalesPerson () {
72 SalesPerson
.prototype = new WorkerBee();
74 function Engineer () {
75 this.dept
= "engineering";
78 Engineer
.prototype = new WorkerBee();
81 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
82 testcases
[tc
].passed
= writeTestCaseResult(
85 testcases
[tc
].description
+" = "+
86 testcases
[tc
].actual
);
88 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
94 var jim
= new Employee();
95 var terry
= new Engineer();
96 var sean
= new SalesPerson();
97 var wally
= new Manager();
99 Employee
.prototype.specialty
= "none";
101 var pat
= new Employee();
102 var leslie
= new Engineer();
103 var bubbles
= new SalesPerson();
104 var furry
= new Manager();
106 Engineer
.prototype.specialty
= "code";
108 var chris
= new Engineer();
111 testcases
[tc
++] = new TestCase( SECTION
,
112 "jim = new Employee(); jim.specialty",
116 testcases
[tc
++] = new TestCase( SECTION
,
117 "terry = new Engineer(); terry.specialty",
121 testcases
[tc
++] = new TestCase( SECTION
,
122 "sean = new SalesPerson(); sean.specialty",
126 testcases
[tc
++] = new TestCase( SECTION
,
127 "wally = new Manager(); wally.specialty",
131 testcases
[tc
++] = new TestCase( SECTION
,
132 "furry = new Manager(); furry.specialty",
136 testcases
[tc
++] = new TestCase( SECTION
,
137 "pat = new Employee(); pat.specialty",
141 testcases
[tc
++] = new TestCase( SECTION
,
142 "leslie = new Engineer(); leslie.specialty",
146 testcases
[tc
++] = new TestCase( SECTION
,
147 "bubbles = new SalesPerson(); bubbles.specialty",
152 testcases
[tc
++] = new TestCase( SECTION
,
153 "chris = new Employee(); chris.specialty",