]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma_3/RegExp/regress-57631.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_3 / RegExp / regress-57631.js
CommitLineData
b37bf2e1
A
1/*
2* The contents of this file are subject to the Netscape Public
3* License Version 1.1 (the "License"); you may not use this file
4* except in compliance with the License. You may obtain a copy of
5* the License at http://www.mozilla.org/NPL/
6*
7* Software distributed under the License is distributed on an "AS
8* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9* implied. See the License for the specific language governing
10* rights and limitations under the License.
11*
12* The Original Code is mozilla.org code.
13*
14* The Initial Developer of the Original Code is Netscape
15* Communications Corporation. Portions created by Netscape are
16* Copyright (C) 1998 Netscape Communications Corporation. All
17* Rights Reserved.
18*
19* Contributor(s): pschwartau@netscape.com
20* Date: 26 November 2000
21*
22*
23* SUMMARY: This test arose from Bugzilla bug 57631:
24* "RegExp with invalid pattern or invalid flag causes segfault"
25*
26* Either error should throw an exception of type SyntaxError,
27* and we check to see that it does...
28*/
29//-------------------------------------------------------------------------------------------------
30var bug = '57631';
31var summary = 'Testing new RegExp(pattern,flag) with illegal pattern or flag';
32var statprefix = 'Testing for error creating illegal RegExp object on pattern ';
33var statsuffix = 'and flag ';
34var cnSUCCESS = 'SyntaxError';
35var cnFAILURE = 'not a SyntaxError';
36var singlequote = "'";
37var i = -1; var j = -1; var s = ''; var f = '';
38var obj = {};
39var status = ''; var actual = ''; var expect = ''; var msg = '';
40var legalpatterns = new Array(); var illegalpatterns = new Array();
41var legalflags = new Array(); var illegalflags = new Array();
42
43
44// valid regular expressions to try -
45legalpatterns[0] = '';
46legalpatterns[1] = 'abc';
47legalpatterns[2] = '(.*)(3-1)\s\w';
48legalpatterns[3] = '(.*)(...)\\s\\w';
49legalpatterns[4] = '[^A-Za-z0-9_]';
50legalpatterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
51
52// invalid regular expressions to try -
53illegalpatterns[0] = '()';
54illegalpatterns[1] = '(a';
55illegalpatterns[2] = '( ]';
56illegalpatterns[3] = '\d{s}';
57
58// valid flags to try -
59legalflags[0] = 'i';
60legalflags[1] = 'g';
61legalflags[2] = 'm';
62legalflags[3] = undefined;
63
64// invalid flags to try -
65illegalflags[0] = 'a';
66illegalflags[1] = 123;
67illegalflags[2] = new RegExp();
68
69
70
71//-------------------------------------------------------------------------------------------------
72test();
73//-------------------------------------------------------------------------------------------------
74
75
76function test()
77{
78 enterFunc ('test');
79 printBugNumber (bug);
80 printStatus (summary);
81
82 testIllegalRegExps(legalpatterns, illegalflags);
83 testIllegalRegExps(illegalpatterns, legalflags);
84 testIllegalRegExps(illegalpatterns, illegalflags);
85
86 exitFunc ('test');
87}
88
89
90// This function will only be called where all the patterns are illegal, or all the flags
91function testIllegalRegExps(patterns, flags)
92{
93 for (i in patterns)
94 {
95 s = patterns[i];
96
97 for (j in flags)
98 {
99 f = flags[j];
100 status = getStatus(s, f);
101
102 try
103 {
104 // This should cause an exception if either s or f is illegal -
105 eval('obj = new RegExp(s, f);');
106 }
107 catch(e)
108 {
109 // We expect to get a SyntaxError - test for this:
110 actual = (e instanceof SyntaxError)? cnSUCCESS : cnFAILURE;
111 expect = cnSUCCESS;
112 reportCompare(expect, actual, status);
113 }
114 }
115 }
116}
117
118
119function getStatus(regexp, flag)
120{
121 return (statprefix + quote(regexp) + statsuffix + quote(flag));
122}
123
124
125function quote(text)
126{
127 return (singlequote + text + singlequote);
128}