forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyOnAccessArray_bugs.js
More file actions
153 lines (149 loc) · 4.94 KB
/
CopyOnAccessArray_bugs.js
File metadata and controls
153 lines (149 loc) · 4.94 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
//Note: see function ArraySpliceHelper of JavascriptArray.cpp
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
}
var tests = [
{
name: "Calling Array.prototype.slice()",
body: function ()
{
var a=[1,2,3,4,5];
var b=Array.prototype.slice.call(a,1,3);
assert.areEqual([2,3], b, "Incorrect result from Array.prototype.slice()");
}
},
{
name: "Calling Array.prototype.push()",
body: function ()
{
var a=[1,2];
Array.prototype.push.call(a,1);
assert.areEqual([1,2,1], a, "Incorrect result from Array.prototype.push()");
}
},
{
name: "Calling Array.isArray()",
body: function ()
{
var a=[1,2,3,4,5,6,7];
assert.areEqual(true, Array.isArray(a), "Incorrect result from Array.isArray()");
}
},
{
name: "Calling Array.prototype.unshift()",
body: function ()
{
var a=[2,1,3,4];
Array.prototype.unshift.call(a,0);
assert.areEqual([0,2,1,3,4], a, "Incorrect result from Array.prototype.unshift()");
}
},
{
name: "Calling Array.prototype.shift()",
body: function ()
{
var a=[1,2,3,4];
var c=Array.prototype.shift.call(a);
assert.areEqual([2,3,4], a, "Incorrect result from Array.prototype.shift()");
assert.areEqual(1, c, "Incorrect result from Array.prototype.shift()");
}
},
{
name: "Calling Array.prototype.entries()",
body: function ()
{
var a=[1,2,3,4];
var c=Array.prototype.entries.call(a);
for (var e of c)
{
print(e);
}
}
},
{
name: "Calling Array.prototype.keys()",
body: function ()
{
var a=[1,2,3,4];
var c=Array.prototype.keys.call(a);
for (var e of c)
{
print(e);
}
}
},
{
name: "Calling Array.prototype.reverse()",
body: function ()
{
var a=[1,2,3,4];
Array.prototype.reverse.call(a);
assert.areEqual([4,3,2,1], a, "Incorrect result from Array.prototype.reverse()");
}
},
{
name: "Calling Object.prototype.toString()",
body: function ()
{
var a=[1,2,3,4,5,6];
var c=Object.prototype.toString.call(a);
assert.areEqual("[object Array]", c, "Incorrect result from Object.prototype.toString()");
}
},
{
name: "Calling Object.prototype.hasOwnProperty()",
body: function ()
{
var a=[1,2,3,4,5,6];
var c=Object.prototype.hasOwnProperty.call(a, 1);
assert.areEqual(c, true);
}
},
{
name: "OS3713376: Accessing COA through proxy",
body: function ()
{
var p = new Proxy([0,0,0,0,0], {});
p.length = 1;
assert.areEqual('0', p.toString(), 'Setting length of an array through Proxy');
var q = new Proxy([0,0,0,0,0], {});
q[0] = 1;
assert.areEqual('1,0,0,0,0', q.toString(), 'Setting array element through Proxy');
}
},
{
name: "Reflect.defineProperty",
body: function ()
{
var b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
Reflect.defineProperty(b, "length", {value: 0});
assert.areEqual(b.length, 0, "Setting length property to 0");
}
},
{
name: "Reflect.set",
body: function ()
{
assert.isTrue(Reflect.set([1950, 1960, 1970, 1980, 1990], "0", 1), "Should be able to set property on int array");
assert.isTrue(Reflect.set([1950, 1960.1, 1970, 1980, 1990], "0", 1), "Should be able to set property on float array");
}
},
{
name: "Array.of",
body: function ()
{
var target = [1,2,3,4,5];
function constructor()
{
return target;
}
var a = Array.of.call(constructor);
assert.areEqual(a, [], "Array.of.call with custom constructor");
}
}
];
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });