js/src/tests/js1_3/inherit/proto_1.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_1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,136 @@
     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_1.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 +   Author:             christine@netscape.com
    1.24 +   Date:               12 november 1997
    1.25 +*/
    1.26 +
    1.27 +var SECTION = "proto_1";
    1.28 +var VERSION = "JS1_3";
    1.29 +var TITLE   = "new PrototypeObject";
    1.30 +
    1.31 +startTest();
    1.32 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.33 +
    1.34 +function Employee () {
    1.35 +  this.name = "";
    1.36 +  this.dept = "general";
    1.37 +}
    1.38 +function Manager () {
    1.39 +  this.reports = [];
    1.40 +}
    1.41 +Manager.prototype = new Employee();
    1.42 +
    1.43 +function WorkerBee () {
    1.44 +  this.projects = new Array();
    1.45 +}
    1.46 +WorkerBee.prototype = new Employee();
    1.47 +
    1.48 +function SalesPerson () {
    1.49 +  this.dept = "sales";
    1.50 +  this.quota = 100;
    1.51 +}
    1.52 +SalesPerson.prototype = new WorkerBee();
    1.53 +
    1.54 +function Engineer () {
    1.55 +  this.dept = "engineering";
    1.56 +  this.machine = "";
    1.57 +}
    1.58 +Engineer.prototype = new WorkerBee();
    1.59 +
    1.60 +var jim = new Employee();
    1.61 +
    1.62 +new TestCase( SECTION,
    1.63 +	      "jim = new Employee(); jim.name",
    1.64 +	      "",
    1.65 +	      jim.name );
    1.66 +
    1.67 +
    1.68 +new TestCase( SECTION,
    1.69 +	      "jim = new Employee(); jim.dept",
    1.70 +	      "general",
    1.71 +	      jim.dept );
    1.72 +
    1.73 +var sally = new Manager();
    1.74 +
    1.75 +new TestCase( SECTION,
    1.76 +	      "sally = new Manager(); sally.name",
    1.77 +	      "",
    1.78 +	      sally.name );
    1.79 +new TestCase( SECTION,
    1.80 +	      "sally = new Manager(); sally.dept",
    1.81 +	      "general",
    1.82 +	      sally.dept );
    1.83 +
    1.84 +new TestCase( SECTION,
    1.85 +	      "sally = new Manager(); sally.reports.length",
    1.86 +	      0,
    1.87 +	      sally.reports.length );
    1.88 +
    1.89 +new TestCase( SECTION,
    1.90 +	      "sally = new Manager(); typeof sally.reports",
    1.91 +	      "object",
    1.92 +	      typeof sally.reports );
    1.93 +
    1.94 +var fred = new SalesPerson();
    1.95 +
    1.96 +new TestCase( SECTION,
    1.97 +	      "fred = new SalesPerson(); fred.name",
    1.98 +	      "",
    1.99 +	      fred.name );
   1.100 +
   1.101 +new TestCase( SECTION,
   1.102 +	      "fred = new SalesPerson(); fred.dept",
   1.103 +	      "sales",
   1.104 +	      fred.dept );
   1.105 +
   1.106 +new TestCase( SECTION,
   1.107 +	      "fred = new SalesPerson(); fred.quota",
   1.108 +	      100,
   1.109 +	      fred.quota );
   1.110 +
   1.111 +new TestCase( SECTION,
   1.112 +	      "fred = new SalesPerson(); fred.projects.length",
   1.113 +	      0,
   1.114 +	      fred.projects.length );
   1.115 +
   1.116 +var jane = new Engineer();
   1.117 +
   1.118 +new TestCase( SECTION,
   1.119 +	      "jane = new Engineer(); jane.name",
   1.120 +	      "",
   1.121 +	      jane.name );
   1.122 +
   1.123 +new TestCase( SECTION,
   1.124 +	      "jane = new Engineer(); jane.dept",
   1.125 +	      "engineering",
   1.126 +	      jane.dept );
   1.127 +
   1.128 +new TestCase( SECTION,
   1.129 +	      "jane = new Engineer(); jane.projects.length",
   1.130 +	      0,
   1.131 +	      jane.projects.length );
   1.132 +
   1.133 +new TestCase( SECTION,
   1.134 +	      "jane = new Engineer(); jane.machine",
   1.135 +	      "",
   1.136 +	      jane.machine );
   1.137 +
   1.138 +
   1.139 +test();

mercurial