| description("This test ensures that Canvas and CanvasRenderingContext2D work correctly if the rendering context outlives the canvas element"); |
| |
| function dataToArray(data) { |
| var result = new Array(data.length) |
| for (var i = 0; i < data.length; i++) |
| result[i] = data[i]; |
| return result; |
| } |
| |
| function getPixel(x, y) { |
| var data = context.getImageData(x,y,1,1); |
| if (!data) // getImageData failed, which should never happen |
| return [-1,-1,-1,-1]; |
| return dataToArray(data.data); |
| } |
| |
| function pixelShouldBe(x, y, colour) { |
| shouldBe("getPixel(" + [x, y] +")", "["+colour+"]"); |
| } |
| |
| function prepareCanvas() { |
| var context = document.createElement("canvas").getContext("2d"); |
| context.fillStyle = "green"; |
| context.fillRect(0,0,100,100); |
| return context; |
| } |
| |
| function clobberGC(count) { |
| for (var i = 0; i < 5000; ++i) |
| ({a: i*i*i*0.5+"str", b: i/Math.sqrt(i)}); |
| if (count > 0) |
| clobberGC(count-1); |
| } |
| |
| function test() { |
| context = prepareCanvas(); |
| clobberGC(40); |
| pixelShouldBe(50, 50, [0, 128, 0, 255]); |
| } |
| test(); |
| |
| var successfullyParsed = true; |