[Filesystem] Substitute codePointAt with getCodePoint 39/124539/4
authorPawel Wasowski <p.wasowski2@partner.samsung.com>
Tue, 11 Apr 2017 13:41:15 +0000 (15:41 +0200)
committerPawel Wasowski <p.wasowski2@partner.samsung.com>
Wed, 12 Apr 2017 06:03:09 +0000 (08:03 +0200)
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 <p.wasowski2@partner.samsung.com>
Change-Id: Id1d1df587a41494934dc01f1c88e417982f9b64f

src/filesystem/js/base64.js

index d2868f3eace80b5c07f5bb57fdf56affe3cbbbc5..edd4513316535ebf855006cf4eaf5bc24bec9e9f 100755 (executable)
@@ -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);