1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9
* SUMMARY: A [DontEnum] prop, if overridden, should appear in for-in loops.
10
* See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
12
* NOTE: some inefficiencies in the test are made for the sake of readability.
13
* For example, we quote string values like "Hi" in lines like this:
15
* actual = enumerateThis(obj);
16
* expect = '{prop:"Hi"}';
18
* But enumerateThis(obj) gets literal value Hi for obj.prop, not
19
* literal "Hi". We take care of all these details in the
20
* compactThis(), sortThis() functions. Sorting properties
21
* alphabetically is necessary for the test to work in Rhino.
23
//-----------------------------------------------------------------------------
25
var BUGNUMBER = 90596;
26
var summary = '[DontEnum] props (if overridden) should appear in for-in loops';
34
var actualvalues = [];
36
var expectedvalues = [];
40
status = inSection(1);
42
actual = enumerateThis(obj);
43
expect = '{toString:9}';
46
status = inSection(2);
47
obj = {hasOwnProperty:"Hi"};
48
actual = enumerateThis(obj);
49
expect = '{hasOwnProperty:"Hi"}';
52
status = inSection(3);
53
obj = {toString:9, hasOwnProperty:"Hi"};
54
actual = enumerateThis(obj);
55
expect = '{toString:9, hasOwnProperty:"Hi"}';
58
status = inSection(4);
59
obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
60
actual = enumerateThis(obj);
61
expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
65
// TRY THE SAME THING IN EVAL CODE
68
status = inSection(5);
69
s = 'obj = {toString:9}';
71
actual = enumerateThis(obj);
72
expect = '{toString:9}';
75
status = inSection(6);
76
s = 'obj = {hasOwnProperty:"Hi"}';
78
actual = enumerateThis(obj);
79
expect = '{hasOwnProperty:"Hi"}';
82
status = inSection(7);
83
s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
85
actual = enumerateThis(obj);
86
expect = '{toString:9, hasOwnProperty:"Hi"}';
89
status = inSection(8);
90
s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
92
actual = enumerateThis(obj);
93
expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
97
// TRY THE SAME THING IN FUNCTION CODE
100
status = inSection(9);
101
var s = 'obj = {toString:9}';
103
actual = enumerateThis(obj);
104
expect = '{toString:9}';
111
status = inSection(10);
112
var s = 'obj = {hasOwnProperty:"Hi"}';
114
actual = enumerateThis(obj);
115
expect = '{hasOwnProperty:"Hi"}';
122
status = inSection(11);
123
var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
125
actual = enumerateThis(obj);
126
expect = '{toString:9, hasOwnProperty:"Hi"}';
133
status = inSection(12);
134
var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
136
actual = enumerateThis(obj);
137
expect = '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
144
//-----------------------------------------------------------------------------
146
//-----------------------------------------------------------------------------
150
function enumerateThis(obj)
152
var arr = new Array();
154
for (var prop in obj)
156
arr.push(prop + cnCOLON + obj[prop]);
159
var ret = addBraces(String(arr));
164
function addBraces(text)
166
return cnLBRACE + text + cnRBRACE;
171
* Sort properties alphabetically so the test will work in Rhino
175
statusitems[UBound] = status;
176
actualvalues[UBound] = sortThis(actual);
177
expectedvalues[UBound] = sortThis(expect);
183
* Takes a string of the form '{"c", "b", "a", 2}' and returns '{2,a,b,c}'
185
function sortThis(sList)
187
sList = compactThis(sList);
188
sList = stripBraces(sList);
189
var arr = sList.split(cnCOMMA);
191
var ret = String(arr);
192
ret = addBraces(ret);
198
* Strips out any whitespace or quotes from the text -
200
function compactThis(text)
205
for (var i=0; i<text.length; i++)
207
charCode = text.charCodeAt(i);
209
if (!isWhiteSpace(charCode) && !isQuote(charCode))
210
ret += text.charAt(i);
217
function isWhiteSpace(charCode)
225
case (0x000A): // '\n'
226
case (0x000D): // '\r'
236
function isQuote(charCode)
240
case (0x0027): // single quote
241
case (0x0022): // double quote
252
* strips off braces at beginning and end of text -
254
function stripBraces(text)
256
// remember to escape the braces...
257
var arr = text.match(/^\{(.*)\}$/);
259
// defend against a null match...
260
if (arr != null && arr[1] != null)
269
printBugNumber(BUGNUMBER);
270
printStatus (summary);
272
for (var i=0; i<UBound; i++)
274
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);