1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/RegExp/regexp-enumerate-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: regexp-enumerate-001.js 1.12 + ECMA V2 Section: 1.13 + Description: Regression Test. 1.14 + 1.15 + If instance Native Object have properties that are enumerable, 1.16 + JavaScript enumerated through the properties twice. This only 1.17 + happened if objects had been instantiated, but their properties 1.18 + had not been enumerated. ie, the object inherited properties 1.19 + from its prototype that are enumerated. 1.20 + 1.21 + In the core JavaScript, this is only a problem with RegExp 1.22 + objects, since the inherited properties of most core JavaScript 1.23 + objects are not enumerated. 1.24 + 1.25 + Author: christine@netscape.com, pschwartau@netscape.com 1.26 + Date: 12 November 1997 1.27 + Modified: 14 July 2002 1.28 + Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155291 1.29 + ECMA-262 Ed.3 Sections 15.10.7.1 through 15.10.7.5 1.30 + RegExp properties should be DontEnum 1.31 + * 1.32 + */ 1.33 +// onerror = err; 1.34 + 1.35 +var SECTION = "regexp-enumerate-001"; 1.36 +var VERSION = "ECMA_2"; 1.37 +var TITLE = "Regression Test for Enumerating Properties"; 1.38 + 1.39 +var BUGNUMBER="339403"; 1.40 + 1.41 +startTest(); 1.42 +writeHeaderToLog( SECTION + " "+ TITLE); 1.43 + 1.44 +/* 1.45 + * This test expects RegExp instances to have four enumerated properties: 1.46 + * source, global, ignoreCase, and lastIndex 1.47 + * 1.48 + * 99.01.25: now they also have a multiLine instance property. 1.49 + * 1.50 + */ 1.51 + 1.52 + 1.53 +var r = new RegExp(); 1.54 + 1.55 +var e = new Array(); 1.56 + 1.57 +var t = new TestRegExp(); 1.58 + 1.59 +for ( p in r ) { e[e.length] = { property:p, value:r[p] }; t.addProperty( p, r[p]) }; 1.60 + 1.61 +new TestCase( SECTION, 1.62 + "r = new RegExp(); e = new Array(); "+ 1.63 + "for ( p in r ) { e[e.length] = { property:p, value:r[p] }; e.length", 1.64 + 0, 1.65 + e.length ); 1.66 + 1.67 +test(); 1.68 + 1.69 +function TestRegExp() { 1.70 + this.addProperty = addProperty; 1.71 +} 1.72 +function addProperty(name, value) { 1.73 + var pass = false; 1.74 + 1.75 + if ( eval("this."+name) != void 0 ) { 1.76 + pass = true; 1.77 + } else { 1.78 + eval( "this."+ name+" = "+ false ); 1.79 + } 1.80 + 1.81 + new TestCase( SECTION, 1.82 + "Property: " + name +" already enumerated?", 1.83 + false, 1.84 + pass ); 1.85 + 1.86 + if ( gTestcases[ gTestcases.length-1].passed == false ) { 1.87 + gTestcases[gTestcases.length-1].reason = "property already enumerated"; 1.88 + 1.89 + } 1.90 + 1.91 +}