JavaScript Tests - factor common code into top level shell.js|browser.js, bug 379779, r=igor, sr=brendan

This commit is contained in:
bclary@bclary.com 2007-05-19 13:05:05 -07:00
Родитель 65c95345a0
Коммит 34c73f8469
33 изменённых файлов: 945 добавлений и 8050 удалений

457
js/tests/browser.js Executable file
Просмотреть файл

@ -0,0 +1,457 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
var testcases = new Array();
var tc = testcases.length;
var bug = '';
var summary = '';
var description = '';
var expected = '';
var actual = '';
var msg = '';
function TestCase(n, d, e, a)
{
this.path = (typeof gTestPath == 'undefined') ? '' : gTestPath;
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = ( e == a );
this.reason = '';
this.bugnumber = typeof(bug) != 'undefined' ? bug : '';
testcases[tc++] = this;
}
var gInReportCompare = false;
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;
optionsPush();
if (gInReportCompare)
{
testcase = testcases[tc - 1];
testcase.passed = false;
}
else
{
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
testcase = new TestCase(gTestName, DESCRIPTION, EXPECTED, "error");
if (document.location.href.indexOf('-n.js') != -1)
{
// negative test
testcase.passed = true;
}
}
testcase.reason += msg;
if (typeof(page) != 'undefined')
{
testcase.reason += ' Page: ' + page;
}
if (typeof(line) != 'undefined')
{
testcase.reason += ' Line: ' + line;
}
_reportFailure(msg);
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
print('gc: ' + ex);
}
}
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();

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

@ -35,66 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
/*
* JavaScript test library shared functions file for running the tests
* in the browser. Overrides the shell's print function with document.write
* and make everything HTML pretty.
*
* To run the tests in the browser, use the mkhtml.pl script to generate
* html pages that include the shell.js, browser.js (this file), and the
* test js file in script tags.
*
* The source of the page that is generated should look something like this:
* <script src="./../shell.js"></script>
* <script src="./../browser.js"></script>
* <script src="./mytest.js"></script>
*/
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
var testcases = new Array();
var tc = testcases.length;
var BUGSTR = '';
var SUMMARY = '';
var DESCRIPTION = '';
@ -220,292 +160,5 @@ TEST_XML = function (section, expected, actual)
}
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
var tmp = Math.PI * 1e500, tmp2;
for (var i = 0; i != 1 << 15; ++i)
{
tmp2 = tmp * 1.5;
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
print('gc: ' + ex);
}
}
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');

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

@ -39,32 +39,6 @@
*
* ***** END LICENSE BLOCK ***** */
var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var VERBOSE = false;
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
/*
* 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.
*/
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
/*
* Statuses current section of a test
*/
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
/*
* Report a failure in the 'accepted' manner
*/
@ -76,28 +50,6 @@ function reportFailure (section, msg)
print (FAILED + lines[i]);
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
msg = msg.toString();
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
function toPrinted(value)
{
if (typeof value == "xml") {
@ -224,92 +176,7 @@ 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');
}

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

@ -52,50 +52,6 @@
var GLOBAL = this + '';
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -196,283 +152,3 @@ function version(v)
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -779,91 +779,3 @@ function OptLevel( i ) {
}
/* end of Rhino functions */
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();
}

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

@ -52,50 +52,6 @@
var GLOBAL = this + '';
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -196,283 +152,3 @@ function version(v)
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -266,91 +266,3 @@ function getTimeZoneDiff()
{
return -((new Date(2000, 1, 1)).getTimezoneOffset())/60;
}
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();
}

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

