MCPcopy Index your code
hub / github.com/nodejs/node / encodeWtf8

Function encodeWtf8

deps/v8/test/mjsunit/wasm/stringrefs-exec.js:28–52  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

26let kSig_w_w = makeSig([kWasmStringRef], [kWasmStringRef]);
27
28function 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).

Callers 3

makeWtf8TestDataSegmentFunction · 0.70
stringrefs-exec.jsFile · 0.70
checkEncodingFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected