1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_3/inherit/proto_6.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 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_6.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_6"; 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 ( name, dept, projs ) { 1.46 + this.base = Employee; 1.47 + this.base( name, dept) 1.48 + this.projects = projs || new Array(); 1.49 +} 1.50 + 1.51 +WorkerBee.prototype = new Employee(); 1.52 + 1.53 +function SalesPerson () { 1.54 + this.dept = "sales"; 1.55 + this.quota = 100; 1.56 +} 1.57 +SalesPerson.prototype = new WorkerBee(); 1.58 + 1.59 +function Engineer ( name, projs, machine ) { 1.60 + this.base = WorkerBee; 1.61 + this.base( name, "engineering", projs ) 1.62 + this.machine = machine || ""; 1.63 +} 1.64 +Engineer.prototype = new WorkerBee(); 1.65 + 1.66 +var pat = new Engineer( "Toonces, Pat", 1.67 + ["SpiderMonkey", "Rhino"], 1.68 + "indy" ); 1.69 + 1.70 +var les = new WorkerBee( "Morris, Les", 1.71 + "Training", 1.72 + ["Hippo"] ) 1.73 + 1.74 + var terry = new Employee( "Boomberi, Terry", 1.75 + "Marketing" ); 1.76 + 1.77 +// Pat, the Engineer 1.78 + 1.79 +new TestCase( SECTION, 1.80 + "pat.name", 1.81 + "Toonces, Pat", 1.82 + pat.name ); 1.83 + 1.84 +new TestCase( SECTION, 1.85 + "pat.dept", 1.86 + "engineering", 1.87 + pat.dept ); 1.88 + 1.89 +new TestCase( SECTION, 1.90 + "pat.projects.length", 1.91 + 2, 1.92 + pat.projects.length ); 1.93 + 1.94 +new TestCase( SECTION, 1.95 + "pat.projects[0]", 1.96 + "SpiderMonkey", 1.97 + pat.projects[0] ); 1.98 + 1.99 +new TestCase( SECTION, 1.100 + "pat.projects[1]", 1.101 + "Rhino", 1.102 + pat.projects[1] ); 1.103 + 1.104 +new TestCase( SECTION, 1.105 + "pat.machine", 1.106 + "indy", 1.107 + pat.machine ); 1.108 + 1.109 + 1.110 +// Les, the WorkerBee 1.111 + 1.112 +new TestCase( SECTION, 1.113 + "les.name", 1.114 + "Morris, Les", 1.115 + les.name ); 1.116 + 1.117 +new TestCase( SECTION, 1.118 + "les.dept", 1.119 + "Training", 1.120 + les.dept ); 1.121 + 1.122 +new TestCase( SECTION, 1.123 + "les.projects.length", 1.124 + 1, 1.125 + les.projects.length ); 1.126 + 1.127 +new TestCase( SECTION, 1.128 + "les.projects[0]", 1.129 + "Hippo", 1.130 + les.projects[0] ); 1.131 + 1.132 +// Terry, the Employee 1.133 +new TestCase( SECTION, 1.134 + "terry.name", 1.135 + "Boomberi, Terry", 1.136 + terry.name ); 1.137 + 1.138 +new TestCase( SECTION, 1.139 + "terry.dept", 1.140 + "Marketing", 1.141 + terry.dept ); 1.142 +test(); 1.143 +