js/src/tests/js1_5/Object/regress-137000.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 *
michael@0 8 * Date: 03 June 2002
michael@0 9 * SUMMARY: Function param or local var with same name as a function property
michael@0 10 *
michael@0 11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=137000
michael@0 12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=138708
michael@0 13 * See http://bugzilla.mozilla.org/show_bug.cgi?id=150032
michael@0 14 * See http://bugzilla.mozilla.org/show_bug.cgi?id=150859
michael@0 15 *
michael@0 16 */
michael@0 17 //-----------------------------------------------------------------------------
michael@0 18 var UBound = 0;
michael@0 19 var BUGNUMBER = 137000;
michael@0 20 var summary = 'Function param or local var with same name as a function prop';
michael@0 21 var status = '';
michael@0 22 var statusitems = [];
michael@0 23 var actual = '';
michael@0 24 var actualvalues = [];
michael@0 25 var expect= '';
michael@0 26 var expectedvalues = [];
michael@0 27
michael@0 28
michael@0 29 /*
michael@0 30 * Note use of 'x' both for the parameter to f,
michael@0 31 * and as a property name for |f| as an object
michael@0 32 */
michael@0 33 function f(x)
michael@0 34 {
michael@0 35 }
michael@0 36
michael@0 37 status = inSection(1);
michael@0 38 f.x = 12;
michael@0 39 actual = f.x;
michael@0 40 expect = 12;
michael@0 41 addThis();
michael@0 42
michael@0 43
michael@0 44
michael@0 45 /*
michael@0 46 * A more elaborate example, using the call() method
michael@0 47 * to chain constructors from child to parent.
michael@0 48 *
michael@0 49 * The key point is the use of the same name 'p' for both
michael@0 50 * the parameter to the constructor, and as a property name
michael@0 51 */
michael@0 52 function parentObject(p)
michael@0 53 {
michael@0 54 this.p = 1;
michael@0 55 }
michael@0 56
michael@0 57 function childObject()
michael@0 58 {
michael@0 59 parentObject.call(this);
michael@0 60 }
michael@0 61 childObject.prototype = parentObject;
michael@0 62
michael@0 63 status = inSection(2);
michael@0 64 var objParent = new parentObject();
michael@0 65 actual = objParent.p;
michael@0 66 expect = 1;
michael@0 67 addThis();
michael@0 68
michael@0 69 status = inSection(3);
michael@0 70 var objChild = new childObject();
michael@0 71 actual = objChild.p;
michael@0 72 expect = 1;
michael@0 73 addThis();
michael@0 74
michael@0 75
michael@0 76
michael@0 77 /*
michael@0 78 * A similar set-up. Here the same name is being used for
michael@0 79 * the parameter to both the Base and Child constructors,
michael@0 80 */
michael@0 81 function Base(id)
michael@0 82 {
michael@0 83 }
michael@0 84
michael@0 85 function Child(id)
michael@0 86 {
michael@0 87 this.prop = id;
michael@0 88 }
michael@0 89 Child.prototype=Base;
michael@0 90
michael@0 91 status = inSection(4);
michael@0 92 var c1 = new Child('child1');
michael@0 93 actual = c1.prop;
michael@0 94 expect = 'child1';
michael@0 95 addThis();
michael@0 96
michael@0 97
michael@0 98
michael@0 99 /*
michael@0 100 * Use same identifier as a property name, too -
michael@0 101 */
michael@0 102 function BaseX(id)
michael@0 103 {
michael@0 104 }
michael@0 105
michael@0 106 function ChildX(id)
michael@0 107 {
michael@0 108 this.id = id;
michael@0 109 }
michael@0 110 ChildX.prototype=BaseX;
michael@0 111
michael@0 112 status = inSection(5);
michael@0 113 c1 = new ChildX('child1');
michael@0 114 actual = c1.id;
michael@0 115 expect = 'child1';
michael@0 116 addThis();
michael@0 117
michael@0 118
michael@0 119
michael@0 120 /*
michael@0 121 * From http://bugzilla.mozilla.org/show_bug.cgi?id=150032
michael@0 122 *
michael@0 123 * Here the same name is being used both for a local variable
michael@0 124 * declared in g(), and as a property name for |g| as an object
michael@0 125 */
michael@0 126 function g()
michael@0 127 {
michael@0 128 var propA = g.propA;
michael@0 129 var propB = g.propC;
michael@0 130
michael@0 131 this.getVarA = function() {return propA;}
michael@0 132 this.getVarB = function() {return propB;}
michael@0 133 }
michael@0 134 g.propA = 'A';
michael@0 135 g.propB = 'B';
michael@0 136 g.propC = 'C';
michael@0 137 var obj = new g();
michael@0 138
michael@0 139 status = inSection(6);
michael@0 140 actual = obj.getVarA(); // this one was returning 'undefined'
michael@0 141 expect = 'A';
michael@0 142 addThis();
michael@0 143
michael@0 144 status = inSection(7);
michael@0 145 actual = obj.getVarB(); // this one is easy; it never failed
michael@0 146 expect = 'C';
michael@0 147 addThis();
michael@0 148
michael@0 149
michael@0 150
michael@0 151 /*
michael@0 152 * By martin.honnen@gmx.de
michael@0 153 * From http://bugzilla.mozilla.org/show_bug.cgi?id=150859
michael@0 154 *
michael@0 155 * Here the same name is being used for a local var in F
michael@0 156 * and as a property name for |F| as an object
michael@0 157 *
michael@0 158 * Twist: the property is added via another function.
michael@0 159 */
michael@0 160 function setFProperty(val)
michael@0 161 {
michael@0 162 F.propA = val;
michael@0 163 }
michael@0 164
michael@0 165 function F()
michael@0 166 {
michael@0 167 var propA = 'Local variable in F';
michael@0 168 }
michael@0 169
michael@0 170 status = inSection(8);
michael@0 171 setFProperty('Hello');
michael@0 172 actual = F.propA; // this was returning 'undefined'
michael@0 173 expect = 'Hello';
michael@0 174 addThis();
michael@0 175
michael@0 176
michael@0 177
michael@0 178
michael@0 179 //-----------------------------------------------------------------------------
michael@0 180 test();
michael@0 181 //-----------------------------------------------------------------------------
michael@0 182
michael@0 183
michael@0 184
michael@0 185 function addThis()
michael@0 186 {
michael@0 187 statusitems[UBound] = status;
michael@0 188 actualvalues[UBound] = actual;
michael@0 189 expectedvalues[UBound] = expect;
michael@0 190 UBound++;
michael@0 191 }
michael@0 192
michael@0 193
michael@0 194 function test()
michael@0 195 {
michael@0 196 enterFunc('test');
michael@0 197 printBugNumber(BUGNUMBER);
michael@0 198 printStatus(summary);
michael@0 199
michael@0 200 for (var i=0; i<UBound; i++)
michael@0 201 {
michael@0 202 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
michael@0 203 }
michael@0 204
michael@0 205 exitFunc ('test');
michael@0 206 }

mercurial