JavaScript Tests - replace JavaScriptOptions, bug 379701

This commit is contained in:
bclary@bclary.com 2007-05-04 11:49:29 -07:00
parent 8a85c90946
commit bada760dab
58 changed files with 4403 additions and 1945 deletions

View File

@ -125,10 +125,8 @@ function reportSuccess(section, expected, actual)
function reportError(msg, page, line)
{
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof SUMMARY == 'undefined')
{
@ -165,6 +163,7 @@ function reportError(msg, page, line)
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
@ -253,3 +252,260 @@ function quit()
}
window.onerror = reportError;
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();
options('xml');

View File

@ -46,13 +46,6 @@ var VERBOSE = false;
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
if (typeof options != 'undefined' &&
options().indexOf('xml') < 0)
{
// automatically turn on e4x support
options('xml');
}
/*
* The test driver searches for such a phrase in the test output.
* If such phrase exists, it will set n as the expected exit code.
@ -184,149 +177,7 @@ function SHOULD_THROW(section)
function END()
{
}
/* 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
{
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;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);
debugger;
}
function compareSource(n, expect, actual)
@ -373,3 +224,93 @@ function compareSource(n, expect, actual)
{
}
}
function optionsInit() {
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
optionsframe[optionName] = '';
}
}
optionsClear();
// keep xml turned on
options('xml');
}
function optionsPop()
{
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
options('xml');
}

View File

@ -64,9 +64,9 @@ var actual = 'no error';
var prefValue;
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -77,8 +77,6 @@ catch(e)
actual = 'error';
}
jsOptions.reset();
DESCRIPTION = "var enum = true";
EXPECTED = "error";
@ -94,5 +92,3 @@ new TestCase( SECTION,
actual );
test();

View File

@ -66,9 +66,8 @@ var prefValue;
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -79,8 +78,6 @@ catch(e)
actual = 'error';
}
jsOptions.reset();
DESCRIPTION = "var import = true";
EXPECTED = "error";
@ -96,4 +93,3 @@ new TestCase( SECTION,
actual );
test();

View File

@ -64,9 +64,9 @@ var actual = 'no error';
var prefValue;
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -77,8 +77,6 @@ catch(e)
actual = 'error';
}
jsOptions.reset();
DESCRIPTION = "var super = true"
EXPECTED = "error";
@ -93,4 +91,3 @@ new TestCase( SECTION,
"error",
actual );
test();

View File

@ -65,9 +65,8 @@ var prefValue;
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -78,8 +77,6 @@ catch(e)
actual = 'error';
}
jsOptions.reset();
DESCRIPTION = "var extends = true";
EXPECTED = "error";
@ -95,4 +92,3 @@ new TestCase( SECTION,
actual);
test();

View File

@ -68,9 +68,9 @@ EXPECTED = "error";
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -81,8 +81,6 @@ catch(e)
actual = 'error';
}
jsOptions.reset();
// force exception since this is a negative test
if (actual == 'error')
{
@ -95,4 +93,3 @@ new TestCase( SECTION,
actual );
test();

View File

@ -142,10 +142,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -185,6 +183,7 @@ function err( msg, page, line ) {
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
var gVersion = 0;
@ -222,3 +221,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -780,147 +780,90 @@ 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -27,9 +27,8 @@ writeHeaderToLog( SECTION + " "+ TITLE);
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var result = "Failed";
var exception = "No exception thrown";
@ -42,8 +41,6 @@ try {
exception = e.toString();
}
jsOptions.reset();
new TestCase(
SECTION,
"super = true" +
@ -52,5 +49,3 @@ new TestCase(
result );
test();

View File

@ -27,9 +27,8 @@ writeHeaderToLog( SECTION + " "+ TITLE);
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var result = "Failed";
var exception = "No exception thrown";
@ -42,8 +41,6 @@ try {
exception = e.toString();
}
jsOptions.reset();
new TestCase(
SECTION,
"extends = true" +
@ -52,5 +49,3 @@ new TestCase(
result );
test();

View File

@ -27,9 +27,8 @@ writeHeaderToLog( SECTION + " "+ TITLE);
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var result = "Failed";
var exception = "No exception thrown";
@ -42,8 +41,6 @@ try {
exception = e.toString();
}
jsOptions.reset();
new TestCase(
SECTION,
"class = true" +

View File

@ -27,9 +27,8 @@ writeHeaderToLog( SECTION + " "+ TITLE);
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var result = "Failed";
var exception = "No exception thrown";
@ -42,8 +41,6 @@ try {
exception = e.toString();
}
jsOptions.reset();
new TestCase(
SECTION,
"enum = true" +
@ -52,5 +49,3 @@ new TestCase(
result );
test();

View File

@ -16,9 +16,8 @@ startTest();
print("This test requires option javascript.options.strict enabled");
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var result = "failed";
@ -30,8 +29,6 @@ catch (x) {
result = x.name;
}
jsOptions.reset();
AddTestCase(
"using the expression \"super\" shouldn't cause js to crash",
"SyntaxError",

View File

@ -142,10 +142,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -185,6 +183,7 @@ function err( msg, page, line ) {
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
var gVersion = 0;
@ -222,3 +221,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -268,145 +268,89 @@ function getTimeZoneDiff()
}
/* 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -49,10 +49,9 @@ var actual = '';
var expect = 's.length is read-only';
var status = summary + ': Throw if STRICT and WERROR is enabled';
var jsOptions = new JavaScriptOptions();
options('strict');
options('werror');
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
var s = new String ('abc');
@ -62,7 +61,6 @@ catch (e)
{
actual = e.message;
}
jsOptions.reset();
reportCompare(expect, actual, status);
@ -72,8 +70,9 @@ actual = 'did not throw';
expect = 'did not throw';
var status = summary + ': Do not throw if STRICT is enabled and WERROR is disabled';
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', false);
// toggle werror off
options('werror');
try
{
s.length = 0;
@ -82,7 +81,7 @@ catch (e)
{
actual = e.message;
}
jsOptions.reset();
reportCompare(expect, actual, status);
// should not throw an error if not in strict mode
@ -91,8 +90,9 @@ actual = 'did not throw';
expect = 'did not throw';
var status = summary + ': Do not throw if not in strict mode';
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
// toggle strict off
options('strict');
try
{
s.length = 0;
@ -101,8 +101,5 @@ catch (e)
{
actual = e.message;
}
jsOptions.reset();
reportCompare(expect, actual, status);
exitFunc (String (bug));

View File

@ -134,10 +134,8 @@ var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (gInReportCompare)
{
@ -180,6 +178,7 @@ reportFailure = function (msg, page, line)
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function quit()
@ -213,3 +212,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -335,145 +335,89 @@ 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -129,6 +129,17 @@ function jsTestDriverEnd()
return;
}
window.onerror = null;
try
{
optionsReset();
}
catch(ex)
{
dump('jsTestDriverEnd ' + ex);
}
if (window.opener && window.opener.runNextTest)
{
if (window.opener.reportCallBack)

View File

@ -142,10 +142,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -185,6 +183,7 @@ function err( msg, page, line ) {
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
function version(v) {
@ -220,3 +219,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -217,145 +217,89 @@ 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -142,10 +142,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -185,6 +183,8 @@ function err( msg, page, line ) {
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
var gVersion = 0;
@ -222,3 +222,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -191,145 +191,89 @@ function stopTest() {
}
}
/* 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -142,10 +142,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -185,6 +183,8 @@ function err( msg, page, line ) {
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
function version(v)
@ -220,3 +220,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -239,145 +239,89 @@ 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -142,10 +142,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -185,6 +183,7 @@ function err( msg, page, line ) {
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
var gVersion = 0;
@ -222,3 +221,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -240,145 +240,89 @@ 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -43,11 +43,8 @@ var expect = 'ReferenceError';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
// strict
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var o = {};
@ -60,6 +57,5 @@ catch(ex)
{
actual = ex.name;
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,10 +43,8 @@ var expect = 'test for equality (==) mistyped as assignment (=)?';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var a = false;
var b = true;
@ -65,7 +63,7 @@ catch(ex)
{
actual = ex.message;
}
jsOptions.reset();
printStatus('result = ' + result);
print('result = ' + result);
reportCompare(expect, actual, summary);

View File

@ -41,12 +41,10 @@ var summary = 'Do not crash javascript warning duplicate arguments';
var actual = 'No Crash';
var expect = 'No Crash';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
options('strict');
function x(y,y)
{
@ -55,6 +53,4 @@ function x(y,y)
var z = x(4,5);
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,8 +43,7 @@ var expect = 'No Crash';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
options('strict');
var code = "var bar1=new Array();\n" +
"bar1[0]='foo';\n" +
@ -73,7 +72,5 @@ try
catch(e)
{
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,12 +43,11 @@ var expect = 'No warning';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
var testobject = {};
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
var testresult = testobject.foo;
@ -58,11 +57,9 @@ catch(ex)
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 1');
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
if (testobject.foo)
@ -75,11 +72,9 @@ catch(ex)
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 2');
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
if (typeof testobject.foo == 'undefined')
@ -92,11 +87,9 @@ catch(ex)
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 3');
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
if (testobject.foo == null)
@ -109,11 +102,9 @@ catch(ex)
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 4');
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
if (testobject.foo == undefined)
@ -126,5 +117,5 @@ catch(ex)
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 3');

View File

@ -43,11 +43,8 @@ var expect = '';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
// strict
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
expect = 'SyntaxError';
@ -59,8 +56,5 @@ catch(e)
{
actual = e.name;
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,11 +43,8 @@ var expect = '';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
// test with strict off
// non strict
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
try
{
expect = null;
@ -56,11 +53,12 @@ try
catch(e)
{
}
jsOptions.reset();
reportCompare(expect, actual, summary);
// strict
jsOptions.setOption('strict', true);
// test with strict on
options('strict');
expect = null;
try
{
@ -69,7 +67,5 @@ try
catch(e)
{
}
jsOptions.reset();
reportCompare(expect, actual, summary);
reportCompare(expect, actual, summary);

View File

@ -43,9 +43,8 @@ var expect = 'No error';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -56,6 +55,4 @@ catch(e)
actual = e + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,9 +43,8 @@ var expect = 'No warning';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -56,6 +55,4 @@ catch(e)
actual = e + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -44,38 +44,38 @@ printBugNumber (bug);
printStatus (summary);
var code;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
debugger;
options('strict');
options('werror');
try
{
actual = '';
code = "function(x){ if(x) return x; }";
printStatus(code);
print(code);
eval(code);
}
catch(ex)
{
actual = ex + '';
printStatus(ex);
print(ex);
}
jsOptions.reset();
reportCompare(expect, actual, summary);
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
actual = '';
code = "function(x){ if(x) return x; ;}";
printStatus(code);
print(code);
eval(code);
}
catch(ex)
{
actual = ex + '';
printStatus(ex);
print(ex);
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,9 +43,8 @@ var expect = '';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werrror');
expect = 'No Warning';
@ -65,6 +64,5 @@ catch(ex)
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,9 +43,8 @@ var expect = '';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
var xyzzy;
@ -62,6 +61,5 @@ catch(ex)
actual = ex.name;
printStatus(ex + '');
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -43,10 +43,8 @@ var expect = 'TypeError: function f does not always return a value';
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -57,13 +55,8 @@ catch(ex)
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary);
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
eval('function f() { if (x) { return y; } }');
@ -72,6 +65,5 @@ catch(ex)
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -122,22 +122,25 @@ var _reportCompare = reportCompare;
reportCompare = function(expected, actual, description)
{
optionsPush();
gInReportCompare = true;
var testcase = new TestCase(gTestName, description, expected, actual);
testcase.passed = _reportCompare(expected, actual, description);
gInReportCompare = false;
optionsPop();
};
var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (gInReportCompare)
{
@ -177,6 +180,7 @@ reportFailure = function (msg, page, line)
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
@ -211,3 +215,257 @@ function quit()
window.onerror = reportFailure;
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -54,8 +54,6 @@ function test()
var s;
expect = 'InternalError: regular expression too complex';
var jsOptions = new JavaScriptOptions();
s = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' +
'<html>\n' +
@ -74,7 +72,8 @@ function test()
'</body>\n' +
'</html>\n';
jsOptions.setOption('relimit', true);
options('relimit');
try
{
/<!--(.*|\n)*-->/.exec(s);
@ -83,9 +82,8 @@ function test()
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': /<!--(.*|\\n)*-->/.exec(s)');
reportCompare(expect, actual, summary + ': /<!--(.*|\\n)*-->/.exec(s)');
function testre( re, n ) {
for ( var i= 0; i <= n; ++i ) {
@ -93,7 +91,6 @@ function test()
}
}
jsOptions.setOption('relimit', true);
try
{
testre( /(?:,*)*x/, 22 );
@ -102,10 +99,9 @@ function test()
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': testre( /(?:,*)*x/, 22 )');
jsOptions.setOption('relimit', true);
try
{
testre( /(?:,|,)*x/, 22 );
@ -114,10 +110,9 @@ function test()
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': testre( /(?:,|,)*x/, 22 )');
jsOptions.setOption('relimit', true);
try
{
testre( /(?:,|,|,|,|,)*x/, 10 );
@ -126,7 +121,6 @@ function test()
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': testre( /(?:,|,|,|,|,)*x/, 10 )');
exitFunc ('test');

View File

@ -74,11 +74,11 @@ function test()
];
expect = 'InternalError: regular expression too complex';
var jsOptions = new JavaScriptOptions();
options('relimit');
for (var i = 0; i < strings.length; i++)
{
jsOptions.setOption('relimit', true);
try
{
eval(strings[i]);
@ -87,7 +87,6 @@ function test()
{
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': ' + strings[i]);
}

View File

@ -51,11 +51,9 @@ function test()
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
options('strict');
options('werror');
// strict
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
expect = 'TypeError: redeclaration of property a';
@ -68,14 +66,11 @@ function test()
actual = ex + '';
print(ex);
}
jsOptions.reset();
reportCompare(expect, actual, summary);
print('test crash from bug 371292');
// strict
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
expect = 'TypeError: redeclaration of property 1';
@ -88,7 +83,6 @@ function test()
actual = ex + '';
print(ex);
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -53,11 +53,9 @@ function test()
print('This test will fail in Gecko prior to 1.9');
var jsOptions = new JavaScriptOptions();
options('strict');
options('werror');
// strict
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
expect = 'TypeError: variable v redeclares argument';
@ -70,7 +68,6 @@ function test()
actual = ex + '';
print(ex);
}
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -153,6 +153,7 @@ function reportCompare (expected, actual, description)
{
print('PASSED! ' + description);
}
return (output == ""); // true if passed
}
@ -334,149 +335,6 @@ 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
{
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;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);
}
function compareSource(expect, actual, summary)
{
// compare source
@ -522,3 +380,89 @@ function compareSource(expect, actual, summary)
{
}
}
function optionsInit() {
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
optionsframe[optionName] = '';
}
}
optionsClear();
}
function optionsPop()
{
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -135,10 +135,8 @@ var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (gInReportCompare)
{
@ -181,6 +179,8 @@ reportFailure = function (msg, page, line)
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
@ -215,3 +215,257 @@ function quit()
window.onerror = reportFailure;
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -335,149 +335,6 @@ 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
{
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;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);
}
function compareSource(expect, actual, summary)
{
// compare source
@ -523,3 +380,90 @@ function compareSource(expect, actual, summary)
{
}
}
function optionsInit() {
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
optionsframe[optionName] = '';
}
}
optionsClear();
}
function optionsPop()
{
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -53,13 +53,11 @@ function test()
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
actual = 'No Warning';
expect = 'No Warning';
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
try
{
@ -70,16 +68,11 @@ function test()
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 1');
actual = 'No Warning';
expect = 'TypeError: function f does not always return a value';
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
eval('function f() { if (asdf) return 3; let x; }');
@ -89,16 +82,11 @@ function test()
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 2');
actual = 'No Warning';
expect = 'No Warning';
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
try
{
eval('function f() { if (asdf) return 3; let (x) { return 4; } }');
@ -108,8 +96,6 @@ function test()
actual = ex + '';
}
jsOptions.reset();
reportCompare(expect, actual, summary + ': 3');
exitFunc ('test');

View File

@ -135,10 +135,8 @@ var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (gInReportCompare)
{
@ -181,6 +179,7 @@ reportFailure = function (msg, page, line)
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
@ -215,3 +214,257 @@ function quit()
window.onerror = reportFailure;
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -51,12 +51,8 @@ function test()
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
// strict
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
function f() {
this.a = {1: "a", 2: "b"};
@ -66,7 +62,6 @@ function test()
}
f();
jsOptions.reset();
reportCompare(expect, actual, summary);

View File

@ -51,11 +51,8 @@ function test()
printBugNumber (bug);
printStatus (summary);
var jsOptions = new JavaScriptOptions();
// strict
jsOptions.setOption('strict', true);
jsOptions.setOption('werror', true);
options('strict');
options('werror');
function f() {
this.a = <><a/><b/></>
@ -66,8 +63,6 @@ function test()
f();
jsOptions.reset();
reportCompare(expect, actual, summary);
exitFunc ('test');

View File

@ -341,149 +341,6 @@ 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
{
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
{
// shell
if (this[optionName] != optionValue)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;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);
}
function compareSource(expect, actual, summary)
{
// compare source
@ -529,3 +386,90 @@ function compareSource(expect, actual, summary)
{
}
}
function optionsInit() {
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
var optionName = optionNames[i];
if (optionName)
{
optionsframe[optionName] = '';
}
}
optionsClear();
}
function optionsPop()
{
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -165,10 +165,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -184,30 +182,32 @@ function err( msg, page, line ) {
// negative test
testcase.passed = true;
}
return;
}
if (typeof SECTION == 'undefined')
else
{
SECTION = 'Unknown';
}
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
if (typeof SECTION == 'undefined')
{
SECTION = 'Unknown';
}
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
testcase = new TestCase(SECTION, DESCRIPTION, EXPECTED, "error");
testcase.reason += "Error: " + msg +
" Source File: " + page + " Line: " + line + ".";
stopTest();
gDelayTestDriverEnd = false;
jsTestDriverEnd();
}
testcase = new TestCase(SECTION, DESCRIPTION, EXPECTED, "error");
testcase.reason += "Error: " + msg +
" Source File: " + page + " Line: " + line + ".";
stopTest();
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
var gVersion = 0;
@ -245,3 +245,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -263,145 +263,89 @@ 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch(e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}

View File

@ -157,10 +157,8 @@ var gExceptionExpected = false;
function err( msg, page, line ) {
var testcase;
var jsOptions = new JavaScriptOptions();
jsOptions.setOption('strict', false);
jsOptions.setOption('werror', false);
optionsPush();
if (typeof(EXPECTED) == "undefined" || EXPECTED != "error") {
/*
@ -176,30 +174,32 @@ function err( msg, page, line ) {
// negative test
testcase.passed = true;
}
return;
}
else
{
if (typeof SECTION == 'undefined')
{
SECTION = 'Unknown';
}
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
if (typeof SECTION == 'undefined')
{
SECTION = 'Unknown';
testcase = new TestCase(SECTION, DESCRIPTION, EXPECTED, "error");
testcase.reason += "Error: " + msg +
" Source File: " + page + " Line: " + line + ".";
}
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
testcase = new TestCase(SECTION, DESCRIPTION, EXPECTED, "error");
testcase.reason += "Error: " + msg +
" Source File: " + page + " Line: " + line + ".";
stopTest();
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
}
var gVersion = 0;
@ -237,3 +237,258 @@ function jsdgc()
print('gc: ' + ex);
}
}
function Preferences(aPrefRoot)
{
try
{
this.orig = {};
this.privs = 'UniversalXPConnect UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
this.prefRoot = aPrefRoot;
this.prefService = Components.classes[nsPrefService_CONTRACTID].
getService(nsIPrefService);
this.prefBranch = this.prefService.getBranch(aPrefRoot).
QueryInterface(Components.interfaces.nsIPrefBranch2);
}
catch(ex)
{
}
}
function Preferences_getPrefRoot()
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
return this.prefBranch.root;
}
catch(ex)
{
return;
}
}
function Preferences_getPref(aPrefName)
{
var value;
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
try
{
value = this.prefBranch.getBoolPref(aPrefName);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
return value;
}
function Preferences_setPref(aPrefName, aPrefValue)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (typeof this.orig[aPrefName] == 'undefined')
{
this.orig[aPrefName] = this.getPref(aPrefName);
}
try
{
value = this.prefBranch.setBoolPref(aPrefName, aPrefValue);
}
catch(ex)
{
//print('Ignoring ' + ex);
}
}
catch(ex)
{
}
}
function Preferences_resetPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
if (aPrefName in this.orig)
{
this.setPref(aPrefName, this.orig[aPrefName]);
}
}
catch(ex)
{
}
}
function Preferences_resetAllPrefs()
{
try
{
var prefName;
var prefValue;
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
for (prefName in this.orig)
{
this.setPref(prefName, this.orig[prefName]);
}
}
catch(ex)
{
}
}
function Preferences_clearPref(aPrefName)
{
try
{
if (typeof netscape != 'undefined' &&
'security' in netscape &&
'PrivilegeManager' in netscape.security &&
'enablePrivilege' in netscape.security.PrivilegeManager)
{
netscape.security.PrivilegeManager.enablePrivilege(this.privs);
}
this.prefBranch.clearUserPref(aPrefName);
}
catch(ex)
{
}
}
Preferences.prototype.getPrefRoot = Preferences_getPrefRoot;
Preferences.prototype.getPref = Preferences_getPref;
Preferences.prototype.setPref = Preferences_setPref;
Preferences.prototype.resetAllPrefs = Preferences_resetAllPrefs;
Preferences.prototype.resetPref = Preferences_resetPref;
Preferences.prototype.clearPref = Preferences_clearPref;
function options(aOptionName)
{
// return value of options() is a comma delimited list
// of the previously set values
var value = '';
for (var optionName in options.currvalues)
{
value += optionName + ',';
}
if (value)
{
value = value.substring(0, value.length-1);
}
if (aOptionName)
{
if (options.currvalues[aOptionName])
{
// option is set, toggle it to unset
delete options.currvalues[aOptionName];
options.preferences.setPref(aOptionName, false);
}
else
{
// option is not set, toggle it to set
options.currvalues[aOptionName] = true;
options.preferences.setPref(aOptionName, true);
}
}
return value;
}
function optionsInit() {
// hash containing the set options
options.currvalues = {strict: '',
werror: '',
atline: '',
xml: '',
relimit: '',
anonfunfux: ''
}
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
options.preferences = new Preferences('javascript.options.');
for (var optionName in options.currvalues)
{
if (!options.preferences.getPref(optionName))
{
delete options.currvalues[optionName];
}
else
{
options.initvalues[optionName] = '';
}
}
}
optionsInit();
optionsClear();

View File

@ -276,145 +276,89 @@ 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.
function optionsInit() {
Usage;
// record initial values to support resetting
// options to their initial values
options.initvalues = {};
// create and initialize object.
jsOptions = new JavaScriptOptions();
// record values in a stack to support pushing
// and popping options
options.stackvalues = [];
// set a particular option
jsOptions.setOption(name, boolean);
var optionNames = options().split(',');
// 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 UniversalPreferencesRead ' +
'UniversalPreferencesWrite';
if (typeof options == 'function')
for (var i = 0; i < optionNames.length; i++)
{
// shell
var optString = options();
if (optString)
{
var optList = optString.split(',');
for (var iOpt = 0; iOpt < optList.length; iOpt++)
{
optName = optList[iOpt];
this[optName] = true;
}
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
{
throw 'JavaScriptOptions: unable to get @mozilla.org/preferences-service;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';
}
try
{
this.orig.strict = this.strict =
pref.getBoolPref('javascript.options.strict');
}
catch (e)
{
}
try
{
this.orig.werror = this.werror =
pref.getBoolPref('javascript.options.werror');
}
catch(e)
var optionName = optionNames[i];
if (optionName)
{
options.initvalues[optionName] = '';
}
}
}
JavaScriptOptions.prototype.setOption =
function (optionName, optionValue)
{
if (typeof options == 'function')
function optionsClear() {
// turn off current settings
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// shell
if (this[optionName] != optionValue)
var optionName = optionNames[i];
if (optionName)
{
options(optionName);
}
}
else if (typeof netscape != 'undefined' && 'security' in netscape)
}
function optionsPush()
{
var optionsframe = {};
options.stackvalues.push(optionsframe);
var optionNames = options().split(',');
for (var i = 0; i < optionNames.length; i++)
{
// browser
netscape.security.PrivilegeManager.enablePrivilege(this.privileges);
var preferences = Components.classes['@mozilla.org/preferences-service;1'];
if (!preferences)
var optionName = optionNames[i];
if (optionName)
{
throw 'setOption: unable to get @mozilla.org/preferences-service;1';
optionsframe[optionName] = '';
}
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;
optionsClear();
}
JavaScriptOptions.prototype.reset = function ()
function optionsPop()
{
this.setOption('strict', this.orig.strict);
this.setOption('werror', this.orig.werror);
var optionsframe = options.stackvalues.pop();
optionsClear();
for (optionName in optionsframe)
{
options(optionName);
}
}
function optionsReset() {
optionsClear();
// turn on initial settings
for (optionName in options.initvalues)
{
options(optionName);
}
}
if (typeof options == 'function')
{
optionsInit();
optionsClear();
}