1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_3/inherit/proto_12.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 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_12.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 + No Multiple Inheritance 1.21 + 1.22 + Author: christine@netscape.com 1.23 + Date: 12 november 1997 1.24 +*/ 1.25 + 1.26 +var SECTION = "proto_12"; 1.27 +var VERSION = "JS1_3"; 1.28 +var TITLE = "No Multiple Inheritance"; 1.29 + 1.30 +startTest(); 1.31 +writeHeaderToLog( SECTION + " "+ TITLE); 1.32 + 1.33 +function Employee ( name, dept ) { 1.34 + this.name = name || ""; 1.35 + this.dept = dept || "general"; 1.36 + this.id = idCounter++; 1.37 +} 1.38 +function Manager () { 1.39 + this.reports = []; 1.40 +} 1.41 +Manager.prototype = new Employee(); 1.42 + 1.43 +function WorkerBee ( name, dept, projs ) { 1.44 + this.base = Employee; 1.45 + this.base( name, dept) 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 Hobbyist( hobby ) { 1.57 + this.hobby = hobby || "yodeling"; 1.58 +} 1.59 + 1.60 +function Engineer ( name, projs, machine, hobby ) { 1.61 + this.base1 = WorkerBee; 1.62 + this.base1( name, "engineering", projs ) 1.63 + 1.64 + this.base2 = Hobbyist; 1.65 + this.base2( hobby ); 1.66 + 1.67 + this.projects = projs || new Array(); 1.68 + this.machine = machine || ""; 1.69 +} 1.70 +Engineer.prototype = new WorkerBee(); 1.71 + 1.72 +var idCounter = 1; 1.73 + 1.74 +var les = new Engineer( "Morris, Les", new Array("JavaScript"), "indy" ); 1.75 + 1.76 +Hobbyist.prototype.equipment = [ "horn", "mountain", "goat" ]; 1.77 + 1.78 +new TestCase( SECTION, 1.79 + "les.name", 1.80 + "Morris, Les", 1.81 + les.name ); 1.82 + 1.83 +new TestCase( SECTION, 1.84 + "les.dept", 1.85 + "engineering", 1.86 + les.dept ); 1.87 + 1.88 +Array.prototype.getClass = Object.prototype.toString; 1.89 + 1.90 +new TestCase( SECTION, 1.91 + "les.projects.getClass()", 1.92 + "[object Array]", 1.93 + les.projects.getClass() ); 1.94 + 1.95 +new TestCase( SECTION, 1.96 + "les.projects[0]", 1.97 + "JavaScript", 1.98 + les.projects[0] ); 1.99 + 1.100 +new TestCase( SECTION, 1.101 + "les.machine", 1.102 + "indy", 1.103 + les.machine ); 1.104 + 1.105 +new TestCase( SECTION, 1.106 + "les.hobby", 1.107 + "yodeling", 1.108 + les.hobby ); 1.109 + 1.110 +new TestCase( SECTION, 1.111 + "les.equpment", 1.112 + void 0, 1.113 + les.equipment ); 1.114 + 1.115 +test();