Bug 1239300 - reject promise with null while creating imagebitmap from empty blob; r=smaug

This commit is contained in:
Kaku Kuo 2016-01-19 14:35:01 +08:00
parent d07db5d65d
commit cc780523ee
8 changed files with 49 additions and 3 deletions

View File

@ -1065,7 +1065,7 @@ private:
RefPtr<layers::Image> data = DecodeAndCropBlob(*mBlob, mCropRect);
if (NS_WARN_IF(!data)) {
mPromise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
mPromise->MaybeRejectWithNull();
return nullptr;
}
@ -1143,9 +1143,9 @@ private:
mPromise->MaybeReject(rv);
return nullptr;
}
if (NS_WARN_IF(!data)) {
mPromise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
mPromise->MaybeRejectWithNull();
return nullptr;
}

View File

@ -0,0 +1,19 @@
function testBug1239300() {
return new Promise(function(resolve, reject) {
createImageBitmap(new Blob()).then(
function() {
ok(false, "The promise should be rejected with null.");
reject();
},
function(result) {
if (result == null) {
ok(true, "The promise should be rejected with null.");
resolve();
} else {
ok(false, "The promise should be rejected with null.");
reject();
}
}
);
});
}

View File

@ -1,3 +1,5 @@
importScripts("imagebitmap_bug1239300.js");
function ok(expect, msg) {
postMessage({type: "status", status: !!expect, msg: msg});
}
@ -77,5 +79,8 @@ onmessage = function(event) {
promiseThrows(createImageBitmap(source), event.data.msg);
}
doneTask();
} else if (event.data.type == "testBug1239300") {
var promise = testBug1239300();
promise.then(doneTask, doneTask);
}
};

View File

@ -24,6 +24,7 @@ support-files =
image_transparent50.png
image_yellow.png
image_yellow75.png
imagebitmap_bug1239300.js
imagebitmap_on_worker.js
imagebitmap_structuredclone.js
imagebitmap_structuredclone_iframe.html
@ -247,13 +248,21 @@ support-files = captureStream_common.js
support-files = file_drawWindow_source.html file_drawWindow_common.js
skip-if = (buildapp == 'b2g' && toolkit != 'gonk')
[test_imagebitmap.html]
tags = imagebitmap
[test_imagebitmap_close.html]
tags = imagebitmap
[test_imagebitmap_cropping.html]
tags = imagebitmap
[test_imagebitmap_on_worker.html]
tags = imagebitmap
[test_imagebitmap_structuredclone.html]
tags = imagebitmap
[test_imagebitmap_structuredclone_iframe.html]
tags = imagebitmap
[test_imagebitmap_structuredclone_window.html]
tags = imagebitmap
[test_imagebitmap_transfer.html]
tags = imagebitmap
[test_ImageData_ctor.html]
[test_isPointInStroke.html]
[test_mozDashOffset.html]

View File

@ -11,6 +11,7 @@
<canvas id="c1" class="output" width="128" height="128"></canvas>
<canvas id="c2" width="128" height="128"></canvas>
<script src="imagebitmap_bug1239300.js"></script>
<script type="text/javascript">
SimpleTest.waitForExplicitFinish();
@ -333,6 +334,7 @@ function runTests() {
.then(testSources)
.then(testExceptions)
.then(testSecurityErrors)
.then(testBug1239300)
.then(SimpleTest.finish, function(ev) { failed(ev); SimpleTest.finish(); });
}

View File

@ -130,6 +130,9 @@ function runTests() {
xhr.send();
}
getNonImageFile("imagebitmap_on_worker.js");
// task: test bug : bug 1239300
WORKER_TASKS.tasks.push(new Task("testBug1239300"));
}
SimpleTest.waitForExplicitFinish();

View File

@ -542,6 +542,12 @@ Promise::MaybeReject(const RefPtr<MediaStreamError>& aArg) {
MaybeSomething(aArg, &Promise::MaybeReject);
}
void
Promise::MaybeRejectWithNull()
{
MaybeSomething(JS::NullHandleValue, &Promise::MaybeReject);
}
bool
Promise::PerformMicroTaskCheckpoint()
{

View File

@ -133,6 +133,8 @@ public:
void MaybeReject(const RefPtr<MediaStreamError>& aArg);
void MaybeRejectWithNull();
// DO NOT USE MaybeRejectBrokenly with in new code. Promises should be
// rejected with Error instances.
// Note: MaybeRejectBrokenly is a template so we can use it with DOMError