js/src/tests/js1_5/extensions/regress-90596-002.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial