(str)
| 26 | let kSig_w_w = makeSig([kWasmStringRef], [kWasmStringRef]); |
| 27 | |
| 28 | function encodeWtf8(str) { |
| 29 | // String iterator coalesces surrogate pairs. |
| 30 | let out = []; |
| 31 | for (let codepoint of str) { |
| 32 | codepoint = codepoint.codePointAt(0); |
| 33 | if (codepoint <= 0x7f) { |
| 34 | out.push(codepoint); |
| 35 | } else if (codepoint <= 0x7ff) { |
| 36 | out.push(0xc0 | (codepoint >> 6)); |
| 37 | out.push(0x80 | (codepoint & 0x3f)); |
| 38 | } else if (codepoint <= 0xffff) { |
| 39 | out.push(0xe0 | (codepoint >> 12)); |
| 40 | out.push(0x80 | ((codepoint >> 6) & 0x3f)); |
| 41 | out.push(0x80 | (codepoint & 0x3f)); |
| 42 | } else if (codepoint <= 0x10ffff) { |
| 43 | out.push(0xf0 | (codepoint >> 18)); |
| 44 | out.push(0x80 | ((codepoint >> 12) & 0x3f)); |
| 45 | out.push(0x80 | ((codepoint >> 6) & 0x3f)); |
| 46 | out.push(0x80 | (codepoint & 0x3f)); |
| 47 | } else { |
| 48 | throw new Error("bad codepoint " + codepoint); |
| 49 | } |
| 50 | } |
| 51 | return out; |
| 52 | } |
| 53 | |
| 54 | // Compute the string that corresponds to the valid WTF-8 bytes from |
| 55 | // start (inclusive) to end (exclusive). |
no test coverage detected