js/src/tests/js1_3/inherit/proto_7.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_7.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     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_7.js
    1.12 +   Section:
    1.13 +   Description:        Adding Properties to the Prototype Object
    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
    1.24 +
    1.25 +   Author:             christine@netscape.com
    1.26 +   Date:               12 november 1997
    1.27 +*/
    1.28 +
    1.29 +var SECTION = "proto_6";
    1.30 +var VERSION = "JS1_3";
    1.31 +var TITLE   = "Adding properties to the Prototype Object";
    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 WorkerBee ( name, dept, projs ) {
    1.41 +  this.base = Employee;
    1.42 +  this.base( name, dept)
    1.43 +    this.projects = projs || new Array();
    1.44 +}
    1.45 +WorkerBee.prototype = new Employee();
    1.46 +
    1.47 +function Engineer ( name, projs, machine ) {
    1.48 +  this.base = WorkerBee;
    1.49 +  this.base( name, "engineering", projs )
    1.50 +    this.machine = machine || "";
    1.51 +}
    1.52 +// Engineer.prototype = new WorkerBee();
    1.53 +
    1.54 +var pat = new Engineer( "Toonces, Pat",
    1.55 +			["SpiderMonkey", "Rhino"],
    1.56 +			"indy" );
    1.57 +
    1.58 +Employee.prototype.specialty = "none";
    1.59 +
    1.60 +
    1.61 +// Pat, the Engineer
    1.62 +
    1.63 +new TestCase( SECTION,
    1.64 +	      "pat.name",
    1.65 +	      "Toonces, Pat",
    1.66 +	      pat.name );
    1.67 +
    1.68 +new TestCase( SECTION,
    1.69 +	      "pat.dept",
    1.70 +	      "engineering",
    1.71 +	      pat.dept );
    1.72 +
    1.73 +new TestCase( SECTION,
    1.74 +	      "pat.projects.length",
    1.75 +	      2,
    1.76 +	      pat.projects.length );
    1.77 +
    1.78 +new TestCase( SECTION,
    1.79 +	      "pat.projects[0]",
    1.80 +	      "SpiderMonkey",
    1.81 +	      pat.projects[0] );
    1.82 +
    1.83 +new TestCase( SECTION,
    1.84 +	      "pat.projects[1]",
    1.85 +	      "Rhino",
    1.86 +	      pat.projects[1] );
    1.87 +
    1.88 +new TestCase( SECTION,
    1.89 +	      "pat.machine",
    1.90 +	      "indy",
    1.91 +	      pat.machine );
    1.92 +
    1.93 +new TestCase( SECTION,
    1.94 +	      "pat.specialty",
    1.95 +	      void 0,
    1.96 +	      pat.specialty );
    1.97 +
    1.98 +test();

mercurial