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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_3/extensions/proto_5.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     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_5.js
    1.12 +   Section:
    1.13 +   Description:        Logical OR || in Constructors
    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 +   This tests the logical OR opererator || syntax in constructors.
    1.24 +
    1.25 +   Author:             christine@netscape.com
    1.26 +   Date:               12 november 1997
    1.27 +*/
    1.28 +
    1.29 +var SECTION = "proto_5";
    1.30 +var VERSION = "JS1_3";
    1.31 +var TITLE   = "Logical OR || in Constructors";
    1.32 +
    1.33 +startTest();
    1.34 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.35 +
    1.36 +function Employee ( name, dept ) {
    1.37 +  this.name = name || "";
    1.38 +  this.dept = dept || "general";
    1.39 +}
    1.40 +function Manager () {
    1.41 +  this.reports = [];
    1.42 +}
    1.43 +Manager.prototype = new Employee();
    1.44 +
    1.45 +function WorkerBee ( projs ) {
    1.46 +  this.projects = projs || new Array();
    1.47 +}
    1.48 +WorkerBee.prototype = new Employee();
    1.49 +
    1.50 +function SalesPerson () {
    1.51 +  this.dept = "sales";
    1.52 +  this.quota = 100;
    1.53 +}
    1.54 +SalesPerson.prototype = new WorkerBee();
    1.55 +
    1.56 +function Engineer ( machine ) {
    1.57 +  this.dept = "engineering";
    1.58 +  this.machine = machine || "";
    1.59 +}
    1.60 +Engineer.prototype = new WorkerBee();
    1.61 +
    1.62 +
    1.63 +var pat = new Engineer( "indy" );
    1.64 +
    1.65 +var les = new Engineer();
    1.66 +
    1.67 +new TestCase( SECTION,
    1.68 +	      "var pat = new Engineer(\"indy\"); pat.name",
    1.69 +	      "",
    1.70 +	      pat.name );
    1.71 +
    1.72 +new TestCase( SECTION,
    1.73 +	      "pat.dept",
    1.74 +	      "engineering",
    1.75 +	      pat.dept );
    1.76 +
    1.77 +new TestCase( SECTION,
    1.78 +	      "pat.projects.length",
    1.79 +	      0,
    1.80 +	      pat.projects.length );
    1.81 +
    1.82 +new TestCase( SECTION,
    1.83 +	      "pat.machine",
    1.84 +	      "indy",
    1.85 +	      pat.machine );
    1.86 +
    1.87 +new TestCase( SECTION,
    1.88 +	      "pat.__proto__ == Engineer.prototype",
    1.89 +	      true,
    1.90 +	      pat.__proto__ == Engineer.prototype );
    1.91 +
    1.92 +new TestCase( SECTION,
    1.93 +	      "var les = new Engineer(); les.name",
    1.94 +	      "",
    1.95 +	      les.name );
    1.96 +
    1.97 +new TestCase( SECTION,
    1.98 +	      "les.dept",
    1.99 +	      "engineering",
   1.100 +	      les.dept );
   1.101 +
   1.102 +new TestCase( SECTION,
   1.103 +	      "les.projects.length",
   1.104 +	      0,
   1.105 +	      les.projects.length );
   1.106 +
   1.107 +new TestCase( SECTION,
   1.108 +	      "les.machine",
   1.109 +	      "",
   1.110 +	      les.machine );
   1.111 +
   1.112 +new TestCase( SECTION,
   1.113 +	      "les.__proto__ == Engineer.prototype",
   1.114 +	      true,
   1.115 +	      les.__proto__ == Engineer.prototype );
   1.116 +
   1.117 +
   1.118 +test();

mercurial