From: Lukasz Bardeli Date: Mon, 7 Jan 2019 10:24:28 +0000 (+0100) Subject: [Common] Fix preventing crash in argument validator X-Git-Tag: accepted/tizen/5.0/unified/20190319.115547~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F67%2F198867%2F1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Fix preventing crash in argument validator If to method which takes object as parameter, array with one element of this object will be passed them applicaiton will crash. This fix prevent such situations and will throw TypeMissmatch [Verification] Code compiles without error. Tested in chrome console and execute automatic TCT (modules which have methods taking platform object as parameter - account, alarm, application, bluetooth, bookmark, calendar, callhistory, contact, content, download, exif, filesystem, iotcon, mediacontroller, messageport, messaging, nfc, notification, push, time) 100% passrate Change-Id: Idfd9ad6f1acc0a6d5fd140dfd655d1cab7d2291a Signed-off-by: Lukasz Bardeli (cherry picked from commit faaf457e2aa1307f0c3406208374d71d5c98827b) --- diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js index 83f18c9..8550192 100644 --- a/src/utils/utils_api.js +++ b/src/utils/utils_api.js @@ -491,28 +491,25 @@ Converter.prototype.toString = function(val, nullable) { }; function _toPlatformObject(val, types) { - var v; var t; - if (_type.isArray(val)) { - v = val; - } else { - v = [val]; - } if (_type.isArray(types)) { t = types; } else { t = [types]; } + + if (_type.isArray(val)) { + throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, + 'Cannot convert ' + String(val) + ' to ' + String(t[0].name) + '.'); + } + var match = false; for (var i = 0; i < t.length; ++i) { - for (var j = 0; j < v.length; ++j) { - match = match || (v[j] instanceof t[i]); + if (val instanceof t[i]) { + return val; } } - if (match) { - return val; - } throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR, 'Cannot convert ' + String(val) + ' to ' + String(t[0].name) + '.');