From 6991561fa2ae8f81bed1ab6d99c16dad3a596d5a Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Sun, 5 Apr 2020 23:42:15 -0600 Subject: [PATCH] Fix assertion failure when using VSCode debugger to inspect Image proto GetSource and SetSource are sort of weird plain functions that require the `this` context to be an Image instance. Fixes #1534 --- CHANGELOG.md | 1 + src/Image.cc | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a185cd64e..5e595ee2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Fixed * Fix BMP issues. (#1497) * Update typings to support jpg and addPage on NodeCanvasRenderingContext2D (#1509) +* Fix assertion failure when using Visual Studio Code debugger to inspect Image prototype (#1534) 2.6.1 ================== diff --git a/src/Image.cc b/src/Image.cc index ed5d8c7be..190e2c9e9 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -187,6 +187,11 @@ NAN_SETTER(Image::SetHeight) { */ NAN_METHOD(Image::GetSource){ + if (!Image::constructor.Get(info.GetIsolate())->HasInstance(info.This())) { + // #1534 + Nan::ThrowTypeError("Method Image.GetSource called on incompatible receiver"); + return; + } Image *img = Nan::ObjectWrap::Unwrap(info.This()); info.GetReturnValue().Set(Nan::New(img->filename ? img->filename : "").ToLocalChecked()); } @@ -227,6 +232,11 @@ Image::clearData() { */ NAN_METHOD(Image::SetSource){ + if (!Image::constructor.Get(info.GetIsolate())->HasInstance(info.This())) { + // #1534 + Nan::ThrowTypeError("Method Image.SetSource called on incompatible receiver"); + return; + } Image *img = Nan::ObjectWrap::Unwrap(info.This()); cairo_status_t status = CAIRO_STATUS_READ_ERROR;