Bug 452451 - "enable relimit by default and find out if it breaks the web" [r=jwalden,jst]

This commit is contained in:
Mounir Lamouri 2010-05-19 22:28:09 -04:00
parent 8fce62a6c6
commit b595578fba
4 changed files with 101 additions and 2 deletions

View File

@ -70,6 +70,7 @@ _TEST_FILES = \
gZipOfflineChild.html^headers^ \
gZipOfflineChild.cacheManifest \
gZipOfflineChild.cacheManifest^headers^ \
test_bug452451.html \
$(NULL)
# The following tests are disabled because they are unreliable:

View File

@ -0,0 +1,97 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=452451
-->
<head>
<title>Test for Bug 452451</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=452451">Mozilla Bug 452451</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 452451 **/
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
ok(prefs.getBoolPref("javascript.options.relimit"),
"relimit should be enabled by default");
/**
* Following tests are inspired from:
* js/src/tests/js1_5/extensions/regress-330569.js
*/
var s;
const expected = 'InternalError: regular expression too complex';
s = '<!DOCTYPE HTML PUBLIC>' +
'<html>\n' +
'<head>\n' +
'<meta http-equiv="content-type" content="text/html">\n' +
'<title></title>\n'+
'</head>\n' +
'<body>\n' +
'<!-- hello -->\n' +
'<script language="JavaScript">\n' +
'var s = document. body. innerHTML;\n' +
'var d = s. replace (/<!--(.*|\n)*-->/, "");\n' +
'<\/script>\n' +
'<\/body>\n' +
'<\/html>\n';
try {
/<!--(.*|\n)*-->/.exec(s);
}
catch(ex) {
actual = ex;
}
is(actual, expected, "reg exp too complex error should have been thrown");
function testre( re, n )
{
var txt = '';
for (var i= 0; i <= n; ++i) {
txt += ',';
re.test(txt);
}
}
try {
testre( /(?:,*)*x/, 22 );
}
catch(ex) {
actual = ex;
}
is(actual, expected, "reg exp too complex error should have been thrown");
try {
testre( /(?:,|,)*x/, 22 );
}
catch(ex) {
actual = ex;
}
is(actual, expected, "reg exp too complex error should have been thrown");
try {
testre( /(?:,|,|,|,|,)*x/, 10 );
}
catch(ex) {
actual = ex;
}
is(actual, expected, "reg exp too complex error should have been thrown");
</script>
</pre>
</body>
</html>

View File

@ -3045,7 +3045,8 @@ GetOptionsProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
if (JSVAL_IS_INT(id)) {
uint32 optbit = (uint32) JSVAL_TO_INT(id);
if ((optbit & (optbit - 1)) == 0 && optbit <= JSOPTION_WERROR)
if (((optbit & (optbit - 1)) == 0 && optbit <= JSOPTION_WERROR) ||
optbit == JSOPTION_RELIMIT)
*vp = (JS_GetOptions(cx) & optbit) ? JSVAL_TRUE : JSVAL_FALSE;
}
return JS_TRUE;

View File

@ -558,7 +558,7 @@ pref("javascript.options.strict", false);
#ifdef DEBUG
pref("javascript.options.strict.debug", true);
#endif
pref("javascript.options.relimit", false);
pref("javascript.options.relimit", true);
pref("javascript.options.jit.content", true);
pref("javascript.options.jit.chrome", true);
// This preference limits the memory usage of javascript.