зеркало из https://github.com/mozilla/gecko-dev.git
Fix for bug 762657 (Fix canvas tests and drop support for fake ImageData in putImageData to comply with spec). r=Ms2ger.
This commit is contained in:
Родитель
c35972a603
Коммит
68c6e44c87
|
@ -9,22 +9,6 @@
|
|||
|
||||
#include "mozilla/dom/ImageData.h"
|
||||
|
||||
static bool
|
||||
GetPositiveInt(JSContext* cx, JSObject& obj, const char* name, uint32_t* out)
|
||||
{
|
||||
JS::Value temp;
|
||||
int32_t signedInt;
|
||||
if (!JS_GetProperty(cx, &obj, name, &temp) ||
|
||||
!JS_ValueToECMAInt32(cx, temp, &signedInt)) {
|
||||
return false;
|
||||
}
|
||||
if (signedInt <= 0) {
|
||||
return xpc_qsThrow(cx, NS_ERROR_DOM_TYPE_MISMATCH_ERR);
|
||||
}
|
||||
*out = uint32_t(signedInt);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetImageData(JSContext* cx, JS::Value& imageData,
|
||||
uint32_t* width, uint32_t* height, JS::Anchor<JSObject*>* array)
|
||||
|
@ -35,34 +19,17 @@ GetImageData(JSContext* cx, JS::Value& imageData,
|
|||
|
||||
nsIDOMImageData* domImageData;
|
||||
xpc_qsSelfRef imageDataRef;
|
||||
if (NS_SUCCEEDED(xpc_qsUnwrapArg<nsIDOMImageData>(cx, imageData,
|
||||
&domImageData,
|
||||
&imageDataRef.ptr,
|
||||
&imageData))) {
|
||||
mozilla::dom::ImageData* concreteImageData =
|
||||
static_cast<mozilla::dom::ImageData*>(domImageData);
|
||||
*width = concreteImageData->GetWidth();
|
||||
*height = concreteImageData->GetHeight();
|
||||
array->set(concreteImageData->GetDataObject());
|
||||
return true;
|
||||
nsresult rv = xpc_qsUnwrapArg<nsIDOMImageData>(cx, imageData, &domImageData,
|
||||
&imageDataRef.ptr, &imageData);
|
||||
if (NS_FAILED(rv)) {
|
||||
return xpc_qsThrow(cx, rv);
|
||||
}
|
||||
|
||||
// TODO - bug 625804: Remove support for duck-typed ImageData.
|
||||
JSObject& dataObject = imageData.toObject();
|
||||
|
||||
if (!GetPositiveInt(cx, dataObject, "width", width) ||
|
||||
!GetPositiveInt(cx, dataObject, "height", height)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::Value temp;
|
||||
if (!JS_GetProperty(cx, &dataObject, "data", &temp)) {
|
||||
return false;
|
||||
}
|
||||
if (!temp.isObject()) {
|
||||
return xpc_qsThrow(cx, NS_ERROR_DOM_TYPE_MISMATCH_ERR);
|
||||
}
|
||||
array->set(&temp.toObject());
|
||||
mozilla::dom::ImageData* concreteImageData =
|
||||
static_cast<mozilla::dom::ImageData*>(domImageData);
|
||||
*width = concreteImageData->GetWidth();
|
||||
*height = concreteImageData->GetHeight();
|
||||
array->set(concreteImageData->GetDataObject());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,18 +32,8 @@ try {
|
|||
threw = true;
|
||||
}
|
||||
|
||||
is(threw, false, "Should be able to pass in custom imagedata objects with array data");
|
||||
|
||||
threw = false;
|
||||
try {
|
||||
c.putImageData({ width: 1, height: 1, data: null }, 0, 0);
|
||||
threw = false;
|
||||
} catch(e) {
|
||||
threw = e.name;
|
||||
}
|
||||
|
||||
is(threw, "TypeMismatchError",
|
||||
"Should throw TypeMismatchError when data is not an array");
|
||||
ok(threw,
|
||||
"Should not be able to pass in custom imagedata objects with array data");
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
|
|
@ -3521,7 +3521,7 @@ var ctx = canvas.getContext('2d');
|
|||
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage(null, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -3693,23 +3693,21 @@ isPixel(ctx, 50,25, 0,255,0,255, 2);
|
|||
|
||||
function test_2d_drawImage_wrongtype() {
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
var canvas = document.getElementById('c127');
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage(undefined, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage(0, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.result == Components.results.NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL, "should throw NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage("", 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.result == Components.results.NS_ERROR_XPC_BAD_CONVERT_JS, "should throw NS_ERROR_XPC_BAD_CONVERT_JS");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
var _thrown = undefined; try {
|
||||
ctx.drawImage(document.createElement('p'), 0, 0);
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -9192,7 +9190,7 @@ var ctx = canvas.getContext('2d');
|
|||
|
||||
var _thrown = undefined; try {
|
||||
ctx.putImageData(null, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -9304,13 +9302,13 @@ var ctx = canvas.getContext('2d');
|
|||
var imgdata = { width: 1, height: 1, data: [255, 0, 0, 255] };
|
||||
var _thrown = undefined; try {
|
||||
ctx.putImageData(imgdata, 0, 0);
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
var _thrown = undefined; try {
|
||||
ctx.putImageData("cheese", 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
var _thrown = undefined; try {
|
||||
ctx.putImageData(42, 0, 0);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -15097,7 +15095,7 @@ var ctx = canvas.getContext('2d');
|
|||
|
||||
var _thrown = undefined; try {
|
||||
ctx.createPattern(null, 'repeat');
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -15116,7 +15114,7 @@ var ctx = canvas.getContext('2d');
|
|||
|
||||
var _thrown = undefined; try {
|
||||
ctx.createPattern('image_red.png', 'repeat');
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -15135,7 +15133,7 @@ var ctx = canvas.getContext('2d');
|
|||
|
||||
var _thrown = undefined; try {
|
||||
ctx.createPattern(undefined, 'repeat');
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "TypeMismatchError" && _thrown.code == DOMException.TYPE_MISMATCH_ERR, "should throw TypeMismatchError");
|
||||
} catch (e) { _thrown = e }; todo(_thrown && _thrown.name == "TypeError", "should throw TypeError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -15977,17 +15975,9 @@ function test_2d_pattern_repeat_null() {
|
|||
var canvas = document.getElementById('c494');
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
ctx.fillStyle = '#f00';
|
||||
ctx.fillRect(0, 0, 100, 50);
|
||||
var img = document.getElementById('green-1x1_2.png');
|
||||
var pattern = ctx.createPattern(img, null);
|
||||
ctx.fillStyle = pattern;
|
||||
ctx.fillRect(0, 0, 100, 50);
|
||||
|
||||
isPixel(ctx, 1,1, 0,255,0,255, 0);
|
||||
isPixel(ctx, 98,1, 0,255,0,255, 0);
|
||||
isPixel(ctx, 1,48, 0,255,0,255, 0);
|
||||
isPixel(ctx, 98,48, 0,255,0,255, 0);
|
||||
var _thrown = undefined; try {
|
||||
ctx.createPattern(canvas, null);
|
||||
} catch (e) { _thrown = e }; ok(_thrown && _thrown.name == "SyntaxError" && _thrown.code == DOMException.SYNTAX_ERR, "should throw SyntaxError");
|
||||
|
||||
|
||||
}
|
||||
|
@ -19548,6 +19538,7 @@ function test_2d_type_prototype() {
|
|||
var canvas = document.getElementById('c611');
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
var fill = window.CanvasRenderingContext2D.prototype.fill;
|
||||
ok(window.CanvasRenderingContext2D.prototype, "window.CanvasRenderingContext2D.prototype");
|
||||
ok(window.CanvasRenderingContext2D.prototype.fill, "window.CanvasRenderingContext2D.prototype.fill");
|
||||
window.CanvasRenderingContext2D.prototype = null;
|
||||
|
@ -19559,7 +19550,8 @@ ok(window.CanvasRenderingContext2D.prototype.fill === 1, "window.CanvasRendering
|
|||
delete window.CanvasRenderingContext2D.prototype.fill;
|
||||
todo(window.CanvasRenderingContext2D.prototype.fill === undefined, "window.CanvasRenderingContext2D.prototype.fill === undefined");
|
||||
|
||||
|
||||
//restore the original method to ensure that other tests can run successfully
|
||||
window.CanvasRenderingContext2D.prototype.fill = fill;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ enum CanvasMultiGetterType {
|
|||
|
||||
nsIDOMCanvasGradient createLinearGradient (in float x0, in float y0, in float x1, in float y1);
|
||||
nsIDOMCanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1);
|
||||
nsIDOMCanvasPattern createPattern(in nsIDOMHTMLElement image, in DOMString repetition);
|
||||
nsIDOMCanvasPattern createPattern(in nsIDOMHTMLElement image, [Null(Stringify)] in DOMString repetition);
|
||||
attribute float lineWidth; /* default 1 */
|
||||
attribute DOMString lineCap; /* "butt", "round", "square" (default) */
|
||||
attribute DOMString lineJoin; /* "round", "bevel", "miter" (default) */
|
||||
|
|
|
@ -39,42 +39,13 @@ function test()
|
|||
isDeeply(data1, [255, 0, 0, 128], "expected half-transparent red canvas 1");
|
||||
|
||||
// half-transparent red 10x10 square
|
||||
var imgData = {
|
||||
width : 10,
|
||||
height : 10,
|
||||
data : [
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128, 255, 0, 0, 128,
|
||||
|
||||
]
|
||||
};
|
||||
var imgData = ctx1.createImageData(10, 10);
|
||||
var rgba = [ 255, 0, 0, 128 ];
|
||||
for (i = 0; i < 50; ++i) {
|
||||
for (j = 0; j < 4; ++j) {
|
||||
imgData.data[(i * 4) + j] = rgba[j];
|
||||
}
|
||||
}
|
||||
|
||||
var canvas2 = document.getElementById("canvas2");
|
||||
var ctx2 = canvas2.getContext("2d");
|
||||
|
|
Загрузка…
Ссылка в новой задаче