js/src/tests/js1_3/extensions/proto_5.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:8ea36f52a6c9
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
7 /**
8 File Name: proto_5.js
9 Section:
10 Description: Logical OR || in Constructors
11
12 This tests Object Hierarchy and Inheritance, as described in the document
13 Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
14 15:19:34 on http://devedge.netscape.com/. Current URL:
15 http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
16
17 This tests the syntax ObjectName.prototype = new PrototypeObject using the
18 Employee example in the document referenced above.
19
20 This tests the logical OR opererator || syntax in constructors.
21
22 Author: christine@netscape.com
23 Date: 12 november 1997
24 */
25
26 var SECTION = "proto_5";
27 var VERSION = "JS1_3";
28 var TITLE = "Logical OR || in Constructors";
29
30 startTest();
31 writeHeaderToLog( SECTION + " "+ TITLE);
32
33 function Employee ( name, dept ) {
34 this.name = name || "";
35 this.dept = dept || "general";
36 }
37 function Manager () {
38 this.reports = [];
39 }
40 Manager.prototype = new Employee();
41
42 function WorkerBee ( projs ) {
43 this.projects = projs || new Array();
44 }
45 WorkerBee.prototype = new Employee();
46
47 function SalesPerson () {
48 this.dept = "sales";
49 this.quota = 100;
50 }
51 SalesPerson.prototype = new WorkerBee();
52
53 function Engineer ( machine ) {
54 this.dept = "engineering";
55 this.machine = machine || "";
56 }
57 Engineer.prototype = new WorkerBee();
58
59
60 var pat = new Engineer( "indy" );
61
62 var les = new Engineer();
63
64 new TestCase( SECTION,
65 "var pat = new Engineer(\"indy\"); pat.name",
66 "",
67 pat.name );
68
69 new TestCase( SECTION,
70 "pat.dept",
71 "engineering",
72 pat.dept );
73
74 new TestCase( SECTION,
75 "pat.projects.length",
76 0,
77 pat.projects.length );
78
79 new TestCase( SECTION,
80 "pat.machine",
81 "indy",
82 pat.machine );
83
84 new TestCase( SECTION,
85 "pat.__proto__ == Engineer.prototype",
86 true,
87 pat.__proto__ == Engineer.prototype );
88
89 new TestCase( SECTION,
90 "var les = new Engineer(); les.name",
91 "",
92 les.name );
93
94 new TestCase( SECTION,
95 "les.dept",
96 "engineering",
97 les.dept );
98
99 new TestCase( SECTION,
100 "les.projects.length",
101 0,
102 les.projects.length );
103
104 new TestCase( SECTION,
105 "les.machine",
106 "",
107 les.machine );
108
109 new TestCase( SECTION,
110 "les.__proto__ == Engineer.prototype",
111 true,
112 les.__proto__ == Engineer.prototype );
113
114
115 test();

mercurial