@ -34,436 +34,3 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JavaScript test library shared functions file for running the tests
* in the browser. Overrides the shell's print function with document.write
* and make everything HTML pretty.
*
* To run the tests in the browser, use the mkhtml.pl script to generate
* html pages that include the shell.js, browser.js (this file), and the
* test js file in script tags.
*
* The source of the page that is generated should look something like this:
* <script src="./../shell.js"></script>
* <script src="./../browser.js"></script>
* <script src="./mytest.js"></script>
*/
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
var testcases = new Array();
var tc = testcases.length;
var bug = '';
var summary = '';
var description = '';
var expected = '';
var actual = '';
var msg = '';
function TestCase(n, d, e, a)
{
this.path = (typeof gTestPath == 'undefined') ? '' : gTestPath;
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = ( e == a );
this.reason = '';
this.bugnumber = typeof(bug) != 'undefined' ? bug : '';
testcases[tc++] = this;
}
var gInReportCompare = false;
var _reportCompare = reportCompare;
reportCompare = function(expected, actual, description)
{
gInReportCompare = true;
var testcase = new TestCase(gTestName, description, expected, actual);
testcase.passed = _reportCompare(expected, actual, description);
gInReportCompare = false;
};
var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
optionsPush();
if (gInReportCompare)
{
testcase = testcases[tc - 1];
testcase.passed = false;
}
else
{
if (typeof(summary) == "undefined")
{
summary = "unknown";
}
if (typeof(expect) == "undefined")
{
expect = "unknown";
}
testcase = new TestCase(gTestName, summary, expect, "error");
if (document.location.href.indexOf('-n.js') != -1)
{
// negative test
testcase.passed = true;
}
}
testcase.reason += msg;
if (typeof(page) != 'undefined')
{
testcase.reason += ' Page: ' + page;
}
if (typeof(line) != 'undefined')
{
testcase.reason += ' Line: ' + line;
}
if (!testcase.passed)
{
_reportFailure(msg);
}
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function quit()
{
}
window.onerror = reportFailure;
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -37,387 +37,3 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
var VERBOSE = false;
var callStack = new Array();
/*
* 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.
*/
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
/*
* Statuses current section of a test
*/
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
/*
* Some tests need to know if we are in Rhino as opposed to SpiderMonkey
*/
function inRhino()
{
return (typeof defineClass == "function");
}
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
msg = msg.toString();
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
output = description + "\n" + output;
reportFailure (output);
}
else
{
print('PASSED! ' + description);
}
return (output == ""); // true if passed
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}
/*
Calculate the "order" of a set of data points {X: [], Y: []}
by computing successive "derivatives" of the data until
the data is exhausted or the derivative is linear.
*/
function BigO(data)
{
var order = 0;
var origLength = data.X.length;
while (data.X.length > 2)
{
var lr = new LinearRegression(data);
if (lr.b > 1e-6)
{
// only increase the order if the slope
// is "great" enough
order++;
}
if (lr.r > 0.98 || lr.Syx < 1 || lr.b < 1e-6)
{
// terminate if close to a line lr.r
// small error lr.Syx
// small slope lr.b
break;
}
data = dataDeriv(data);
}
if (2 == origLength - order)
{
order = Number.POSITIVE_INFINITY;
}
return order;
function LinearRegression(data)
{
/*
y = a + bx
for data points (Xi, Yi); 0 <= i < n
b = (n*SUM(XiYi) - SUM(Xi)*SUM(Yi))/(n*SUM(Xi*Xi) - SUM(Xi)*SUM(Xi))
a = (SUM(Yi) - b*SUM(Xi))/n
*/
var i;
if (data.X.length != data.Y.length)
{
throw 'LinearRegression: data point length mismatch';
}
if (data.X.length < 3)
{
throw 'LinearRegression: data point length < 2';
}
var n = data.X.length;
var X = data.X;
var Y = data.Y;
this.Xavg = 0;
this.Yavg = 0;
var SUM_X = 0;
var SUM_XY = 0;
var SUM_XX = 0;
var SUM_Y = 0;
var SUM_YY = 0;
for (i = 0; i < n; i++)
{
SUM_X += X[i];
SUM_XY += X[i]*Y[i];
SUM_XX += X[i]*X[i];
SUM_Y += Y[i];
SUM_YY += Y[i]*Y[i];
}
this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X);
this.a = (SUM_Y - this.b * SUM_X)/n;
this.Xavg = SUM_X/n;
this.Yavg = SUM_Y/n;
var SUM_Ydiff2 = 0;
var SUM_Xdiff2 = 0;
var SUM_XdiffYdiff = 0;
for (i = 0; i < n; i++)
{
var Ydiff = Y[i] - this.Yavg;
var Xdiff = X[i] - this.Xavg;
SUM_Ydiff2 += Ydiff * Ydiff;
SUM_Xdiff2 += Xdiff * Xdiff;
SUM_XdiffYdiff += Xdiff * Ydiff;
}
var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2);
var r2 = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) /
((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y));
this.Syx = Math.sqrt(Syx2);
this.r = Math.sqrt(r2);
}
function dataDeriv(data)
{
if (data.X.length != data.Y.length)
{
throw 'length mismatch';
}
var length = data.X.length;
if (length < 2)
{
throw 'length ' + length + ' must be >= 2';
}
var X = data.X;
var Y = data.Y;
var deriv = {X: [], Y: [] };
for (var i = 0; i < length - 1; i++)
{
deriv.X[i] = (X[i] + X[i+1])/2;
deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]);
}
return deriv;
}
}
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();
}

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

@ -64,13 +64,19 @@ function init()
return;
}
var suitepath = testpathparts.slice(0,testpathparts.length-2).join('/');
var subsuite = testpathparts[testpathparts.length - 2];
var test = testpathparts[testpathparts.length - 1];
var subsuite = testpathparts[testpathparts.length - 2];
var test = testpathparts[testpathparts.length - 1];
gTestName = test;
outputscripttag(suitepath + '/shell.js', attribute, value, ise4x);
outputscripttag(suitepath + '/browser.js', attribute, value, ise4x);
outputscripttag('shell.js', attribute, value,
false);
outputscripttag('browser.js', attribute, value,
false);
outputscripttag(suitepath + '/shell.js', attribute, value,
ise4x);
outputscripttag(suitepath + '/browser.js', attribute, value,
ise4x);
outputscripttag(suitepath + '/' + subsuite + '/shell.js', attribute, value,
ise4x);
outputscripttag(suitepath + '/' + subsuite + '/browser.js', attribute, value,

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

@ -52,50 +52,6 @@
GLOBAL = this + '';
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -194,283 +150,3 @@ function version(v) {
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -217,89 +217,3 @@ function getFailedCases() {
}
}
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();
}

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

@ -52,50 +52,6 @@
var GLOBAL = this + '';
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -197,283 +153,3 @@ function version(v)
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -191,89 +191,3 @@ function stopTest() {
}
}
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();
}

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

@ -52,50 +52,6 @@
GLOBAL = this + '';
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -195,283 +151,3 @@ function version(v)
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -239,89 +239,3 @@ function getFailedCases() {
}
}
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();
}

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

