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
|
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="resources/webgl-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Verifies that out-of-range parameters for creation, slicing and setting of WebGL arrays are caught");
function testConstructionWithNullBuffer(type, name) {
var array;
try {
array = new type(null, 0, 0);
testFailed("Construction of " + name + " with null buffer should throw exception");
} catch (e) {
testPassed("Construction of " + name + " with null buffer threw exception");
}
}
function testConstructionWithOutOfRangeValues(type, name) {
var buffer = new ArrayBuffer(4);
var array;
try {
array = new type(buffer, 4, 0x3FFFFFFF);
testFailed("Construction of " + name + " with out-of-range values should throw exception");
} catch (e) {
testPassed("Construction of " + name + " with out-of-range values threw exception");
}
}
function testConstructionWithNegativeOutOfRangeValues(type, name) {
var buffer = new ArrayBuffer(4);
var array;
try {
array = new type(buffer, 4, -2147483648);
testFailed("Construction of " + name + " with negative out-of-range values should throw exception");
} catch (e) {
testPassed("Construction of " + name + " with negative out-of-range values threw exception");
}
}
// These need to be global for shouldBe to see them
var array;
var typeSize;
function testSubarrayWithOutOfRangeValues(type, name, sz) {
debug("Testing subarray of " + name);
try {
var buffer = new ArrayBuffer(32);
array = new type(buffer);
typeSize = sz;
shouldBe("array.length", "32 / typeSize");
try {
shouldBe("array.subarray(4, 0x3FFFFFFF).length", "(32 / typeSize) - 4");
shouldBe("array.subarray(4, -2147483648).length", "0");
} catch (e) {
testFailed("Subarray of " + name + " threw exception");
}
} catch (e) {
testFailed("Exception: " + e);
}
}
function testSettingFromArrayWithOutOfRangeOffset(type, name) {
var webglArray = new type(32);
var array = [];
for (var i = 0; i < 16; i++) {
array.push(i);
}
try {
webglArray.set(array, 0x7FFFFFF8);
testFailed("Setting " + name + " from array with out-of-range offset was not caught");
} catch (e) {
testPassed("Setting " + name + " from array with out-of-range offset was caught");
}
}
function testSettingFromFakeArrayWithOutOfRangeLength(type, name) {
var webglArray = new type(32);
var array = {};
array.length = 0x80000000;
try {
webglArray.set(array, 8);
testFailed("Setting " + name + " from fake array with invalid length was not caught");
} catch (e) {
testPassed("Setting " + name + " from fake array with invalid length was caught");
}
}
function testSettingFromWebGLArrayWithOutOfRangeOffset(type, name) {
var webglArray = new type(32);
var srcArray = new type(16);
for (var i = 0; i < 16; i++) {
srcArray[i] = i;
}
try {
webglArray.set(srcArray, 0x7FFFFFF8);
testFailed("Setting " + name + " from " + name + " with out-of-range offset was not caught");
} catch (e) {
testPassed("Setting " + name + " from " + name + " with out-of-range offset was caught");
}
}
var typeNames = [ "Int8Array",
"Uint8Array",
"Int16Array",
"Uint16Array",
"Int32Array",
"Uint32Array",
"Float32Array" ];
var typeSizes = [ 1, 1, 2, 2, 4, 4, 4 ];
for (var i = 0; i < typeNames.length; i++) {
var name = typeNames[i];
var type = window[name];
if (!type) {
testFailed("Could not find array type " + name);
} else {
testConstructionWithNullBuffer(type, name);
testConstructionWithOutOfRangeValues(type, name);
testConstructionWithNegativeOutOfRangeValues(type, name);
testSubarrayWithOutOfRangeValues(type, name, typeSizes[i]);
testSettingFromArrayWithOutOfRangeOffset(type, name);
testSettingFromFakeArrayWithOutOfRangeLength(type, name);
testSettingFromWebGLArrayWithOutOfRangeOffset(type, name);
}
}
buffer = new ArrayBuffer(40);
ints = new Int32Array(buffer, 0, 10);
floats = new Float32Array(buffer, 0, 10);
// Plant a NaN into the buffer
ints[0]=-0x7ffff;
// Read the NaN out as a float
shouldBeTrue("isNaN(floats[0])");
</script>
</body>
</html>
|