On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / js / tests / js1_2 / jsref.js
blobeb43b0b505428df6643efe1f9ca5be243cab8f35
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is Mozilla Communicator client code, released
15 * March 31, 1998.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 var completed = false;
38 var testcases;
39 var tc = 0;
41 SECTION = "";
42 VERSION = "";
43 BUGNUMBER = "";
44 EXCLUDE = "";
47 * constant strings
49 var GLOBAL = "[object global]";
50 var PASSED = " PASSED!"
51 var FAILED = " FAILED! expected: ";
53 var DEBUG = false;
55 version("120");
57 * change this for date tests if you're not in PST
60 TZ_DIFF = -8;
61 /* wrapper for test cas constructor that doesn't require the SECTION
62 * argument.
65 function AddTestCase( description, expect, actual ) {
66 testcases[tc++] = new TestCase( SECTION, description, expect, actual );
68 function TestCase( n, d, e, a ) {
69 this.name = n;
70 this.description = d;
71 this.expect = e;
72 this.actual = a;
73 this.passed = true;
74 this.reason = "";
75 this.bugnumber = BUGNUMBER;
77 this.passed = getTestCaseResult( this.expect, this.actual );
79 function startTest() {
80 version(120);
82 // for ecma version 2.0, we will leave the javascript version to
83 // the default ( for now ).
84 // print out bugnumber
86 if ( BUGNUMBER ) {
87 print ("BUGNUMBER: " + BUGNUMBER );
90 testcases = new Array();
91 tc = 0;
94 function test() {
95 for ( tc=0; tc < testcases.length; tc++ ) {
96 testcases[tc].passed = writeTestCaseResult(
97 testcases[tc].expect,
98 testcases[tc].actual,
99 testcases[tc].description +" = "+
100 testcases[tc].actual );
102 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
104 stopTest();
105 return ( testcases );
107 function getTestCaseResult( expect, actual ) {
108 // because ( NaN == NaN ) always returns false, need to do
109 // a special compare to see if we got the right result.
110 if ( actual != actual ) {
111 if ( typeof actual == "object" ) {
112 actual = "NaN object";
113 } else {
114 actual = "NaN number";
117 if ( expect != expect ) {
118 if ( typeof expect == "object" ) {
119 expect = "NaN object";
120 } else {
121 expect = "NaN number";
125 var passed = ( expect == actual ) ? true : false;
127 // if both objects are numbers, give a little leeway for rounding.
128 if ( !passed
129 && typeof(actual) == "number"
130 && typeof(expect) == "number"
132 if ( Math.abs(actual-expect) < 0.0000001 ) {
133 passed = true;
137 // verify type is the same
138 if ( typeof(expect) != typeof(actual) ) {
139 passed = false;
142 return passed;
145 * Begin printing functions. These functions use the shell's
146 * print function. When running tests in the browser, these
147 * functions, override these functions with functions that use
148 * document.write.
151 function writeTestCaseResult( expect, actual, string ) {
152 var passed = getTestCaseResult( expect, actual );
153 writeFormattedResult( expect, actual, string, passed );
154 return passed;
156 function writeFormattedResult( expect, actual, string, passed ) {
157 var s = string ;
158 s += ( passed ) ? PASSED : FAILED + expect;
159 print( s);
160 return passed;
163 function writeHeaderToLog( string ) {
164 print( string );
166 /* end of print functions */
169 function stopTest() {
170 var sizeTag = "<#TEST CASES SIZE>";
171 var doneTag = "<#TEST CASES DONE>";
172 var beginTag = "<#TEST CASE ";
173 var endTag = ">";
175 print(sizeTag);
176 print(testcases.length);
177 for (tc = 0; tc < testcases.length; tc++)
179 print(beginTag + 'PASSED' + endTag);
180 print(testcases[tc].passed);
181 print(beginTag + 'NAME' + endTag);
182 print(testcases[tc].name);
183 print(beginTag + 'EXPECTED' + endTag);
184 print(testcases[tc].expect);
185 print(beginTag + 'ACTUAL' + endTag);
186 print(testcases[tc].actual);
187 print(beginTag + 'DESCRIPTION' + endTag);
188 print(testcases[tc].description);
189 print(beginTag + 'REASON' + endTag);
190 print(( testcases[tc].passed ) ? "" : "wrong value ");
191 print(beginTag + 'BUGNUMBER' + endTag);
192 print( BUGNUMBER );
194 print(doneTag);
195 gc();
198 function getFailedCases() {
199 for ( var i = 0; i < testcases.length; i++ ) {
200 if ( ! testcases[i].passed ) {
201 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
205 function err( msg, page, line ) {
206 testcases[tc].actual = "error";
207 testcases[tc].reason = msg;
208 writeTestCaseResult( testcases[tc].expect,
209 testcases[tc].actual,
210 testcases[tc].description +" = "+ testcases[tc].actual +
211 ": " + testcases[tc].reason );
212 stopTest();
213 return true;
215 function Enumerate ( o ) {
216 var p;
217 for ( p in o ) {
218 print( p +": " + o[p] );
221 function GetContext() {
222 return Packages.com.netscape.javascript.Context.getCurrentContext();
224 function OptLevel( i ) {
225 i = Number(i);
226 var cx = GetContext();
227 cx.setOptimizationLevel(i);