@ -52,50 +52,6 @@
GLOBAL = this + '';
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -196,283 +152,3 @@ function version(v)
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -240,89 +240,3 @@ function getFailedCases() {
}
}
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();
}

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

@ -35,437 +35,3 @@
*
* ***** END LICENSE BLOCK ***** */
/*
* JavaScript test library shared functions file for running the tests
* in the browser. Overrides the shell's print function with document.write
* and make everything HTML pretty.
*
* To run the tests in the browser, use the mkhtml.pl script to generate
* html pages that include the shell.js, browser.js (this file), and the
* test js file in script tags.
*
* The source of the page that is generated should look something like this:
* <script src="./../shell.js"></script>
* <script src="./../browser.js"></script>
* <script src="./mytest.js"></script>
*/
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
var testcases = new Array();
var tc = testcases.length;
var bug = '';
var summary = '';
var description = '';
var expected = '';
var actual = '';
var msg = '';
function TestCase(n, d, e, a)
{
this.path = (typeof gTestPath == 'undefined') ? '' : gTestPath;
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = ( e == a );
this.reason = '';
this.bugnumber = typeof(bug) != 'undefined' ? bug : '';
testcases[tc++] = this;
}
var gInReportCompare = false;
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;
optionsPush();
if (gInReportCompare)
{
testcase = testcases[tc - 1];
testcase.passed = false;
}
else
{
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
testcase = new TestCase(gTestName, DESCRIPTION, EXPECTED, "error");
if (document.location.href.indexOf('-n.js') != -1)
{
// negative test
testcase.passed = true;
}
}
testcase.reason += msg;
if (typeof(page) != 'undefined')
{
testcase.reason += ' Page: ' + page;
}
if (typeof(line) != 'undefined')
{
testcase.reason += ' Line: ' + line;
}
_reportFailure(msg);
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
print('gc: ' + ex);
}
}
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();

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

@ -39,430 +39,3 @@
*
* ***** END LICENSE BLOCK ***** */
var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var VERBOSE = false;
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
var callStack = new Array();
/*
* 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.
*/
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
/*
* Statuses current section of a test
*/
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
/*
* Some tests need to know if we are in Rhino as opposed to SpiderMonkey
*/
function inRhino()
{
return (typeof defineClass == "function");
}
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
msg = msg.toString();
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
else
{
print('PASSED! ' + description);
}
return (output == ""); // true if passed
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}
/*
Calculate the "order" of a set of data points {X: [], Y: []}
by computing successive "derivatives" of the data until
the data is exhausted or the derivative is linear.
*/
function BigO(data)
{
var order = 0;
var origLength = data.X.length;
while (data.X.length > 2)
{
var lr = new LinearRegression(data);
if (lr.b > 1e-6)
{
// only increase the order if the slope
// is "great" enough
order++;
}
if (lr.r > 0.98 || lr.Syx < 1 || lr.b < 1e-6)
{
// terminate if close to a line lr.r
// small error lr.Syx
// small slope lr.b
break;
}
data = dataDeriv(data);
}
if (2 == origLength - order)
{
order = Number.POSITIVE_INFINITY;
}
return order;
function LinearRegression(data)
{
/*
y = a + bx
for data points (Xi, Yi); 0 <= i < n
b = (n*SUM(XiYi) - SUM(Xi)*SUM(Yi))/(n*SUM(Xi*Xi) - SUM(Xi)*SUM(Xi))
a = (SUM(Yi) - b*SUM(Xi))/n
*/
var i;
if (data.X.length != data.Y.length)
{
throw 'LinearRegression: data point length mismatch';
}
if (data.X.length < 3)
{
throw 'LinearRegression: data point length < 2';
}
var n = data.X.length;
var X = data.X;
var Y = data.Y;
this.Xavg = 0;
this.Yavg = 0;
var SUM_X = 0;
var SUM_XY = 0;
var SUM_XX = 0;
var SUM_Y = 0;
var SUM_YY = 0;
for (i = 0; i < n; i++)
{
SUM_X += X[i];
SUM_XY += X[i]*Y[i];
SUM_XX += X[i]*X[i];
SUM_Y += Y[i];
SUM_YY += Y[i]*Y[i];
}
this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X);
this.a = (SUM_Y - this.b * SUM_X)/n;
this.Xavg = SUM_X/n;
this.Yavg = SUM_Y/n;
var SUM_Ydiff2 = 0;
var SUM_Xdiff2 = 0;
var SUM_XdiffYdiff = 0;
for (i = 0; i < n; i++)
{
var Ydiff = Y[i] - this.Yavg;
var Xdiff = X[i] - this.Xavg;
SUM_Ydiff2 += Ydiff * Ydiff;
SUM_Xdiff2 += Xdiff * Xdiff;
SUM_XdiffYdiff += Xdiff * Ydiff;
}
var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2);
var r2 = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) /
((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y));
this.Syx = Math.sqrt(Syx2);
this.r = Math.sqrt(r2);
}
function dataDeriv(data)
{
if (data.X.length != data.Y.length)
{
throw 'length mismatch';
}
var length = data.X.length;
if (length < 2)
{
throw 'length ' + length + ' must be >= 2';
}
var X = data.X;
var Y = data.Y;
var deriv = {X: [], Y: [] };
for (var i = 0; i < length - 1; i++)
{
deriv.X[i] = (X[i] + X[i+1])/2;
deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]);
}
return deriv;
}
}
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
print('expect:\n' + expectP);
print('actual:\n' + actualP);
reportCompare(expectP, actualP, summary);
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}
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();
}

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

