| 1 |
/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 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: [email protected], [email protected] |
| 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 TITLE = "Regression Test for Enumerating Properties"; |
| 34 |
|
| 35 |
var BUGNUMBER="339403"; |
| 36 |
|
| 37 |
printBugNumber(BUGNUMBER); |
| 38 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 39 |
|
| 40 |
/* |
| 41 |
* This test expects RegExp instances to have four enumerated properties: |
| 42 |
* source, global, ignoreCase, and lastIndex |
| 43 |
* |
| 44 |
* 99.01.25: now they also have a multiLine instance property. |
| 45 |
* |
| 46 |
*/ |
| 47 |
|
| 48 |
|
| 49 |
var r = new RegExp(); |
| 50 |
|
| 51 |
var e = new Array(); |
| 52 |
|
| 53 |
var t = new TestRegExp(); |
| 54 |
|
| 55 |
for ( p in r ) { e[e.length] = { property:p, value:r[p] }; t.addProperty( p, r[p]) }; |
| 56 |
|
| 57 |
new TestCase( "r = new RegExp(); e = new Array(); "+ |
| 58 |
"for ( p in r ) { e[e.length] = { property:p, value:r[p] }; e.length", |
| 59 |
0, |
| 60 |
e.length ); |
| 61 |
|
| 62 |
test(); |
| 63 |
|
| 64 |
function TestRegExp() { |
| 65 |
this.addProperty = addProperty; |
| 66 |
} |
| 67 |
function addProperty(name, value) { |
| 68 |
var pass = false; |
| 69 |
|
| 70 |
if ( eval("this."+name) != void 0 ) { |
| 71 |
pass = true; |
| 72 |
} else { |
| 73 |
eval( "this."+ name+" = "+ false ); |
| 74 |
} |
| 75 |
|
| 76 |
new TestCase( "Property: " + name +" already enumerated?", |
| 77 |
false, |
| 78 |
pass ); |
| 79 |
} |