-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy patharray_indexOf.js
119 lines (95 loc) · 3.03 KB
/
array_indexOf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
var x = [1, 2, 2, 4, 5, +0, -0, NaN, 0, true, true , false]
for(i=-3; i < 15;i++)
{
WScript.Echo(x.indexOf(i));
for(j=-3; j< 15;j++)
{
WScript.Echo(x.indexOf(x[i],j));
WScript.Echo(x.indexOf(i,j));
}
}
WScript.Echo(x.indexOf(-0, -0));
var b = function(){};
b.prototype = Array.prototype;
var y = new b();
var z = new Object();
var a = new Object();
y[0] = "abc";
y[1] = "def";
y[2] = "efg";
y[3] = true;
y[4] = true;
y[5] = false;
y[6] = a;
y[7] = a;
y[8] = null;
y.length = 10;
WScript.Echo(y.indexOf("abc"));
WScript.Echo(y.indexOf("abc", 3));
WScript.Echo(y.indexOf("abc", 2));
WScript.Echo(y.indexOf("abc", -2));
WScript.Echo(y.indexOf("efg"));
WScript.Echo(y.indexOf("efg", 6));
WScript.Echo(y.indexOf("efg", 1));
WScript.Echo(y.indexOf("efg", -3));
WScript.Echo(y.indexOf("xyg"));
WScript.Echo(y.indexOf("esg", 2));
WScript.Echo(y.indexOf("eag", 2));
WScript.Echo(y.indexOf("", -2));
WScript.Echo(y.indexOf(true));
WScript.Echo(y.indexOf(false));
WScript.Echo(y.indexOf(new Boolean(true)));
WScript.Echo(y.indexOf(a , 6));
WScript.Echo(y.indexOf(a , 1));
WScript.Echo(y.indexOf(a ));
WScript.Echo(y.indexOf(b));
WScript.Echo(y.indexOf(null));
WScript.Echo(y.indexOf());
//implicit calls
var a ;
var arr = [10];
Object.defineProperty(Array.prototype, "4", {configurable : true, get: function(){a = true; return 30;}});
a = false;
arr.length = 6;
var f = arr.indexOf(30);
WScript.Echo(a);
//Float array with gaps
var floatArray = new Array(5.5, 5.6);
floatArray[6] = 5.6;
WScript.Echo(floatArray.indexOf(5.7));
// Cases where we do/don't have to resume after failing to find the value in the head segment.
// Run with -forcearraybtree to really stress these.
var gap = [0, 1];
WScript.Echo(gap.indexOf(4));
Array.prototype[2] = 'foo';
WScript.Echo(gap.indexOf('foo'));
gap[5] = 4;
WScript.Echo(gap.indexOf('foo'));
WScript.Echo(gap.indexOf(4));
gap = [0, 1.1];
WScript.Echo(gap.indexOf(4));
Array.prototype[2] = 'bar';
WScript.Echo(gap.indexOf('bar'));
gap[5] = 4;
WScript.Echo(gap.indexOf(4));
WScript.Echo(gap.indexOf('bar'));
gap = [0, 'test'];
WScript.Echo(gap.indexOf(4));
Array.prototype[2] = 4;
WScript.Echo(gap.indexOf(4));
gap[5] = 4;
WScript.Echo(gap.indexOf(4));
delete Array.prototype[2]
WScript.Echo(gap.indexOf(4));
var undefinedValues = [];
undefinedValues[9] = "abc";
undefinedValues[10] = undefined;
WScript.Echo(undefinedValues.indexOf(undefined));
undefinedValues.length = 8;
WScript.Echo(undefinedValues.indexOf(undefined));
WScript.Echo(Array.prototype.indexOf.prototype === undefined);
WScript.Echo("prototype" in Array.prototype.indexOf)