@ -34,438 +34,3 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JavaScript test library shared functions file for running the tests
* in the browser. Overrides the shell's print function with document.write
* and make everything HTML pretty.
*
* To run the tests in the browser, use the mkhtml.pl script to generate
* html pages that include the shell.js, browser.js (this file), and the
* test js file in script tags.
*
* The source of the page that is generated should look something like this:
* <script src="./../shell.js"></script>
* <script src="./../browser.js"></script>
* <script src="./mytest.js"></script>
*/
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
var testcases = new Array();
var tc = testcases.length;
var bug = '';
var summary = '';
var description = '';
var expected = '';
var actual = '';
var msg = '';
function TestCase(n, d, e, a)
{
this.path = (typeof gTestPath == 'undefined') ? '' : gTestPath;
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = ( e == a );
this.reason = '';
this.bugnumber = typeof(bug) != 'undefined' ? bug : '';
testcases[tc++] = this;
}
var gInReportCompare = false;
var _reportCompare = reportCompare;
reportCompare = function(expected, actual, description)
{
gInReportCompare = true;
var testcase = new TestCase(gTestName, description, expected, actual);
testcase.passed = _reportCompare(expected, actual, description);
gInReportCompare = false;
};
var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
optionsPush();
if (gInReportCompare)
{
testcase = testcases[tc - 1];
testcase.passed = false;
}
else
{
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
testcase = new TestCase(gTestName, DESCRIPTION, EXPECTED, "error");
if (document.location.href.indexOf('-n.js') != -1)
{
// negative test
testcase.passed = true;
}
}
testcase.reason += msg;
if (typeof(page) != 'undefined')
{
testcase.reason += ' Page: ' + page;
}
if (typeof(line) != 'undefined')
{
testcase.reason += ' Line: ' + line;
}
if (!testcase.passed)
{
_reportFailure(msg);
}
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
print('gc: ' + ex);
}
}
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();

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

@ -39,431 +39,3 @@
*
* ***** END LICENSE BLOCK ***** */
var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var VERBOSE = false;
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
var callStack = new Array();
/*
* 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.
*/
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
/*
* Statuses current section of a test
*/
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
/*
* Some tests need to know if we are in Rhino as opposed to SpiderMonkey
*/
function inRhino()
{
return (typeof defineClass == "function");
}
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
msg = String(msg);
msg = msg.toString();
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
else
{
print('PASSED! ' + description);
}
return (output == ""); // true if passed
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}
/*
Calculate the "order" of a set of data points {X: [], Y: []}
by computing successive "derivatives" of the data until
the data is exhausted or the derivative is linear.
*/
function BigO(data)
{
var order = 0;
var origLength = data.X.length;
while (data.X.length > 2)
{
var lr = new LinearRegression(data);
if (lr.b > 1e-6)
{
// only increase the order if the slope
// is "great" enough
order++;
}
if (lr.r > 0.98 || lr.Syx < 1 || lr.b < 1e-6)
{
// terminate if close to a line lr.r
// small error lr.Syx
// small slope lr.b
break;
}
data = dataDeriv(data);
}
if (2 == origLength - order)
{
order = Number.POSITIVE_INFINITY;
}
return order;
function LinearRegression(data)
{
/*
y = a + bx
for data points (Xi, Yi); 0 <= i < n
b = (n*SUM(XiYi) - SUM(Xi)*SUM(Yi))/(n*SUM(Xi*Xi) - SUM(Xi)*SUM(Xi))
a = (SUM(Yi) - b*SUM(Xi))/n
*/
var i;
if (data.X.length != data.Y.length)
{
throw 'LinearRegression: data point length mismatch';
}
if (data.X.length < 3)
{
throw 'LinearRegression: data point length < 2';
}
var n = data.X.length;
var X = data.X;
var Y = data.Y;
this.Xavg = 0;
this.Yavg = 0;
var SUM_X = 0;
var SUM_XY = 0;
var SUM_XX = 0;
var SUM_Y = 0;
var SUM_YY = 0;
for (i = 0; i < n; i++)
{
SUM_X += X[i];
SUM_XY += X[i]*Y[i];
SUM_XX += X[i]*X[i];
SUM_Y += Y[i];
SUM_YY += Y[i]*Y[i];
}
this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X);
this.a = (SUM_Y - this.b * SUM_X)/n;
this.Xavg = SUM_X/n;
this.Yavg = SUM_Y/n;
var SUM_Ydiff2 = 0;
var SUM_Xdiff2 = 0;
var SUM_XdiffYdiff = 0;
for (i = 0; i < n; i++)
{
var Ydiff = Y[i] - this.Yavg;
var Xdiff = X[i] - this.Xavg;
SUM_Ydiff2 += Ydiff * Ydiff;
SUM_Xdiff2 += Xdiff * Xdiff;
SUM_XdiffYdiff += Xdiff * Ydiff;
}
var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2);
var r2 = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) /
((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y));
this.Syx = Math.sqrt(Syx2);
this.r = Math.sqrt(r2);
}
function dataDeriv(data)
{
if (data.X.length != data.Y.length)
{
throw 'length mismatch';
}
var length = data.X.length;
if (length < 2)
{
throw 'length ' + length + ' must be >= 2';
}
var X = data.X;
var Y = data.Y;
var deriv = {X: [], Y: [] };
for (var i = 0; i < length - 1; i++)
{
deriv.X[i] = (X[i] + X[i+1])/2;
deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]);
}
return deriv;
}
}
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
print('expect:\n' + expectP);
print('actual:\n' + actualP);
reportCompare(expectP, actualP, summary);
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}
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();
}

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

