On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / js / tests / js1_2 / Array / splice1.js
blob91925a472f3a2b33115b4bb409a238bd9c76116a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile = 'splice1.js';
41 /**
42 Filename: splice1.js
43 Description: 'Tests Array.splice(x,y) w/no var args'
45 Author: Nick Lerissa
46 Date: Fri Feb 13 09:58:28 PST 1998
49 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
50 var VERSION = 'no version';
51 var TITLE = 'String:splice 1';
52 var BUGNUMBER="123795";
54 startTest();
55 writeHeaderToLog('Executing script: splice1.js');
56 writeHeaderToLog( SECTION + " "+ TITLE);
58 var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
59 var b = [1,2,3,4,5,6,7,8,9,0];
61 exhaustiveSpliceTest("exhaustive splice w/no optional args 1",a);
62 exhaustiveSpliceTest("exhaustive splice w/no optional args 1",b);
64 test();
67 function mySplice(testArray, splicedArray, first, len, elements)
69 var removedArray = [];
70 var adjustedFirst = first;
71 var adjustedLen = len;
73 if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
74 if (adjustedFirst < 0) adjustedFirst = 0;
76 if (adjustedLen < 0) adjustedLen = 0;
78 for (i = 0; (i < adjustedFirst)&&(i < testArray.length); ++i)
79 splicedArray.push(testArray[i]);
81 if (adjustedFirst < testArray.length)
82 for (i = adjustedFirst; (i < adjustedFirst + adjustedLen) &&
83 (i < testArray.length); ++i)
85 removedArray.push(testArray[i]);
88 for (i = 0; i < elements.length; i++) splicedArray.push(elements[i]);
90 for (i = adjustedFirst + adjustedLen; i < testArray.length; i++)
91 splicedArray.push(testArray[i]);
93 return removedArray;
96 function exhaustiveSpliceTest(testname, testArray)
98 var errorMessage;
99 var passed = true;
100 var reason = "";
102 for (var first = -(testArray.length+2); first <= 2 + testArray.length; first++)
104 var actualSpliced = [];
105 var expectedSpliced = [];
106 var actualRemoved = [];
107 var expectedRemoved = [];
109 for (var len = 0; len < testArray.length + 2; len++)
111 actualSpliced = [];
112 expectedSpliced = [];
114 for (var i = 0; i < testArray.length; ++i)
115 actualSpliced.push(testArray[i]);
117 actualRemoved = actualSpliced.splice(first,len);
118 expectedRemoved = mySplice(testArray,expectedSpliced,first,len,[]);
120 var adjustedFirst = first;
121 if (adjustedFirst < 0) adjustedFirst = testArray.length + first;
122 if (adjustedFirst < 0) adjustedFirst = 0;
124 if ( (String(actualSpliced) != String(expectedSpliced))
125 ||(String(actualRemoved) != String(expectedRemoved)))
127 if ( (String(actualSpliced) == String(expectedSpliced))
128 &&(String(actualRemoved) != String(expectedRemoved)) )
130 if ( (expectedRemoved.length == 1)
131 &&(String(actualRemoved) == String(expectedRemoved[0]))) continue;
132 if ( expectedRemoved.length == 0 && actualRemoved == void 0) continue;
135 errorMessage =
136 "ERROR: 'TEST FAILED'\n" +
137 " test: " + "a.splice(" + first + "," + len + ",-97,new String('test arg'),[],9.8)\n" +
138 " a: " + String(testArray) + "\n" +
139 " actual spliced: " + String(actualSpliced) + "\n" +
140 " expected spliced: " + String(expectedSpliced) + "\n" +
141 " actual removed: " + String(actualRemoved) + "\n" +
142 " expected removed: " + String(expectedRemoved) + "\n";
143 writeHeaderToLog(errorMessage);
144 reason = reason + errorMessage;
145 passed = false;
149 var testcase = new TestCase( SECTION, testname, true, passed);
150 if (!passed)
151 testcase.reason = reason;
152 return testcase;