js/src/tests/js1_5/Object/regress-90596-003.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 * Date: 28 August 2001
michael@0 8 *
michael@0 9 * SUMMARY: A [DontEnum] prop, if overridden, should appear in for-in loops.
michael@0 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
michael@0 11 *
michael@0 12 * NOTE: some inefficiencies in the test are made for the sake of readability.
michael@0 13 * For example, we quote string values like "Hi" in lines like this:
michael@0 14 *
michael@0 15 * actual = enumerateThis(obj);
michael@0 16 * expect = '{prop:"Hi"}';
michael@0 17 *
michael@0 18 * But enumerateThis(obj) gets literal value Hi for obj.prop, not
michael@0 19 * literal "Hi". We take care of all these details in the
michael@0 20 * compactThis(), sortThis() functions. Sorting properties
michael@0 21 * alphabetically is necessary for the test to work in Rhino.
michael@0 22 */
michael@0 23 //-----------------------------------------------------------------------------
michael@0 24 var UBound = 0;
michael@0 25 var BUGNUMBER = 90596;
michael@0 26 var summary = '[DontEnum] props (if overridden) should appear in for-in loops';
michael@0 27 var cnCOMMA = ',';
michael@0 28 var cnCOLON = ':';
michael@0 29 var cnLBRACE = '{';
michael@0 30 var cnRBRACE = '}';
michael@0 31 var status = '';
michael@0 32 var statusitems = [];
michael@0 33 var actual = '';
michael@0 34 var actualvalues = [];
michael@0 35 var expect= '';
michael@0 36 var expectedvalues = [];
michael@0 37 var obj = {};
michael@0 38
michael@0 39
michael@0 40 status = inSection(1);
michael@0 41 obj = {toString:9};
michael@0 42 actual = enumerateThis(obj);
michael@0 43 expect = '{toString:9}';
michael@0 44 addThis();
michael@0 45
michael@0 46 status = inSection(2);
michael@0 47 obj = {hasOwnProperty:"Hi"};
michael@0 48 actual = enumerateThis(obj);
michael@0 49 expect = '{hasOwnProperty:"Hi"}';
michael@0 50 addThis();
michael@0 51
michael@0 52 status = inSection(3);
michael@0 53 obj = {toString:9, hasOwnProperty:"Hi"};
michael@0 54 actual = enumerateThis(obj);
michael@0 55 expect = '{toString:9, hasOwnProperty:"Hi"}';
michael@0 56 addThis();
michael@0 57
michael@0 58 status = inSection(4);
michael@0 59 obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
michael@0 60 actual = enumerateThis(obj);
michael@0 61 expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
michael@0 62 addThis();
michael@0 63
michael@0 64
michael@0 65 // TRY THE SAME THING IN EVAL CODE
michael@0 66 var s = '';
michael@0 67
michael@0 68 status = inSection(5);
michael@0 69 s = 'obj = {toString:9}';
michael@0 70 eval(s);
michael@0 71 actual = enumerateThis(obj);
michael@0 72 expect = '{toString:9}';
michael@0 73 addThis();
michael@0 74
michael@0 75 status = inSection(6);
michael@0 76 s = 'obj = {hasOwnProperty:"Hi"}';
michael@0 77 eval(s);
michael@0 78 actual = enumerateThis(obj);
michael@0 79 expect = '{hasOwnProperty:"Hi"}';
michael@0 80 addThis();
michael@0 81
michael@0 82 status = inSection(7);
michael@0 83 s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
michael@0 84 eval(s);
michael@0 85 actual = enumerateThis(obj);
michael@0 86 expect = '{toString:9, hasOwnProperty:"Hi"}';
michael@0 87 addThis();
michael@0 88
michael@0 89 status = inSection(8);
michael@0 90 s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
michael@0 91 eval(s);
michael@0 92 actual = enumerateThis(obj);
michael@0 93 expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
michael@0 94 addThis();
michael@0 95
michael@0 96
michael@0 97 // TRY THE SAME THING IN FUNCTION CODE
michael@0 98 function A()
michael@0 99 {
michael@0 100 status = inSection(9);
michael@0 101 var s = 'obj = {toString:9}';
michael@0 102 eval(s);
michael@0 103 actual = enumerateThis(obj);
michael@0 104 expect = '{toString:9}';
michael@0 105 addThis();
michael@0 106 }
michael@0 107 A();
michael@0 108
michael@0 109 function B()
michael@0 110 {
michael@0 111 status = inSection(10);
michael@0 112 var s = 'obj = {hasOwnProperty:"Hi"}';
michael@0 113 eval(s);
michael@0 114 actual = enumerateThis(obj);
michael@0 115 expect = '{hasOwnProperty:"Hi"}';
michael@0 116 addThis();
michael@0 117 }
michael@0 118 B();
michael@0 119
michael@0 120 function C()
michael@0 121 {
michael@0 122 status = inSection(11);
michael@0 123 var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
michael@0 124 eval(s);
michael@0 125 actual = enumerateThis(obj);
michael@0 126 expect = '{toString:9, hasOwnProperty:"Hi"}';
michael@0 127 addThis();
michael@0 128 }
michael@0 129 C();
michael@0 130
michael@0 131 function D()
michael@0 132 {
michael@0 133 status = inSection(12);
michael@0 134 var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
michael@0 135 eval(s);
michael@0 136 actual = enumerateThis(obj);
michael@0 137 expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
michael@0 138 addThis();
michael@0 139 }
michael@0 140 D();
michael@0 141
michael@0 142
michael@0 143
michael@0 144 //-----------------------------------------------------------------------------
michael@0 145 test();
michael@0 146 //-----------------------------------------------------------------------------
michael@0 147
michael@0 148
michael@0 149
michael@0 150 function enumerateThis(obj)
michael@0 151 {
michael@0 152 var arr = new Array();
michael@0 153
michael@0 154 for (var prop in obj)
michael@0 155 {
michael@0 156 arr.push(prop + cnCOLON + obj[prop]);
michael@0 157 }
michael@0 158
michael@0 159 var ret = addBraces(String(arr));
michael@0 160 return ret;
michael@0 161 }
michael@0 162
michael@0 163
michael@0 164 function addBraces(text)
michael@0 165 {
michael@0 166 return cnLBRACE + text + cnRBRACE;
michael@0 167 }
michael@0 168
michael@0 169
michael@0 170 /*
michael@0 171 * Sort properties alphabetically so the test will work in Rhino
michael@0 172 */
michael@0 173 function addThis()
michael@0 174 {
michael@0 175 statusitems[UBound] = status;
michael@0 176 actualvalues[UBound] = sortThis(actual);
michael@0 177 expectedvalues[UBound] = sortThis(expect);
michael@0 178 UBound++;
michael@0 179 }
michael@0 180
michael@0 181
michael@0 182 /*
michael@0 183 * Takes a string of the form '{"c", "b", "a", 2}' and returns '{2,a,b,c}'
michael@0 184 */
michael@0 185 function sortThis(sList)
michael@0 186 {
michael@0 187 sList = compactThis(sList);
michael@0 188 sList = stripBraces(sList);
michael@0 189 var arr = sList.split(cnCOMMA);
michael@0 190 arr = arr.sort();
michael@0 191 var ret = String(arr);
michael@0 192 ret = addBraces(ret);
michael@0 193 return ret;
michael@0 194 }
michael@0 195
michael@0 196
michael@0 197 /*
michael@0 198 * Strips out any whitespace or quotes from the text -
michael@0 199 */
michael@0 200 function compactThis(text)
michael@0 201 {
michael@0 202 var charCode = 0;
michael@0 203 var ret = '';
michael@0 204
michael@0 205 for (var i=0; i<text.length; i++)
michael@0 206 {
michael@0 207 charCode = text.charCodeAt(i);
michael@0 208
michael@0 209 if (!isWhiteSpace(charCode) && !isQuote(charCode))
michael@0 210 ret += text.charAt(i);
michael@0 211 }
michael@0 212
michael@0 213 return ret;
michael@0 214 }
michael@0 215
michael@0 216
michael@0 217 function isWhiteSpace(charCode)
michael@0 218 {
michael@0 219 switch (charCode)
michael@0 220 {
michael@0 221 case (0x0009):
michael@0 222 case (0x000B):
michael@0 223 case (0x000C):
michael@0 224 case (0x0020):
michael@0 225 case (0x000A): // '\n'
michael@0 226 case (0x000D): // '\r'
michael@0 227 return true;
michael@0 228 break;
michael@0 229
michael@0 230 default:
michael@0 231 return false;
michael@0 232 }
michael@0 233 }
michael@0 234
michael@0 235
michael@0 236 function isQuote(charCode)
michael@0 237 {
michael@0 238 switch (charCode)
michael@0 239 {
michael@0 240 case (0x0027): // single quote
michael@0 241 case (0x0022): // double quote
michael@0 242 return true;
michael@0 243 break;
michael@0 244
michael@0 245 default:
michael@0 246 return false;
michael@0 247 }
michael@0 248 }
michael@0 249
michael@0 250
michael@0 251 /*
michael@0 252 * strips off braces at beginning and end of text -
michael@0 253 */
michael@0 254 function stripBraces(text)
michael@0 255 {
michael@0 256 // remember to escape the braces...
michael@0 257 var arr = text.match(/^\{(.*)\}$/);
michael@0 258
michael@0 259 // defend against a null match...
michael@0 260 if (arr != null && arr[1] != null)
michael@0 261 return arr[1];
michael@0 262 return text;
michael@0 263 }
michael@0 264
michael@0 265
michael@0 266 function test()
michael@0 267 {
michael@0 268 enterFunc ('test');
michael@0 269 printBugNumber(BUGNUMBER);
michael@0 270 printStatus (summary);
michael@0 271
michael@0 272 for (var i=0; i<UBound; i++)
michael@0 273 {
michael@0 274 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
michael@0 275 }
michael@0 276
michael@0 277 exitFunc ('test');
michael@0 278 }

mercurial