From: Pawel Wasowski Date: Tue, 11 Apr 2017 13:41:15 +0000 (+0200) Subject: [Filesystem] Substitute codePointAt with getCodePoint X-Git-Tag: submit/tizen_3.0/20170412.105625~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F39%2F124539%2F4;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Substitute codePointAt with getCodePoint getCodePoint() provides the functionality of String.prototype.codePointAt(), which is unsupported on some devices. [Verification] TCT Filesystem tests: the pass rate did not change. Signed-off-by: Pawel Wasowski Change-Id: Id1d1df587a41494934dc01f1c88e417982f9b64f --- diff --git a/src/filesystem/js/base64.js b/src/filesystem/js/base64.js index d2868f3e..edd45133 100755 --- a/src/filesystem/js/base64.js +++ b/src/filesystem/js/base64.js @@ -83,13 +83,30 @@ var Base64 = { return output; }, + getCodePoint: function(string, position) { + var highWord = string.charCodeAt(position); + + if ((highWord & 0xFC00) === 0xD800) { + if (position + 1 >= string.length) { + return undefined; //the string is corrupted + } + + var lowWord = string.charCodeAt(position + 1); + if ((lowWord & 0xFC00) === 0xDC00) { + return ((highWord & 0x03FF) << 10) | (lowWord & 0x03FF) + 0x10000; + } else { + return undefined; //the string is corrupted + } + } + return highWord; + }, _utf8_encode: function(str) { str = str.replace(/\r\n/g, '\n'); var utfarray = []; //TODO: use for( var c of str ) in future versions for (var offset = 0; offset < str.length; offset++) { - var code = str.codePointAt(offset); + var code = this.getCodePoint(str, offset); if (code <= 0x7F) { utfarray.push(code);