Debian Codegraph @

rhino/testsrc/tests/js1_3/extensions/proto_10.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_10.js';
7
8 /**
9 File Name: proto_10.js
10 Section:
11 Description: Determining Instance Relationships
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_10";
26 var VERSION = "JS1_3";
27 var TITLE = "Determining Instance Relationships";
28
29 startTest();
30 writeHeaderToLog( SECTION + " "+ TITLE);
31
32 function InstanceOf( object, constructor ) {
33 while ( object != null ) {
34 if ( object == constructor.prototype ) {
35 return true;
36 }
37 object = object.__proto__;
38 }
39 return false;
40 }
41 function Employee ( name, dept ) {
42 this.name = name || "";
43 this.dept = dept || "general";
44 }
45
46 function Manager () {
47 this.reports = [];
48 }
49 Manager.prototype = new Employee();
50
51 function WorkerBee ( name, dept, projs ) {
52 this.base = Employee;
53 this.base( name, dept)
54 this.projects = projs || new Array();
55 }
56 WorkerBee.prototype = new Employee();
57
58 function SalesPerson () {
59 this.dept = "sales";
60 this.quota = 100;
61 }
62 SalesPerson.prototype = new WorkerBee();
63
64 function Engineer ( name, projs, machine ) {
65 this.base = WorkerBee;
66 this.base( name, "engineering", projs )
67 this.machine = machine || "";
68 }
69 Engineer.prototype = new WorkerBee();
70
71 var pat = new Engineer();
72
73 new TestCase( SECTION,
74 "pat.__proto__ == Engineer.prototype",
75 true,
76 pat.__proto__ == Engineer.prototype );
77
78 new TestCase( SECTION,
79 "pat.__proto__.__proto__ == WorkerBee.prototype",
80 true,
81 pat.__proto__.__proto__ == WorkerBee.prototype );
82
83 new TestCase( SECTION,
84 "pat.__proto__.__proto__.__proto__ == Employee.prototype",
85 true,
86 pat.__proto__.__proto__.__proto__ == Employee.prototype );
87
88 new TestCase( SECTION,
89 "pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype",
90 true,
91 pat.__proto__.__proto__.__proto__.__proto__ == Object.prototype );
92
93 new TestCase( SECTION,
94 "pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null",
95 true,
96 pat.__proto__.__proto__.__proto__.__proto__.__proto__ == null );
97
98
99 new TestCase( SECTION,
100 "InstanceOf( pat, Engineer )",
101 true,
102 InstanceOf( pat, Engineer ) );
103
104 new TestCase( SECTION,
105 "InstanceOf( pat, WorkerBee )",
106 true,
107 InstanceOf( pat, WorkerBee ) );
108
109 new TestCase( SECTION,
110 "InstanceOf( pat, Employee )",
111 true,
112 InstanceOf( pat, Employee ) );
113
114 new TestCase( SECTION,
115 "InstanceOf( pat, Object )",
116 true,
117 InstanceOf( pat, Object ) );
118
119 new TestCase( SECTION,
120 "InstanceOf( pat, SalesPerson )",
121 false,
122 InstanceOf ( pat, SalesPerson ) );
123 test();