{"ScriptPreparationCode":"// needed to create bytes array\r\nvar encoder = new TextEncoder();\r\n// string length, multiple of 4 - vary to get different results\r\nvar n = 8;\r\nvar arr = new Uint16Array(n);\r\nfor (let i = 0; i \u003C n; \u002B\u002Bi) {\r\n arr[i] = (Math.random() * 0x10000) | 0;\r\n}\r\nvar decoder = new TextDecoder();\r\nfunction decodeNative(arr) {\r\n return decoder.decode(arr);\r\n}\r\n\r\nfunction decoderJs(buffer) {\r\n var start = 0;\r\n var end = buffer.byteLength;\r\n\r\n if (end - start \u003C 1) {\r\n return \u0022\u0022;\r\n }\r\n\r\n var str = \u0022\u0022;\r\n for (var i = start; i \u003C end;) {\r\n var t = buffer[i\u002B\u002B];\r\n\r\n if (t \u003C= 0x7F) {\r\n str \u002B= String.fromCharCode(t);\r\n } else if (t \u003E= 0xC0 \u0026\u0026 t \u003C 0xE0) {\r\n str \u002B= String.fromCharCode((t \u0026 0x1F) \u003C\u003C 6 | buffer[i\u002B\u002B] \u0026 0x3F);\r\n } else if (t \u003E= 0xE0 \u0026\u0026 t \u003C 0xF0) {\r\n str \u002B= String.fromCharCode((t \u0026 0xF) \u003C\u003C 12 | (buffer[i\u002B\u002B] \u0026 0x3F) \u003C\u003C 6 | buffer[i\u002B\u002B] \u0026 0x3F);\r\n } else if (t \u003E= 0xF0) {\r\n var t2 = ((t \u0026 7) \u003C\u003C 18 | (buffer[i\u002B\u002B] \u0026 0x3F) \u003C\u003C 12 | (buffer[i\u002B\u002B] \u0026 0x3F) \u003C\u003C 6 | buffer[i\u002B\u002B] \u0026 0x3F) - 0x10000;\r\n str \u002B= String.fromCharCode(0xD800 \u002B (t2 \u003E\u003E 10));\r\n str \u002B= String.fromCharCode(0xDC00 \u002B (t2 \u0026 0x3FF));\r\n }\r\n }\r\n return str;\r\n}","TestCases":[{"Name":"decodeNative","Code":"decodeNative(arr)","IsDeferred":false},{"Name":"decoderJs","Code":"decoderJs(arr)","IsDeferred":false}]}