@ -34,437 +34,3 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JavaScript test library shared functions file for running the tests
* in the browser. Overrides the shell's print function with document.write
* and make everything HTML pretty.
*
* To run the tests in the browser, use the mkhtml.pl script to generate
* html pages that include the shell.js, browser.js (this file), and the
* test js file in script tags.
*
* The source of the page that is generated should look something like this:
* <script src="./../shell.js"></script>
* <script src="./../browser.js"></script>
* <script src="./mytest.js"></script>
*/
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
var testcases = new Array();
var tc = testcases.length;
var bug = '';
var summary = '';
var description = '';
var expected = '';
var actual = '';
var msg = '';
function TestCase(n, d, e, a)
{
this.path = (typeof gTestPath == 'undefined') ? '' : gTestPath;
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = ( e == a );
this.reason = '';
this.bugnumber = typeof(bug) != 'undefined' ? bug : '';
testcases[tc++] = this;
}
var gInReportCompare = false;
var _reportCompare = reportCompare;
reportCompare = function(expected, actual, description)
{
gInReportCompare = true;
var testcase = new TestCase(gTestName, description, expected, actual);
testcase.passed = _reportCompare(expected, actual, description);
gInReportCompare = false;
};
var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
optionsPush();
if (gInReportCompare)
{
testcase = testcases[tc - 1];
testcase.passed = false;
}
else
{
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
testcase = new TestCase(gTestName, DESCRIPTION, EXPECTED, "error");
if (document.location.href.indexOf('-n.js') != -1)
{
// negative test
testcase.passed = true;
}
}
testcase.reason += msg;
if (typeof(page) != 'undefined')
{
testcase.reason += ' Page: ' + page;
}
if (typeof(line) != 'undefined')
{
testcase.reason += ' Line: ' + line;
}
if (!testcase.passed)
{
_reportFailure(msg);
}
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
print('gc: ' + ex);
}
}
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();

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

@ -45,431 +45,3 @@ if (typeof version != 'undefined')
version(170);
}
var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var VERBOSE = false;
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
var callStack = new Array();
/*
* 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.
*/
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
/*
* Statuses current section of a test
*/
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
/*
* Some tests need to know if we are in Rhino as opposed to SpiderMonkey
*/
function inRhino()
{
return (typeof defineClass == "function");
}
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
msg = String(msg);
msg = msg.toString();
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
else
{
print('PASSED! ' + description);
}
return (output == ""); // true if passed
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}
/*
Calculate the "order" of a set of data points {X: [], Y: []}
by computing successive "derivatives" of the data until
the data is exhausted or the derivative is linear.
*/
function BigO(data)
{
var order = 0;
var origLength = data.X.length;
while (data.X.length > 2)
{
var lr = new LinearRegression(data);
if (lr.b > 1e-6)
{
// only increase the order if the slope
// is "great" enough
order++;
}
if (lr.r > 0.98 || lr.Syx < 1 || lr.b < 1e-6)
{
// terminate if close to a line lr.r
// small error lr.Syx
// small slope lr.b
break;
}
data = dataDeriv(data);
}
if (2 == origLength - order)
{
order = Number.POSITIVE_INFINITY;
}
return order;
function LinearRegression(data)
{
/*
y = a + bx
for data points (Xi, Yi); 0 <= i < n
b = (n*SUM(XiYi) - SUM(Xi)*SUM(Yi))/(n*SUM(Xi*Xi) - SUM(Xi)*SUM(Xi))
a = (SUM(Yi) - b*SUM(Xi))/n
*/
var i;
if (data.X.length != data.Y.length)
{
throw 'LinearRegression: data point length mismatch';
}
if (data.X.length < 3)
{
throw 'LinearRegression: data point length < 2';
}
var n = data.X.length;
var X = data.X;
var Y = data.Y;
this.Xavg = 0;
this.Yavg = 0;
var SUM_X = 0;
var SUM_XY = 0;
var SUM_XX = 0;
var SUM_Y = 0;
var SUM_YY = 0;
for (i = 0; i < n; i++)
{
SUM_X += X[i];
SUM_XY += X[i]*Y[i];
SUM_XX += X[i]*X[i];
SUM_Y += Y[i];
SUM_YY += Y[i]*Y[i];
}
this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X);
this.a = (SUM_Y - this.b * SUM_X)/n;
this.Xavg = SUM_X/n;
this.Yavg = SUM_Y/n;
var SUM_Ydiff2 = 0;
var SUM_Xdiff2 = 0;
var SUM_XdiffYdiff = 0;
for (i = 0; i < n; i++)
{
var Ydiff = Y[i] - this.Yavg;
var Xdiff = X[i] - this.Xavg;
SUM_Ydiff2 += Ydiff * Ydiff;
SUM_Xdiff2 += Xdiff * Xdiff;
SUM_XdiffYdiff += Xdiff * Ydiff;
}
var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2);
var r2 = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) /
((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y));
this.Syx = Math.sqrt(Syx2);
this.r = Math.sqrt(r2);
}
function dataDeriv(data)
{
if (data.X.length != data.Y.length)
{
throw 'length mismatch';
}
var length = data.X.length;
if (length < 2)
{
throw 'length ' + length + ' must be >= 2';
}
var X = data.X;
var Y = data.Y;
var deriv = {X: [], Y: [] };
for (var i = 0; i < length - 1; i++)
{
deriv.X[i] = (X[i] + X[i+1])/2;
deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]);
}
return deriv;
}
}
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
print('expect:\n' + expectP);
print('actual:\n' + actualP);
reportCompare(expectP, actualP, summary + ': compare source');
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}
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();
}

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

