Debian Codegraph @

rhino/testsrc/tests/js1_3/inherit/proto_1.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'proto_1.js';
7
8 /**
9 File Name: proto_1.js
10 Section:
11 Description: new PrototypeObject
12
13 This tests Object Hierarchy and Inheritance, as described in the document
14 Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
15 15:19:34 on http://devedge.netscape.com/. Current URL:
16 http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
17
18 This tests the syntax ObjectName.prototype = new PrototypeObject using the
19 Employee example in the document referenced above.
20
21 Author: [email protected]
22 Date: 12 november 1997
23 */
24
25 var SECTION = "proto_1";
26 var VERSION = "JS1_3";
27 var TITLE = "new PrototypeObject";
28
29 startTest();
30 writeHeaderToLog( SECTION + " "+ TITLE);
31
32 function Employee () {
33 this.name = "";
34 this.dept = "general";
35 }
36 function Manager () {
37 this.reports = [];
38 }
39 Manager.prototype = new Employee();
40
41 function WorkerBee () {
42 this.projects = new Array();
43 }
44 WorkerBee.prototype = new Employee();
45
46 function SalesPerson () {
47 this.dept = "sales";
48 this.quota = 100;
49 }
50 SalesPerson.prototype = new WorkerBee();
51
52 function Engineer () {
53 this.dept = "engineering";
54 this.machine = "";
55 }
56 Engineer.prototype = new WorkerBee();
57
58 var jim = new Employee();
59
60 new TestCase( SECTION,
61 "jim = new Employee(); jim.name",
62 "",
63 jim.name );
64
65
66 new TestCase( SECTION,
67 "jim = new Employee(); jim.dept",
68 "general",
69 jim.dept );
70
71 var sally = new Manager();
72
73 new TestCase( SECTION,
74 "sally = new Manager(); sally.name",
75 "",
76 sally.name );
77 new TestCase( SECTION,
78 "sally = new Manager(); sally.dept",
79 "general",
80 sally.dept );
81
82 new TestCase( SECTION,
83 "sally = new Manager(); sally.reports.length",
84 0,
85 sally.reports.length );
86
87 new TestCase( SECTION,
88 "sally = new Manager(); typeof sally.reports",
89 "object",
90 typeof sally.reports );
91
92 var fred = new SalesPerson();
93
94 new TestCase( SECTION,
95 "fred = new SalesPerson(); fred.name",
96 "",
97 fred.name );
98
99 new TestCase( SECTION,
100 "fred = new SalesPerson(); fred.dept",
101 "sales",
102 fred.dept );
103
104 new TestCase( SECTION,
105 "fred = new SalesPerson(); fred.quota",
106 100,
107 fred.quota );
108
109 new TestCase( SECTION,
110 "fred = new SalesPerson(); fred.projects.length",
111 0,
112 fred.projects.length );
113
114 var jane = new Engineer();
115
116 new TestCase( SECTION,
117 "jane = new Engineer(); jane.name",
118 "",
119 jane.name );
120
121 new TestCase( SECTION,
122 "jane = new Engineer(); jane.dept",
123 "engineering",
124 jane.dept );
125
126 new TestCase( SECTION,
127 "jane = new Engineer(); jane.projects.length",
128 0,
129 jane.projects.length );
130
131 new TestCase( SECTION,
132 "jane = new Engineer(); jane.machine",
133 "",
134 jane.machine );
135
136
137 test();