Bug 1582196 part 1. Stop using NS_ERROR_RANGE_ERR in createImageBitmap. r=baku

Differential Revision: https://phabricator.services.mozilla.com/D46459

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-09-19 15:35:07 +00:00
Родитель d20b4a18cb
Коммит ccc114b512
2 изменённых файлов: 31 добавлений и 22 удалений

Просмотреть файл

@ -1196,10 +1196,18 @@ already_AddRefed<Promise> ImageBitmap::Create(
return nullptr;
}
if (aCropRect.isSome() &&
(aCropRect->Width() == 0 || aCropRect->Height() == 0)) {
aRv.Throw(NS_ERROR_RANGE_ERR);
return promise.forget();
if (aCropRect.isSome()) {
if (aCropRect->Width() == 0) {
aRv.ThrowRangeError(
u"The crop rect width passed to createImageBitmap must be nonzero");
return promise.forget();
}
if (aCropRect->Height() == 0) {
aRv.ThrowRangeError(
u"The crop rect height passed to createImageBitmap must be nonzero");
return promise.forget();
}
}
RefPtr<ImageBitmap> imageBitmap;

Просмотреть файл

@ -52,7 +52,7 @@ testCases = [
description: 'createImageBitmap with <sourceType> source and sw set to 0',
promiseTestFunction:
(source, t) => {
return promise_rejects(t, new RangeError(),
return promise_rejects_js(t, RangeError,
createImageBitmap(source, 0, 0, 0, 10));
}
},
@ -60,7 +60,7 @@ testCases = [
description: 'createImageBitmap with <sourceType> source and sh set to 0',
promiseTestFunction:
(source, t) => {
return promise_rejects(t, new RangeError(),
return promise_rejects_js(t, RangeError,
createImageBitmap(source, 0, 0, 10, 0));
}
},
@ -100,88 +100,88 @@ imageSourceTypes.forEach(imageSourceType => {
});
promise_test( t => {
return promise_rejects(t, new TypeError(), createImageBitmap(undefined));
return promise_rejects_js(t, TypeError, createImageBitmap(undefined));
}, "createImageBitmap with undefined image source.");
promise_test( t => {
return promise_rejects(t, new TypeError(), createImageBitmap(null));
return promise_rejects_js(t, TypeError, createImageBitmap(null));
}, "createImageBitmap with null image source.");
promise_test( t => {
var context = document.createElement("canvas").getContext("2d");
return promise_rejects(t, new TypeError(), createImageBitmap(context));
return promise_rejects_js(t, TypeError, createImageBitmap(context));
}, "createImageBitmap with CanvasRenderingContext2D image source.");
promise_test( t => {
var context = document.createElement("canvas").getContext("webgl");
return promise_rejects(t, new TypeError(), createImageBitmap(context));
return promise_rejects_js(t, TypeError, createImageBitmap(context));
}, "createImageBitmap with WebGLRenderingContext image source.");
promise_test( t => {
var buffer = new Uint8Array();
return promise_rejects(t, new TypeError(), createImageBitmap(buffer));
return promise_rejects_js(t, TypeError, createImageBitmap(buffer));
}, "createImageBitmap with Uint8Array image source.");
promise_test( t => {
var buffer = new ArrayBuffer(8);
return promise_rejects(t, new TypeError(), createImageBitmap(buffer));
return promise_rejects_js(t, TypeError, createImageBitmap(buffer));
}, "createImageBitmap with ArrayBuffer image source.");
promise_test( t => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(new Image()));
}, "createImageBitmap with empty image source.");
promise_test( t => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(document.createElement('video')));
}, "createImageBitmap with empty video source.");
promise_test( t => {
return makeOversizedCanvas().then(canvas => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(canvas));
});
}, "createImageBitmap with an oversized canvas source.");
promise_test( t => {
return makeOversizedOffscreenCanvas().then(offscreenCanvas => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(offscreenCanvas));
});
}, "createImageBitmap with an invalid OffscreenCanvas source.");
promise_test( t => {
return makeInvalidBlob().then(blob => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(blob));
});
}, "createImageBitmap with an undecodable blob source.");
promise_test( t => {
return makeBrokenImage().then(image => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(image));
});
}, "createImageBitmap with a broken image source.");
promise_test( t => {
return makeAvailableButBrokenImage("/images/broken.png").then(image => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(image));
});
}, "createImageBitmap with an available but undecodable image source.");
promise_test( t => {
return makeAvailableButBrokenImage("/images/red-zeroheight.svg").then(image => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(image));
});
}, "createImageBitmap with an available but zero height image source.");
promise_test( t => {
return makeAvailableButBrokenImage("/images/red-zerowidth.svg").then(image => {
return promise_rejects(t, "InvalidStateError",
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(image));
});
}, "createImageBitmap with an available but zero width image source.");
@ -189,7 +189,8 @@ promise_test( t => {
promise_test( t => {
return makeImageBitmap().then(bitmap => {
bitmap.close()
return promise_rejects(t, "InvalidStateError", createImageBitmap(bitmap));
return promise_rejects_dom(t, "InvalidStateError",
createImageBitmap(bitmap));
});
}, "createImageBitmap with a closed ImageBitmap.");
</script>