]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/for-in-array-mode.js
9002b940ad596b75481f02540e50ac9e9cbb5088
2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 var funcArgAndBodyStr
=
28 " var sum = 0;" + "\n" +
29 " for (var i in arr)" + "\n" +
30 " sum += arr[i];" + "\n" +
31 " return sum;" + "\n" +
35 "ArrayWithUndecided": { in: [], out: 0 },
36 "ArrayWithInt32": { in: [ 1, 2, 3 ], out: 6 },
37 "ArrayWithContiguous": { in: [ "a", "b", "c" ], out: "0abc" },
38 "ArrayWithDouble": { in: [10.25, 20.25, 30.25 ], out: 60.75 },
39 "ArrayWithArrayStorage": { in: [ "a", "b", "c" ], out: "0abc1000" }, // The in array will be augmented below.
40 "ArrayWithSlowPutArrayStorage": { in: [ "a", "b", "c" ], out: "0abc10" }, // the in array will be augmented below.
42 "NonArrayWithUndecided": { in: {}, out: 0 },
43 "NonArrayWithInt32": { in: { "0":1, "1":2, "2":3 }, out: 6 },
44 "NonArrayWithContiguous": { in: { "0":"a", "1":"b", "2":"c" }, out: "0abc" },
45 "NonArrayWithDouble": { in: { "0":10.25, "1":20.25, "2":30.25 }, out: 60.75 },
46 "NonArrayWithArrayStorage": { in: { "0":"a", "1":"b", "2":"c" }, out: "0abc1000" }, // The in obj will be augmented below.
47 "NonArrayWithSlowPutArrayStorage": { in: { "0":"a", "1":"b", "2":"c" }, out: "0abc10" }, // the in obj will be augmented below.
52 Object
.defineProperties(o
, {
54 get: function() { return this.a
; },
55 set: function(x
) { this.a
= x
; },
59 testData
["ArrayWithArrayStorage"].in[1000] = 1000;
60 testData
["ArrayWithSlowPutArrayStorage"].in.__proto__
= o
;
61 testData
["NonArrayWithArrayStorage"].in["1000"] = 1000;
62 testData
["NonArrayWithSlowPutArrayStorage"].in.__proto__
= o
;
64 var numberOfFailures
= 0;
66 function test(name
, data
) {
67 eval("function " + name
+ funcArgAndBodyStr
);
72 for (var i
= 0; i
< 10000; ++i
) {
73 var expected
= data
.out
;
74 var actual
= eval(name
+ "(data.in)");
76 if ((actual
!= expected
) && (actual
!= previousResult
)) {
77 print("FAIL: " + name
+ ": expected: " + expected
+ ", actual: " + actual
+ ", starting @ loop iteration " + i
);
78 previousResult
= actual
;
85 for (name
in testData
)
86 test(name
, testData
[name
]);
89 throw "Error: number of failures found: " + numberOfFailures
;