|
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/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: regexp-enumerate-001.js |
|
9 ECMA V2 Section: |
|
10 Description: Regression Test. |
|
11 |
|
12 If instance Native Object have properties that are enumerable, |
|
13 JavaScript enumerated through the properties twice. This only |
|
14 happened if objects had been instantiated, but their properties |
|
15 had not been enumerated. ie, the object inherited properties |
|
16 from its prototype that are enumerated. |
|
17 |
|
18 In the core JavaScript, this is only a problem with RegExp |
|
19 objects, since the inherited properties of most core JavaScript |
|
20 objects are not enumerated. |
|
21 |
|
22 Author: christine@netscape.com, pschwartau@netscape.com |
|
23 Date: 12 November 1997 |
|
24 Modified: 14 July 2002 |
|
25 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155291 |
|
26 ECMA-262 Ed.3 Sections 15.10.7.1 through 15.10.7.5 |
|
27 RegExp properties should be DontEnum |
|
28 * |
|
29 */ |
|
30 // onerror = err; |
|
31 |
|
32 var SECTION = "regexp-enumerate-001"; |
|
33 var VERSION = "ECMA_2"; |
|
34 var TITLE = "Regression Test for Enumerating Properties"; |
|
35 |
|
36 var BUGNUMBER="339403"; |
|
37 |
|
38 startTest(); |
|
39 writeHeaderToLog( SECTION + " "+ TITLE); |
|
40 |
|
41 /* |
|
42 * This test expects RegExp instances to have four enumerated properties: |
|
43 * source, global, ignoreCase, and lastIndex |
|
44 * |
|
45 * 99.01.25: now they also have a multiLine instance property. |
|
46 * |
|
47 */ |
|
48 |
|
49 |
|
50 var r = new RegExp(); |
|
51 |
|
52 var e = new Array(); |
|
53 |
|
54 var t = new TestRegExp(); |
|
55 |
|
56 for ( p in r ) { e[e.length] = { property:p, value:r[p] }; t.addProperty( p, r[p]) }; |
|
57 |
|
58 new TestCase( SECTION, |
|
59 "r = new RegExp(); e = new Array(); "+ |
|
60 "for ( p in r ) { e[e.length] = { property:p, value:r[p] }; e.length", |
|
61 0, |
|
62 e.length ); |
|
63 |
|
64 test(); |
|
65 |
|
66 function TestRegExp() { |
|
67 this.addProperty = addProperty; |
|
68 } |
|
69 function addProperty(name, value) { |
|
70 var pass = false; |
|
71 |
|
72 if ( eval("this."+name) != void 0 ) { |
|
73 pass = true; |
|
74 } else { |
|
75 eval( "this."+ name+" = "+ false ); |
|
76 } |
|
77 |
|
78 new TestCase( SECTION, |
|
79 "Property: " + name +" already enumerated?", |
|
80 false, |
|
81 pass ); |
|
82 |
|
83 if ( gTestcases[ gTestcases.length-1].passed == false ) { |
|
84 gTestcases[gTestcases.length-1].reason = "property already enumerated"; |
|
85 |
|
86 } |
|
87 |
|
88 } |