diff --git a/common/Resources/ti.internal/extensions/ti/ti.blob.js b/common/Resources/ti.internal/extensions/ti/ti.blob.js index 2590c7c3077..5106a72d962 100644 --- a/common/Resources/ti.internal/extensions/ti/ti.blob.js +++ b/common/Resources/ti.internal/extensions/ti/ti.blob.js @@ -7,22 +7,10 @@ /* globals OS_IOS, OS_VERSION_MAJOR */ const buffer = Ti.createBuffer({ value: '' }); const blob = buffer.toBlob(); - -if (OS_IOS) { - blob.constructor.prototype.toString = function () { - const value = this.text; - return (value === undefined) ? '[object TiBlob]' : value; - }; - - if (OS_VERSION_MAJOR < 11) { - // This is hack to fix TIMOB-27707. Remove it after minimum target set iOS 11+ - setTimeout(function () {}, Infinity); - } -} - +const BlobPrototype = Object.getPrototypeOf(blob); // Web Blob has an arrayBuffer() method that returns a Promise // https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer -blob.constructor.prototype.arrayBuffer = function () { +BlobPrototype.arrayBuffer = function () { return new Promise((resolve, reject) => { let buf; try { @@ -33,3 +21,17 @@ blob.constructor.prototype.arrayBuffer = function () { resolve(buf); }); }; + +if (OS_IOS) { + if (OS_VERSION_MAJOR < 13) { + BlobPrototype.toString = function () { + const value = this.text; + return (value === undefined) ? '[object TiBlob]' : value; + }; + } + + if (OS_VERSION_MAJOR < 11) { + // This is hack to fix TIMOB-27707. Remove it after minimum target set iOS 11+ + setTimeout(function () {}, Infinity); + } +} diff --git a/iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m b/iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m index 12322a66c1e..49484a5b34c 100644 --- a/iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m +++ b/iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m @@ -454,7 +454,7 @@ - (NSString *)toString if (t != nil) { return t; } - return [super toString]; + return @"[object TiBlob]"; } static void jsArrayBufferFreeDeallocator(void *data, void *ctx)