Rewrite code to switch javascript options for strict/werror

This commit is contained in:
bob%bclary.com 2005-10-17 22:33:38 +00:00
Родитель a7d3440ca7
Коммит 3522e21df2
27 изменённых файлов: 1449 добавлений и 302 удалений

Просмотреть файл

@ -64,14 +64,9 @@ var actual = 'no error';
var prefValue;
writeLineToLog("This test requires option javascript.options.strict enabled");
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
@ -82,10 +77,7 @@ catch(e)
actual = 'error';
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
DESCRIPTION = "var enum = true";
EXPECTED = "error";

Просмотреть файл

@ -65,14 +65,10 @@ var actual = 'no error';
var prefValue;
writeLineToLog("This test requires option javascript.options.strict enabled");
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
@ -83,10 +79,7 @@ catch(e)
actual = 'error';
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
DESCRIPTION = "var import = true";
EXPECTED = "error";

Просмотреть файл

@ -64,14 +64,9 @@ var actual = 'no error';
var prefValue;
writeLineToLog("This test requires option javascript.options.strict enabled");
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
@ -82,10 +77,7 @@ catch(e)
actual = 'error';
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
DESCRIPTION = "var super = true"
EXPECTED = "error";

Просмотреть файл

@ -64,14 +64,10 @@ var actual = 'no error';
var prefValue;
writeLineToLog("This test requires option javascript.options.strict enabled");
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
@ -82,10 +78,7 @@ catch(e)
actual = 'error';
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
DESCRIPTION = "var extends = true";
EXPECTED = "error";

Просмотреть файл

