3 <script src=
"../../../resources/js-test.js"></script>
4 <script src=
"resources/webgl-test.js"></script>
7 <div id=
"description"></div>
8 <div id=
"console"></div>
12 description("Verifies that out-of-range parameters for creation, slicing and setting of WebGL arrays are caught");
14 function testConstructionWithNullBuffer(type
, name
) {
17 array
= new type(null, 0, 0);
18 testFailed("Construction of " + name
+ " with null buffer should throw exception");
20 testPassed("Construction of " + name
+ " with null buffer threw exception");
25 function testConstructionWithOutOfRangeValues(type
, name
) {
26 var buffer
= new ArrayBuffer(4);
29 array
= new type(buffer
, 4, 0x3FFFFFFF);
30 testFailed("Construction of " + name
+ " with out-of-range values should throw exception");
32 testPassed("Construction of " + name
+ " with out-of-range values threw exception");
36 function testConstructionWithNegativeOutOfRangeValues(type
, name
) {
37 var buffer
= new ArrayBuffer(4);
40 array
= new type(buffer
, 4, -2147483648);
41 testFailed("Construction of " + name
+ " with negative out-of-range values should throw exception");
43 testPassed("Construction of " + name
+ " with negative out-of-range values threw exception");
47 // These need to be global for shouldBe to see them
51 function testSubarrayWithOutOfRangeValues(type
, name
, sz
) {
52 debug("Testing subarray of " + name
);
54 var buffer
= new ArrayBuffer(32);
55 array
= new type(buffer
);
57 shouldBe("array.length", "32 / typeSize");
59 shouldBe("array.subarray(4, 0x3FFFFFFF).length", "(32 / typeSize) - 4");
60 shouldBe("array.subarray(4, -2147483648).length", "0");
62 testFailed("Subarray of " + name
+ " threw exception");
65 testFailed("Exception: " + e
);
69 function testSettingFromArrayWithOutOfRangeOffset(type
, name
) {
70 var webglArray
= new type(32);
72 for (var i
= 0; i
< 16; i
++) {
76 webglArray
.set(array
, 0x7FFFFFF8);
77 testFailed("Setting " + name
+ " from array with out-of-range offset was not caught");
79 testPassed("Setting " + name
+ " from array with out-of-range offset was caught");
83 function testSettingFromFakeArrayWithOutOfRangeLength(type
, name
) {
84 var webglArray
= new type(32);
86 array
.length
= 0x80000000;
88 webglArray
.set(array
, 8);
89 testFailed("Setting " + name
+ " from fake array with invalid length was not caught");
91 testPassed("Setting " + name
+ " from fake array with invalid length was caught");
95 function testSettingFromWebGLArrayWithOutOfRangeOffset(type
, name
) {
96 var webglArray
= new type(32);
97 var srcArray
= new type(16);
98 for (var i
= 0; i
< 16; i
++) {
102 webglArray
.set(srcArray
, 0x7FFFFFF8);
103 testFailed("Setting " + name
+ " from " + name
+ " with out-of-range offset was not caught");
105 testPassed("Setting " + name
+ " from " + name
+ " with out-of-range offset was caught");
109 var typeNames
= [ "Int8Array",
117 var typeSizes
= [ 1, 1, 2, 2, 4, 4, 4 ];
119 for (var i
= 0; i
< typeNames
.length
; i
++) {
120 var name
= typeNames
[i
];
121 var type
= window
[name
];
123 testFailed("Could not find array type " + name
);
125 testConstructionWithNullBuffer(type
, name
);
126 testConstructionWithOutOfRangeValues(type
, name
);
127 testConstructionWithNegativeOutOfRangeValues(type
, name
);
128 testSubarrayWithOutOfRangeValues(type
, name
, typeSizes
[i
]);
129 testSettingFromArrayWithOutOfRangeOffset(type
, name
);
130 testSettingFromFakeArrayWithOutOfRangeLength(type
, name
);
131 testSettingFromWebGLArrayWithOutOfRangeOffset(type
, name
);
135 buffer
= new ArrayBuffer(40);
136 ints
= new Int32Array(buffer
, 0, 10);
137 floats
= new Float32Array(buffer
, 0, 10);
138 // Plant a NaN into the buffer
140 // Read the NaN out as a float
141 shouldBeTrue("isNaN(floats[0])");