@ -34,437 +34,3 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JavaScript test library shared functions file for running the tests
* in the browser. Overrides the shell's print function with document.write
* and make everything HTML pretty.
*
* To run the tests in the browser, use the mkhtml.pl script to generate
* html pages that include the shell.js, browser.js (this file), and the
* test js file in script tags.
*
* The source of the page that is generated should look something like this:
* <script src="./../shell.js"></script>
* <script src="./../browser.js"></script>
* <script src="./mytest.js"></script>
*/
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
var testcases = new Array();
var tc = testcases.length;
var bug = '';
var summary = '';
var description = '';
var expected = '';
var actual = '';
var msg = '';
function TestCase(n, d, e, a)
{
this.path = (typeof gTestPath == 'undefined') ? '' : gTestPath;
this.name = n;
this.description = d;
this.expect = e;
this.actual = a;
this.passed = ( e == a );
this.reason = '';
this.bugnumber = typeof(bug) != 'undefined' ? bug : '';
testcases[tc++] = this;
}
var gInReportCompare = false;
var _reportCompare = reportCompare;
reportCompare = function(expected, actual, description)
{
gInReportCompare = true;
var testcase = new TestCase(gTestName, description, expected, actual);
testcase.passed = _reportCompare(expected, actual, description);
gInReportCompare = false;
};
var _reportFailure = reportFailure;
reportFailure = function (msg, page, line)
{
var testcase;
optionsPush();
if (gInReportCompare)
{
testcase = testcases[tc - 1];
testcase.passed = false;
}
else
{
if (typeof DESCRIPTION == 'undefined')
{
DESCRIPTION = 'Unknown';
}
if (typeof EXPECTED == 'undefined')
{
EXPECTED = 'Unknown';
}
testcase = new TestCase(gTestName, DESCRIPTION, EXPECTED, "error");
if (document.location.href.indexOf('-n.js') != -1)
{
// negative test
testcase.passed = true;
}
}
testcase.reason += msg;
if (typeof(page) != 'undefined')
{
testcase.reason += ' Page: ' + page;
}
if (typeof(line) != 'undefined')
{
testcase.reason += ' Line: ' + line;
}
if (!testcase.passed)
{
_reportFailure(msg);
}
gDelayTestDriverEnd = false;
jsTestDriverEnd();
optionsReset();
};
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
print('gc: ' + ex);
}
}
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();

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

@ -45,431 +45,3 @@ if (typeof version != 'undefined')
version(170);
}
var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var VERBOSE = false;
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
var callStack = new Array();
/*
* 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.
*/
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
/*
* Statuses current section of a test
*/
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
/*
* Some tests need to know if we are in Rhino as opposed to SpiderMonkey
*/
function inRhino()
{
return (typeof defineClass == "function");
}
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
msg = String(msg);
msg = msg.toString();
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
else
{
print('PASSED! ' + description);
}
return (output == ""); // true if passed
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}
/*
Calculate the "order" of a set of data points {X: [], Y: []}
by computing successive "derivatives" of the data until
the data is exhausted or the derivative is linear.
*/
function BigO(data)
{
var order = 0;
var origLength = data.X.length;
while (data.X.length > 2)
{
var lr = new LinearRegression(data);
if (lr.b > 1e-6)
{
// only increase the order if the slope
// is "great" enough
order++;
}
if (lr.r > 0.98 || lr.Syx < 1 || lr.b < 1e-6)
{
// terminate if close to a line lr.r
// small error lr.Syx
// small slope lr.b
break;
}
data = dataDeriv(data);
}
if (2 == origLength - order)
{
order = Number.POSITIVE_INFINITY;
}
return order;
function LinearRegression(data)
{
/*
y = a + bx
for data points (Xi, Yi); 0 <= i < n
b = (n*SUM(XiYi) - SUM(Xi)*SUM(Yi))/(n*SUM(Xi*Xi) - SUM(Xi)*SUM(Xi))
a = (SUM(Yi) - b*SUM(Xi))/n
*/
var i;
if (data.X.length != data.Y.length)
{
throw 'LinearRegression: data point length mismatch';
}
if (data.X.length < 3)
{
throw 'LinearRegression: data point length < 2';
}
var n = data.X.length;
var X = data.X;
var Y = data.Y;
this.Xavg = 0;
this.Yavg = 0;
var SUM_X = 0;
var SUM_XY = 0;
var SUM_XX = 0;
var SUM_Y = 0;
var SUM_YY = 0;
for (i = 0; i < n; i++)
{
SUM_X += X[i];
SUM_XY += X[i]*Y[i];
SUM_XX += X[i]*X[i];
SUM_Y += Y[i];
SUM_YY += Y[i]*Y[i];
}
this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X);
this.a = (SUM_Y - this.b * SUM_X)/n;
this.Xavg = SUM_X/n;
this.Yavg = SUM_Y/n;
var SUM_Ydiff2 = 0;
var SUM_Xdiff2 = 0;
var SUM_XdiffYdiff = 0;
for (i = 0; i < n; i++)
{
var Ydiff = Y[i] - this.Yavg;
var Xdiff = X[i] - this.Xavg;
SUM_Ydiff2 += Ydiff * Ydiff;
SUM_Xdiff2 += Xdiff * Xdiff;
SUM_XdiffYdiff += Xdiff * Ydiff;
}
var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2);
var r2 = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) /
((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y));
this.Syx = Math.sqrt(Syx2);
this.r = Math.sqrt(r2);
}
function dataDeriv(data)
{
if (data.X.length != data.Y.length)
{
throw 'length mismatch';
}
var length = data.X.length;
if (length < 2)
{
throw 'length ' + length + ' must be >= 2';
}
var X = data.X;
var Y = data.Y;
var deriv = {X: [], Y: [] };
for (var i = 0; i < length - 1; i++)
{
deriv.X[i] = (X[i] + X[i+1])/2;
deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]);
}
return deriv;
}
}
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
print('expect:\n' + expectP);
print('actual:\n' + actualP);
reportCompare(expectP, actualP, summary + ': compare source');
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}
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();
}

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

