From 624da58a842d6e8c8afa426b4b355c756471e1fd Mon Sep 17 00:00:00 2001 From: Davit Barbakadze Date: Thu, 2 Feb 2017 11:39:33 +0400 Subject: [PATCH] Image: Bring some consistency and clarification to meta update --- src/javascript/image/Image.js | 17 +++++------------ src/javascript/runtime/flash/image/Image.js | 2 +- src/javascript/runtime/html5/image/Image.js | 3 ++- .../runtime/silverlight/image/Image.js | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/javascript/image/Image.js b/src/javascript/image/Image.js index fb58f6aa..1aa63c90 100644 --- a/src/javascript/image/Image.js +++ b/src/javascript/image/Image.js @@ -573,7 +573,10 @@ define("moxie/image/Image", [ this.getRuntime().exec.call(this, 'Image', 'destroy'); this.disconnectRuntime(); } - _updateMeta.call(this, null); + if (this.meta && this.meta.thumb) { + // thumb is blob, make sure we destroy it first + this.meta.thumb.data.destroy(); + } this.unbindAll(); } }); @@ -587,15 +590,6 @@ define("moxie/image/Image", [ }, 999); - function _updateMeta(data) { - if (this.meta && this.meta.thumb) { - // thumb is blob, make sure we destroy it first - this.meta.thumb.data.destroy(); - } - this.meta = data; - } - - function _updateInfo(info) { try { if (!info) { @@ -606,14 +600,13 @@ define("moxie/image/Image", [ this.width = info.width; this.height = info.height; this.type = info.type; + this.meta = info.meta; // update file name, only if empty if (this.name === '') { this.name = info.name; } - _updateMeta.call(this, info.meta); - return true; } catch(ex) { this.trigger('error', ex.code); diff --git a/src/javascript/runtime/flash/image/Image.js b/src/javascript/runtime/flash/image/Image.js index d04dc1d3..3c7ad969 100644 --- a/src/javascript/runtime/flash/image/Image.js +++ b/src/javascript/runtime/flash/image/Image.js @@ -50,7 +50,7 @@ define("moxie/runtime/flash/image/Image", [ , info = self.shimExec.call(this, 'Image', 'getInfo') ; - if (info.meta && info.meta.thumb && !(info.meta.thumb.data instanceof Blob)) { + if (info.meta && info.meta.thumb && info.meta.thumb.data && !(self.meta.thumb.data instanceof Blob)) { info.meta.thumb.data = new Blob(self.uid, info.meta.thumb.data); } return info; diff --git a/src/javascript/runtime/html5/image/Image.js b/src/javascript/runtime/html5/image/Image.js index fd78d3f5..57c1c9de 100644 --- a/src/javascript/runtime/html5/image/Image.js +++ b/src/javascript/runtime/html5/image/Image.js @@ -77,6 +77,7 @@ define("moxie/runtime/html5/image/Image", [ _imgInfo = new ImageInfo(_binStr); } + // this stuff below is definitely having fun with itself info = { width: _getImg().width || 0, height: _getImg().height || 0, @@ -89,7 +90,7 @@ define("moxie/runtime/html5/image/Image", [ if (_preserveHeaders) { info.meta = _imgInfo && _imgInfo.meta || this.meta || {}; - // store thumbnail data as blob + // if data was taken from ImageInfo it will be a binary string, so we convert it to blob if (info.meta && info.meta.thumb && !(info.meta.thumb.data instanceof Blob)) { info.meta.thumb.data = new Blob(null, { type: 'image/jpeg', diff --git a/src/javascript/runtime/silverlight/image/Image.js b/src/javascript/runtime/silverlight/image/Image.js index 2f475803..803e0c20 100644 --- a/src/javascript/runtime/silverlight/image/Image.js +++ b/src/javascript/runtime/silverlight/image/Image.js @@ -54,7 +54,7 @@ define("moxie/runtime/silverlight/image/Image", [ }); // save thumb data as blob - if (info.meta && info.meta.thumb && !(info.meta.thumb.data instanceof Blob)) { + if (info.meta && info.meta.thumb && info.meta.thumb.data && !(self.meta.thumb.data instanceof Blob)) { info.meta.thumb.data = new Blob(self.uid, info.meta.thumb.data); } }