~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/src/tests/js1_3/inherit/proto_4.js

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_4.js
 
9
   Section:
 
10
   Description:        new PrototypeObject
 
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
   If you add a property to an object in the prototype chain, instances of
 
21
   objects that derive from that prototype should inherit that property, even
 
22
   if they were instatiated after the property was added to the prototype object.
 
23
 
 
24
 
 
25
   Author:             christine@netscape.com
 
26
   Date:               12 november 1997
 
27
*/
 
28
 
 
29
var SECTION = "proto_3";
 
30
var VERSION = "JS1_3";
 
31
var TITLE   = "Adding properties to the prototype";
 
32
 
 
33
startTest();
 
34
writeHeaderToLog( SECTION + " "+ TITLE);
 
35
 
 
36
function Employee () {
 
37
  this.name = "";
 
38
  this.dept = "general";
 
39
}
 
40
function Manager () {
 
41
  this.reports = [];
 
42
}
 
43
Manager.prototype = new Employee();
 
44
 
 
45
function WorkerBee () {
 
46
  this.projects = new Array();
 
47
}
 
48
 
 
49
WorkerBee.prototype = new Employee();
 
50
 
 
51
function SalesPerson () {
 
52
  this.dept = "sales";
 
53
  this.quota = 100;
 
54
}
 
55
SalesPerson.prototype = new WorkerBee();
 
56
 
 
57
function Engineer () {
 
58
  this.dept = "engineering";
 
59
  this.machine = "";
 
60
}
 
61
Engineer.prototype = new WorkerBee();
 
62
 
 
63
var jim = new Employee();
 
64
var terry = new Engineer();
 
65
var sean = new SalesPerson();
 
66
var wally = new Manager();
 
67
 
 
68
Employee.prototype.specialty = "none";
 
69
 
 
70
var pat = new Employee();
 
71
var leslie = new Engineer();
 
72
var bubbles = new SalesPerson();
 
73
var furry = new Manager();
 
74
 
 
75
Engineer.prototype.specialty = "code";
 
76
 
 
77
var chris = new Engineer();
 
78
 
 
79
 
 
80
new TestCase( SECTION,
 
81
              "jim = new Employee(); jim.specialty",
 
82
              "none",
 
83
              jim.specialty );
 
84
 
 
85
new TestCase( SECTION,
 
86
              "terry = new Engineer(); terry.specialty",
 
87
              "code",
 
88
              terry.specialty );
 
89
 
 
90
new TestCase( SECTION,
 
91
              "sean = new SalesPerson(); sean.specialty",
 
92
              "none",
 
93
              sean.specialty );
 
94
 
 
95
new TestCase( SECTION,
 
96
              "wally = new Manager(); wally.specialty",
 
97
              "none",
 
98
              wally.specialty );
 
99
 
 
100
new TestCase( SECTION,
 
101
              "furry = new Manager(); furry.specialty",
 
102
              "none",
 
103
              furry.specialty );
 
104
 
 
105
new TestCase( SECTION,
 
106
              "pat = new Employee(); pat.specialty",
 
107
              "none",
 
108
              pat.specialty );
 
109
 
 
110
new TestCase( SECTION,
 
111
              "leslie = new Engineer(); leslie.specialty",
 
112
              "code",
 
113
              leslie.specialty );
 
114
 
 
115
new TestCase( SECTION,
 
116
              "bubbles = new SalesPerson(); bubbles.specialty",
 
117
              "none",
 
118
              bubbles.specialty );
 
119
 
 
120
 
 
121
new TestCase( SECTION,
 
122
              "chris = new Employee(); chris.specialty",
 
123
              "code",
 
124
              chris.specialty );
 
125
test();