@ -208,6 +208,12 @@ sub execute_tests {
if ($last_suite ne $suite || $last_test_dir ne $test_dir) {
$shell_command = &xp_path($engine_command);
$path = &xp_path($opt_suite_path ."shell.js");
if (-f $path) {
$shell_command = &append_file_to_command($shell_command,
$path);
}
$path = &xp_path($opt_suite_path . $suite . "/shell.js");
if (-f $path) {
$shell_command = &append_file_to_command($shell_command,

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

@ -53,50 +53,6 @@ var H2 = "<h2>";
var H2_ = "</h2>";
var HR = "<hr>";
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -220,283 +176,3 @@ function version(v)
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -263,89 +263,3 @@ function getFailedCases() {
}
}
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();
}

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

@ -67,50 +67,6 @@ var H2 = "<h2>";
var H2_ = "</h2>";
var HR = "<hr>";
function htmlesc(str) {
if (str == '<')
return '&lt;';
if (str == '>')
return '&gt;';
if (str == '&')
return '&amp;';
return str;
}
function DocumentWrite(s)
{
try
{
var msgDiv = document.createElement('div');
msgDiv.innerHTML = s;
document.body.appendChild(msgDiv);
msgDiv = null;
}
catch(excp)
{
document.write(s + '<br>\n');
}
}
function print() {
var s = '';
var a;
for (var i = 0; i < arguments.length; i++)
{
a = arguments[i];
s += String(a) + ' ';
}
if (typeof dump == 'function')
{
dump( s + '\n');
}
s = s.replace(/[<>&]/g, htmlesc);
DocumentWrite(s);
}
function writeHeaderToLog( string ) {
string = String(string);
@ -212,283 +168,3 @@ function version(v)
return gVersion;
}
function gc()
{
// Thanks to igor.bukanov@gmail.com
for (var i = 0; i != 100000; ++i)
{
var tmp = new Object();
}
}
function jsdgc()
{
try
{
// Thanks to dveditz
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
var service = Components.classes['@mozilla.org/js/jsd/debugger-service;1'].
getService(jsdIDebuggerService);
service.GC();
}
catch(ex)
{
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();

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

@ -275,90 +275,3 @@ function getFailedCases() {
}
}
}
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();
}

472
js/tests/shell.js Normal file
Просмотреть файл

@ -0,0 +1,472 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Rob Ginda rginda@netscape.com
* Bob Clary bob@bclary.com
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var VERBOSE = false;
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
var callStack = new Array();
/*
* 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.
*/
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
/*
* Statuses current section of a test
*/
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
/*
* Some tests need to know if we are in Rhino as opposed to SpiderMonkey
*/
function inRhino()
{
return (typeof defineClass == "function");
}
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
/* js1_6 had...
msg = String(msg);
msg = msg.toString();
*/
msg = msg.toString();
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
else
{
print('PASSED! ' + description);
}
return (output == ""); // true if passed
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}
/*
Calculate the "order" of a set of data points {X: [], Y: []}
by computing successive "derivatives" of the data until
the data is exhausted or the derivative is linear.
*/
function BigO(data)
{
var order = 0;
var origLength = data.X.length;
while (data.X.length > 2)
{
var lr = new LinearRegression(data);
if (lr.b > 1e-6)
{
// only increase the order if the slope
// is "great" enough
order++;
}
if (lr.r > 0.98 || lr.Syx < 1 || lr.b < 1e-6)
{
// terminate if close to a line lr.r
// small error lr.Syx
// small slope lr.b
break;
}
data = dataDeriv(data);
}
if (2 == origLength - order)
{
order = Number.POSITIVE_INFINITY;
}
return order;
function LinearRegression(data)
{
/*
y = a + bx
for data points (Xi, Yi); 0 <= i < n
b = (n*SUM(XiYi) - SUM(Xi)*SUM(Yi))/(n*SUM(Xi*Xi) - SUM(Xi)*SUM(Xi))
a = (SUM(Yi) - b*SUM(Xi))/n
*/
var i;
if (data.X.length != data.Y.length)
{
throw 'LinearRegression: data point length mismatch';
}
if (data.X.length < 3)
{
throw 'LinearRegression: data point length < 2';
}
var n = data.X.length;
var X = data.X;
var Y = data.Y;
this.Xavg = 0;
this.Yavg = 0;
var SUM_X = 0;
var SUM_XY = 0;
var SUM_XX = 0;
var SUM_Y = 0;
var SUM_YY = 0;
for (i = 0; i < n; i++)
{
SUM_X += X[i];
SUM_XY += X[i]*Y[i];
SUM_XX += X[i]*X[i];
SUM_Y += Y[i];
SUM_YY += Y[i]*Y[i];
}
this.b = (n * SUM_XY - SUM_X * SUM_Y)/(n * SUM_XX - SUM_X * SUM_X);
this.a = (SUM_Y - this.b * SUM_X)/n;
this.Xavg = SUM_X/n;
this.Yavg = SUM_Y/n;
var SUM_Ydiff2 = 0;
var SUM_Xdiff2 = 0;
var SUM_XdiffYdiff = 0;
for (i = 0; i < n; i++)
{
var Ydiff = Y[i] - this.Yavg;
var Xdiff = X[i] - this.Xavg;
SUM_Ydiff2 += Ydiff * Ydiff;
SUM_Xdiff2 += Xdiff * Xdiff;
SUM_XdiffYdiff += Xdiff * Ydiff;
}
var Syx2 = (SUM_Ydiff2 - Math.pow(SUM_XdiffYdiff/SUM_Xdiff2, 2))/(n - 2);
var r2 = Math.pow((n*SUM_XY - SUM_X * SUM_Y), 2) /
((n*SUM_XX - SUM_X*SUM_X)*(n*SUM_YY-SUM_Y*SUM_Y));
this.Syx = Math.sqrt(Syx2);
this.r = Math.sqrt(r2);
}
function dataDeriv(data)
{
if (data.X.length != data.Y.length)
{
throw 'length mismatch';
}
var length = data.X.length;
if (length < 2)
{
throw 'length ' + length + ' must be >= 2';
}
var X = data.X;
var Y = data.Y;
var deriv = {X: [], Y: [] };
for (var i = 0; i < length - 1; i++)
{
deriv.X[i] = (X[i] + X[i+1])/2;
deriv.Y[i] = (Y[i+1] - Y[i])/(X[i+1] - X[i]);
}
return deriv;
}
}
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
print('expect:\n' + expectP);
print('actual:\n' + actualP);
reportCompare(expectP, actualP, summary);
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}
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();
}

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