@ -63,15 +63,14 @@ writeHeaderToLog( SECTION + " "+ TITLE);
var actual = 'no error';
var prefValue;
DESCRIPTION = "var class = true";
EXPECTED = "error";
writeLineToLog("This test requires option javascript.options.strict enabled");
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
@ -82,14 +81,6 @@ catch(e)
actual = 'error';
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
DESCRIPTION = "var class = true";
EXPECTED = "error";
// force exception since this is a negative test
if (actual == 'error')
{

Просмотреть файл

@ -125,41 +125,6 @@ function version(v)
return gVersion;
}
var gPrivileges = 'UniversalXPConnect';
function setBoolPref(prefName, newValue)
{
var prevValue = false;
try
{
netscape.security.PrivilegeManager.
enablePrivilege(gPrivileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (preferences)
{
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
var pref = prefService.getBranch('');
try
{
prevValue = pref.getBoolPref(prefName);
}
catch(eget)
{
writeLineToLog('Unable to get preference ' + prefName);
}
pref.setBoolPref(prefName, newValue);
}
}
catch (e)
{
writeLineToLog('Unable to set preference ' +
prefName + ' to ' + prevValue);
}
return prevValue;
}
function gc()
{

Просмотреть файл

@ -58,6 +58,9 @@ var FAILED = " FAILED! expected: ";
var DEBUG = false;
var DESCRIPTION;
var EXPECTED;
/*
* wrapper for test case constructor that doesn't require the SECTION
* argument.
@ -704,3 +707,132 @@ function OptLevel( i ) {
}
/* end of Rhino functions */
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -27,15 +27,9 @@ writeHeaderToLog( SECTION + " "+ TITLE);
writeLineToLog("This test requires option javascript.options.strict enabled");
var prefValue;
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
var result = "Failed";
var exception = "No exception thrown";
@ -48,10 +42,7 @@ try {
exception = e.toString();
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
new TestCase(
SECTION,

Просмотреть файл

@ -27,15 +27,9 @@ writeHeaderToLog( SECTION + " "+ TITLE);
writeLineToLog("This test requires option javascript.options.strict enabled");
var prefValue;
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
var result = "Failed";
var exception = "No exception thrown";
@ -48,10 +42,7 @@ try {
exception = e.toString();
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
new TestCase(
SECTION,

Просмотреть файл

@ -27,15 +27,9 @@ writeHeaderToLog( SECTION + " "+ TITLE);
writeLineToLog("This test requires option javascript.options.strict enabled");
var prefValue;
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
var result = "Failed";
var exception = "No exception thrown";
@ -48,10 +42,7 @@ try {
exception = e.toString();
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
new TestCase(
SECTION,

Просмотреть файл

@ -27,15 +27,9 @@ writeHeaderToLog( SECTION + " "+ TITLE);
writeLineToLog("This test requires option javascript.options.strict enabled");
var prefValue;
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
var result = "Failed";
var exception = "No exception thrown";
@ -48,10 +42,7 @@ try {
exception = e.toString();
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
new TestCase(
SECTION,

Просмотреть файл

@ -16,15 +16,9 @@ startTest();
writeLineToLog("This test requires option javascript.options.strict enabled");
var prefValue;
if (typeof document == "undefined" && typeof options == 'function')
{
options("strict", "werror");
}
else
{
prefValue = setBoolPref("javascript.options.werror", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
var result = "failed";
@ -36,10 +30,7 @@ catch (x) {
result = x.name;
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.werror", prefValue);
}
jsOptions.reset();
AddTestCase(
"using the expression \"super\" shouldn't cause js to crash",

Просмотреть файл

@ -125,42 +125,6 @@ function version(v)
return gVersion;
}
var gPrivileges = 'UniversalXPConnect';
function setBoolPref(prefName, newValue)
{
var prevValue = false;
try
{
netscape.security.PrivilegeManager.
enablePrivilege(gPrivileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (preferences)
{
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
var pref = prefService.getBranch('');
try
{
prevValue = pref.getBoolPref(prefName);
}
catch(eget)
{
writeLineToLog('Unable to get preference ' + prefName);
}
pref.setBoolPref(prefName, newValue);
}
}
catch (e)
{
writeLineToLog('Unable to set preference ' +
prefName + ' to ' + prevValue);
}
return prevValue;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com

Просмотреть файл

@ -270,3 +270,130 @@ function getTimeZoneDiff()
return -((new Date(2000, 1, 1)).getTimezoneOffset())/60;
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -199,3 +199,129 @@ function currentFunc()
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -219,3 +219,129 @@ function getFailedCases() {
}
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -192,3 +192,130 @@ function stopTest() {
gc();
}
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -241,3 +241,129 @@ function getFailedCases() {
}
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -242,3 +242,129 @@ function getFailedCases() {
}
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -45,14 +45,8 @@ var expect = 'No Crash';
printBugNumber (bug);
printStatus (summary);
if (typeof document == "undefined" && typeof options == 'function')
{
prefValue = options("strict");
}
else
{
prefValue = setBoolPref("javascript.options.strict", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
function x(y,y)
{
@ -61,13 +55,6 @@ function x(y,y)
var z = x(4,5);
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.strict", prefValue);
}
else
{
options(prefValue);
}
jsOptions.reset();
reportCompare(expect, actual, summary);

Просмотреть файл

@ -43,14 +43,8 @@ var expect = 'No Crash';
printBugNumber (bug);
printStatus (summary);
if (typeof document == "undefined" && typeof options == 'function')
{
prefValue = options("strict");
}
else
{
prefValue = setBoolPref("javascript.options.strict", true);
}
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
var code = "var bar1=new Array();\n" +
"bar1[0]='foo';\n" +
@ -80,13 +74,6 @@ catch(e)
{
}
if (typeof prefValue == 'boolean')
{
setBoolPref("javascript.options.strict", prefValue);
}
else
{
options(prefValue);
}
jsOptions.reset();
reportCompare(expect, actual, summary);

Просмотреть файл

@ -142,38 +142,3 @@ function quit()
window.onerror = reportFailure;
var gPrivileges = 'UniversalXPConnect';
function setBoolPref(prefName, newValue)
{
var prevValue = false;
try
{
netscape.security.PrivilegeManager.
enablePrivilege(gPrivileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (preferences)
{
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
var pref = prefService.getBranch('');
try
{
prevValue = pref.getBoolPref(prefName);
}
catch(eget)
{
writeLineToLog('Unable to get preference ' + prefName);
}
pref.setBoolPref(prefName, newValue);
}
}
catch (e)
{
writeLineToLog('Unable to set preference ' +
prefName + ' to ' + prevValue);
}
return prevValue;
}

Просмотреть файл

@ -311,3 +311,130 @@ function BigO(data)
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -137,38 +137,3 @@ function quit()
window.onerror = reportFailure;
var gPrivileges = 'UniversalXPConnect';
function setBoolPref(prefName, newValue)
{
var prevValue = false;
try
{
netscape.security.PrivilegeManager.
enablePrivilege(gPrivileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (preferences)
{
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
var pref = prefService.getBranch('');
try
{
prevValue = pref.getBoolPref(prefName);
}
catch(eget)
{
writeLineToLog('Unable to get preference ' + prefName);
}
pref.setBoolPref(prefName, newValue);
}
}
catch (e)
{
writeLineToLog('Unable to set preference ' +
prefName + ' to ' + prevValue);
}
return prevValue;
}

Просмотреть файл

@ -311,3 +311,129 @@ function BigO(data)
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -265,3 +265,130 @@ function getFailedCases() {
}
}
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}

Просмотреть файл

@ -1,3 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -276,3 +277,130 @@ function getFailedCases() {
}
}
}
/* JavaScriptOptions
encapsulate the logic for setting and retrieving the values
of the javascript options.
Note: in shell, options() takes an optional comma delimited list
of option names, toggles the values for each option and returns the
list of option names which were set before the call.
If no argument is passed to options(), it returns the current
options with value true.
Usage;
// create and initialize object.
jsOptions = new JavaScriptOptions();
// set a particular option
jsOptions.setOption(name, boolean);
// reset all options to their original values.
jsOptions.reset();
*/
function JavaScriptOptions()
{
this.orig = {};
this.orig.strict = this.strict = false;
this.orig.werror = this.werror = false;
this.privileges = 'UniversalXPConnect';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (iOpt = 0; i < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'JavaScriptOptions: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'JavaScriptOptions: unable to get prefService branch';
}
this.orig.strict = this.strict = pref.getBoolPref('javascript.options.strict');
this.orig.werror = this.werror = pref.getBoolPref('javascript.options.werror');
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof document != 'undefined')
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preference;1';
}
var prefService = preferences.
getService(Components.interfaces.nsIPrefService);
if (!prefService)
{
throw 'setOption: unable to get nsIPrefService';
}
var pref = prefService.getBranch('');
if (!pref)
{
throw 'setOption: unable to get prefService branch';
}
pref.setBoolPref('javascript.options.' + optionName, optionValue);
}
this[optionName] = optionValue;
return;
}
JavaScriptOptions.prototype.reset = function ()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
}