]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/RegExp/regress-57631.js
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/
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.
12 * The Original Code is mozilla.org code.
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
19 * Contributor(s): pschwartau@netscape.com
20 * Date: 26 November 2000
23 * SUMMARY: This test arose from Bugzilla bug 57631:
24 * "RegExp with invalid pattern or invalid flag causes segfault"
26 * Either error should throw an exception of type SyntaxError,
27 * and we check to see that it does...
29 //-------------------------------------------------------------------------------------------------
31 var summary
= 'Testing new RegExp(pattern,flag) with illegal pattern or flag';
32 var statprefix
= 'Testing for error creating illegal RegExp object on pattern ';
33 var statsuffix
= 'and flag ';
34 var cnSUCCESS
= 'SyntaxError';
35 var cnFAILURE
= 'not a SyntaxError';
36 var singlequote
= "'";
37 var i
= -1; var j
= -1; var s
= ''; var f
= '';
39 var status
= ''; var actual
= ''; var expect
= ''; var msg
= '';
40 var legalpatterns
= new Array(); var illegalpatterns
= new Array();
41 var legalflags
= new Array(); var illegalflags
= new Array();
44 // valid regular expressions to try -
45 legalpatterns
[0] = '';
46 legalpatterns
[1] = 'abc';
47 legalpatterns
[2] = '(.*)(3-1)\s\w';
48 legalpatterns
[3] = '(.*)(...)\\s\\w';
49 legalpatterns
[4] = '[^A-Za-z0-9_]';
50 legalpatterns
[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
52 // invalid regular expressions to try -
53 illegalpatterns
[0] = '()';
54 illegalpatterns
[1] = '(a';
55 illegalpatterns
[2] = '( ]';
56 illegalpatterns
[3] = '\d{s}';
58 // valid flags to try -
62 legalflags
[3] = undefined;
64 // invalid flags to try -
65 illegalflags
[0] = 'a';
66 illegalflags
[1] = 123;
67 illegalflags
[2] = new RegExp();
71 //-------------------------------------------------------------------------------------------------
73 //-------------------------------------------------------------------------------------------------
80 printStatus (summary
);
82 testIllegalRegExps(legalpatterns
, illegalflags
);
83 testIllegalRegExps(illegalpatterns
, legalflags
);
84 testIllegalRegExps(illegalpatterns
, illegalflags
);
90 // This function will only be called where all the patterns are illegal, or all the flags
91 function testIllegalRegExps(patterns
, flags
)
100 status
= getStatus(s
, f
);
104 // This should cause an exception if either s or f is illegal -
105 eval('obj = new RegExp(s, f);');
109 // We expect to get a SyntaxError - test for this:
110 actual
= (e
instanceof SyntaxError
)? cnSUCCESS : cnFAILURE
;
112 reportCompare(expect
, actual
, status
);
119 function getStatus(regexp
, flag
)
121 return (statprefix
+ quote(regexp
) + statsuffix
+ quote(flag
));
127 return (singlequote
+ text
+ singlequote
);