@ -133,9 +133,6 @@
./js1_5/extensions/regress-350312-02.js
./js1_5/extensions/regress-350312-03.js
./js1_5/extensions/regress-350531.js
./js1_5/extensions/regress-351102-01.js
./js1_5/extensions/regress-351102-02.js
./js1_5/extensions/regress-351102-06.js
./js1_5/extensions/regress-351448.js
./js1_5/extensions/regress-351973.js
./js1_5/extensions/regress-352060.js
@ -152,7 +149,6 @@
./js1_5/extensions/regress-354541-04.js
./js1_5/extensions/regress-355339.js
./js1_5/extensions/regress-355497.js
./js1_5/extensions/regress-355655.js
./js1_5/extensions/regress-355736.js
./js1_5/extensions/regress-355820.js
./js1_5/extensions/regress-355982.js
@ -167,7 +163,6 @@
./js1_5/extensions/regress-361964.js
./js1_5/extensions/regress-363988.js
./js1_5/extensions/regress-365527.js
./js1_5/extensions/regress-365692.js
./js1_5/extensions/regress-365869.js
./js1_5/extensions/regress-366288.js
./js1_5/extensions/regress-366292.js
@ -178,18 +173,11 @@
./js1_5/extensions/regress-367119-02.js
./js1_5/extensions/regress-367120-01.js
./js1_5/extensions/regress-367120-02.js
./js1_5/extensions/regress-367501-01.js
./js1_5/extensions/regress-367501-02.js
./js1_5/extensions/regress-367501-03.js
./js1_5/extensions/regress-367501-04.js
./js1_5/extensions/regress-367589.js
./js1_5/extensions/regress-367630.js
./js1_5/extensions/regress-367923.js
./js1_5/extensions/regress-368859.js
./js1_5/extensions/regress-369404.js
./js1_5/extensions/regress-372309.js
./js1_5/extensions/regress-374589.js
./js1_5/extensions/regress-375183.js
./js1_5/extensions/regress-376052.js
./js1_5/extensions/regress-44009.js
./js1_5/extensions/regress-50447-1.js
@ -212,10 +200,6 @@
./js1_7/extensions/regress-349619.js
./js1_7/extensions/regress-350312.js
./js1_7/extensions/regress-351070-02.js
./js1_7/extensions/regress-351102-03.js
./js1_7/extensions/regress-351102-04.js
./js1_7/extensions/regress-351102-05.js
./js1_7/extensions/regress-351102-07.js
./js1_7/extensions/regress-352797-01.js
./js1_7/extensions/regress-352885-01.js
./js1_7/extensions/regress-352885-02.js