Debian Codegraph @

rhino/testsrc/tests/js1_3/inherit/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 return object instanceof constructor;
34 }
35 function Employee ( name, dept ) {
36 this.name = name || "";
37 this.dept = dept || "general";
38 }
39
40 function Manager () {
41 this.reports = [];
42 }
43 Manager.prototype = new Employee();
44
45 function WorkerBee ( name, dept, projs ) {
46 this.base = Employee;
47 this.base( name, dept)
48 this.projects = projs || new Array();
49 }
50 WorkerBee.prototype = new Employee();
51
52 function SalesPerson () {
53 this.dept = "sales";
54 this.quota = 100;
55 }
56 SalesPerson.prototype = new WorkerBee();
57
58 function Engineer ( name, projs, machine ) {
59 this.base = WorkerBee;
60 this.base( name, "engineering", projs )
61 this.machine = machine || "";
62 }
63 Engineer.prototype = new WorkerBee();
64
65 var pat = new Engineer();
66
67 new TestCase( SECTION,
68 "InstanceOf( pat, Engineer )",
69 true,
70 InstanceOf( pat, Engineer ) );
71
72 new TestCase( SECTION,
73 "InstanceOf( pat, WorkerBee )",
74 true,
75 InstanceOf( pat, WorkerBee ) );
76
77 new TestCase( SECTION,
78 "InstanceOf( pat, Employee )",
79 true,
80 InstanceOf( pat, Employee ) );
81
82 new TestCase( SECTION,
83 "InstanceOf( pat, Object )",
84 true,
85 InstanceOf( pat, Object ) );
86
87 new TestCase( SECTION,
88 "InstanceOf( pat, SalesPerson )",
89 false,
90 InstanceOf ( pat, SalesPerson ) );
91 test();