Skip to content

Commit 2e9ea73

Browse files
authored
Fix assertion failure when using VSCode debugger to inspect Image proto (#1550)
GetSource and SetSource are sort of weird plain functions that require the `this` context to be an Image instance. Fixes #1534
1 parent c025143 commit 2e9ea73

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1212
### Fixed
1313
* Fix BMP issues. (#1497)
1414
* Update typings to support jpg and addPage on NodeCanvasRenderingContext2D (#1509)
15+
* Fix assertion failure when using Visual Studio Code debugger to inspect Image prototype (#1534)
1516

1617
2.6.1
1718
==================

src/Image.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ NAN_SETTER(Image::SetHeight) {
187187
*/
188188

189189
NAN_METHOD(Image::GetSource){
190+
if (!Image::constructor.Get(info.GetIsolate())->HasInstance(info.This())) {
191+
// #1534
192+
Nan::ThrowTypeError("Method Image.GetSource called on incompatible receiver");
193+
return;
194+
}
190195
Image *img = Nan::ObjectWrap::Unwrap<Image>(info.This());
191196
info.GetReturnValue().Set(Nan::New<String>(img->filename ? img->filename : "").ToLocalChecked());
192197
}
@@ -227,6 +232,11 @@ Image::clearData() {
227232
*/
228233

229234
NAN_METHOD(Image::SetSource){
235+
if (!Image::constructor.Get(info.GetIsolate())->HasInstance(info.This())) {
236+
// #1534
237+
Nan::ThrowTypeError("Method Image.SetSource called on incompatible receiver");
238+
return;
239+
}
230240
Image *img = Nan::ObjectWrap::Unwrap<Image>(info.This());
231241
cairo_status_t status = CAIRO_STATUS_READ_ERROR;
232242

0 commit comments

Comments
 (0)