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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 /**
     8    File Name:          proto_5.js
     9    Section:
    10    Description:        Logical OR || in Constructors
    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
    17    This tests the syntax ObjectName.prototype = new PrototypeObject using the
    18    Employee example in the document referenced above.
    20    This tests the logical OR opererator || syntax in constructors.
    22    Author:             christine@netscape.com
    23    Date:               12 november 1997
    24 */
    26 var SECTION = "proto_5";
    27 var VERSION = "JS1_3";
    28 var TITLE   = "Logical OR || in Constructors";
    30 startTest();
    31 writeHeaderToLog( SECTION + " "+ TITLE);
    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();
    42 function WorkerBee ( projs ) {
    43   this.projects = projs || new Array();
    44 }
    45 WorkerBee.prototype = new Employee();
    47 function SalesPerson () {
    48   this.dept = "sales";
    49   this.quota = 100;
    50 }
    51 SalesPerson.prototype = new WorkerBee();
    53 function Engineer ( machine ) {
    54   this.dept = "engineering";
    55   this.machine = machine || "";
    56 }
    57 Engineer.prototype = new WorkerBee();
    60 var pat = new Engineer( "indy" );
    62 var les = new Engineer();
    64 new TestCase( SECTION,
    65 	      "var pat = new Engineer(\"indy\"); pat.name",
    66 	      "",
    67 	      pat.name );
    69 new TestCase( SECTION,
    70 	      "pat.dept",
    71 	      "engineering",
    72 	      pat.dept );
    74 new TestCase( SECTION,
    75 	      "pat.projects.length",
    76 	      0,
    77 	      pat.projects.length );
    79 new TestCase( SECTION,
    80 	      "pat.machine",
    81 	      "indy",
    82 	      pat.machine );
    84 new TestCase( SECTION,
    85 	      "pat.__proto__ == Engineer.prototype",
    86 	      true,
    87 	      pat.__proto__ == Engineer.prototype );
    89 new TestCase( SECTION,
    90 	      "var les = new Engineer(); les.name",
    91 	      "",
    92 	      les.name );
    94 new TestCase( SECTION,
    95 	      "les.dept",
    96 	      "engineering",
    97 	      les.dept );
    99 new TestCase( SECTION,
   100 	      "les.projects.length",
   101 	      0,
   102 	      les.projects.length );
   104 new TestCase( SECTION,
   105 	      "les.machine",
   106 	      "",
   107 	      les.machine );
   109 new TestCase( SECTION,
   110 	      "les.__proto__ == Engineer.prototype",
   111 	      true,
   112 	      les.__proto__ == Engineer.prototype );
   115 test();

mercurial