js/src/tests/js1_3/inherit/proto_4.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_3/inherit/proto_4.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          proto_4.js
    1.12 +   Section:
    1.13 +   Description:        new PrototypeObject
    1.14 +
    1.15 +   This tests Object Hierarchy and Inheritance, as described in the document
    1.16 +   Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
    1.17 +   15:19:34 on http://devedge.netscape.com/.  Current URL:
    1.18 +   http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
    1.19 +
    1.20 +   This tests the syntax ObjectName.prototype = new PrototypeObject using the
    1.21 +   Employee example in the document referenced above.
    1.22 +
    1.23 +   If you add a property to an object in the prototype chain, instances of
    1.24 +   objects that derive from that prototype should inherit that property, even
    1.25 +   if they were instatiated after the property was added to the prototype object.
    1.26 +
    1.27 +
    1.28 +   Author:             christine@netscape.com
    1.29 +   Date:               12 november 1997
    1.30 +*/
    1.31 +
    1.32 +var SECTION = "proto_3";
    1.33 +var VERSION = "JS1_3";
    1.34 +var TITLE   = "Adding properties to the prototype";
    1.35 +
    1.36 +startTest();
    1.37 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.38 +
    1.39 +function Employee () {
    1.40 +  this.name = "";
    1.41 +  this.dept = "general";
    1.42 +}
    1.43 +function Manager () {
    1.44 +  this.reports = [];
    1.45 +}
    1.46 +Manager.prototype = new Employee();
    1.47 +
    1.48 +function WorkerBee () {
    1.49 +  this.projects = new Array();
    1.50 +}
    1.51 +
    1.52 +WorkerBee.prototype = new Employee();
    1.53 +
    1.54 +function SalesPerson () {
    1.55 +  this.dept = "sales";
    1.56 +  this.quota = 100;
    1.57 +}
    1.58 +SalesPerson.prototype = new WorkerBee();
    1.59 +
    1.60 +function Engineer () {
    1.61 +  this.dept = "engineering";
    1.62 +  this.machine = "";
    1.63 +}
    1.64 +Engineer.prototype = new WorkerBee();
    1.65 +
    1.66 +var jim = new Employee();
    1.67 +var terry = new Engineer();
    1.68 +var sean = new SalesPerson();
    1.69 +var wally = new Manager();
    1.70 +
    1.71 +Employee.prototype.specialty = "none";
    1.72 +
    1.73 +var pat = new Employee();
    1.74 +var leslie = new Engineer();
    1.75 +var bubbles = new SalesPerson();
    1.76 +var furry = new Manager();
    1.77 +
    1.78 +Engineer.prototype.specialty = "code";
    1.79 +
    1.80 +var chris = new Engineer();
    1.81 +
    1.82 +
    1.83 +new TestCase( SECTION,
    1.84 +	      "jim = new Employee(); jim.specialty",
    1.85 +	      "none",
    1.86 +	      jim.specialty );
    1.87 +
    1.88 +new TestCase( SECTION,
    1.89 +	      "terry = new Engineer(); terry.specialty",
    1.90 +	      "code",
    1.91 +	      terry.specialty );
    1.92 +
    1.93 +new TestCase( SECTION,
    1.94 +	      "sean = new SalesPerson(); sean.specialty",
    1.95 +	      "none",
    1.96 +	      sean.specialty );
    1.97 +
    1.98 +new TestCase( SECTION,
    1.99 +	      "wally = new Manager(); wally.specialty",
   1.100 +	      "none",
   1.101 +	      wally.specialty );
   1.102 +
   1.103 +new TestCase( SECTION,
   1.104 +	      "furry = new Manager(); furry.specialty",
   1.105 +	      "none",
   1.106 +	      furry.specialty );
   1.107 +
   1.108 +new TestCase( SECTION,
   1.109 +	      "pat = new Employee(); pat.specialty",
   1.110 +	      "none",
   1.111 +	      pat.specialty );
   1.112 +
   1.113 +new TestCase( SECTION,
   1.114 +	      "leslie = new Engineer(); leslie.specialty",
   1.115 +	      "code",
   1.116 +	      leslie.specialty );
   1.117 +
   1.118 +new TestCase( SECTION,
   1.119 +	      "bubbles = new SalesPerson(); bubbles.specialty",
   1.120 +	      "none",
   1.121 +	      bubbles.specialty );
   1.122 +
   1.123 +
   1.124 +new TestCase( SECTION,
   1.125 +	      "chris = new Employee(); chris.specialty",
   1.126 +	      "code",
   1.127 +	      chris.specialty );
   1.128 +test();

mercurial