Merge pull request #8510 from electron/empty-image-crashes
Fix empty image crashes
This commit is contained in:
commit
640b03f7d0
2 changed files with 19 additions and 1 deletions
|
@ -238,6 +238,8 @@ v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::ToBitmap(v8::Isolate* isolate) {
|
||||
if (IsEmpty()) return node::Buffer::New(isolate, 0).ToLocalChecked();
|
||||
|
||||
const SkBitmap* bitmap = image_.ToSkBitmap();
|
||||
SkPixelRef* ref = bitmap->pixelRef();
|
||||
return node::Buffer::Copy(isolate,
|
||||
|
@ -264,6 +266,8 @@ std::string NativeImage::ToDataURL() {
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
|
||||
if (IsEmpty()) return node::Buffer::New(isolate, 0).ToLocalChecked();
|
||||
|
||||
const SkBitmap* bitmap = image_.ToSkBitmap();
|
||||
SkPixelRef* ref = bitmap->pixelRef();
|
||||
return node::Buffer::New(isolate,
|
||||
|
@ -276,6 +280,8 @@ v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
|
|||
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
#if defined(OS_MACOSX)
|
||||
if (IsEmpty()) return node::Buffer::New(isolate, 0).ToLocalChecked();
|
||||
|
||||
NSImage* ptr = image_.AsNSImage();
|
||||
return node::Buffer::Copy(
|
||||
isolate,
|
||||
|
|
|
@ -7,7 +7,19 @@ const path = require('path')
|
|||
describe('nativeImage module', () => {
|
||||
describe('createEmpty()', () => {
|
||||
it('returns an empty image', () => {
|
||||
assert(nativeImage.createEmpty().isEmpty())
|
||||
const empty = nativeImage.createEmpty()
|
||||
assert.equal(empty.isEmpty(), true)
|
||||
assert.equal(empty.getAspectRatio(), 1)
|
||||
assert.equal(empty.toDataURL(), 'data:image/png;base64,')
|
||||
assert.deepEqual(empty.getSize(), {width: 0, height: 0})
|
||||
assert.deepEqual(empty.getBitmap(), [])
|
||||
assert.deepEqual(empty.toBitmap(), [])
|
||||
assert.deepEqual(empty.toJPEG(100), [])
|
||||
assert.deepEqual(empty.toPNG(), [])
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
assert.deepEqual(empty.getNativeHandle(), [])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue