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

Function decodeWtf8

deps/v8/test/mjsunit/wasm/stringrefs-exec.js:56–91  ·  view source on GitHub ↗
(wtf8, start, end)

Source from the content-addressed store, hash-verified

54// Compute the string that corresponds to the valid WTF-8 bytes from
55// start (inclusive) to end (exclusive).
56function decodeWtf8(wtf8, start, end) {
57 let result = ''
58 while (start < end) {
59 let cp;
60 let b0 = wtf8[start];
61 if ((b0 & 0xC0) == 0x80) {
62 // The precondition is that we have valid WTF-8 bytes and that
63 // start and end are codepoint boundaries. Here we make a weak
64 // assertion about that invariant, that we don't start decoding
65 // with a continuation byte.
66 throw new Error('invalid wtf8');
67 }
68 if (b0 <= 0x7F) {
69 cp = b0;
70 start += 1;
71 } else if (b0 <= 0xDF) {
72 cp = (b0 & 0x1f) << 6;
73 cp |= (wtf8[start + 1] & 0x3f);
74 start += 2;
75 } else if (b0 <= 0xEF) {
76 cp = (b0 & 0x0f) << 12;
77 cp |= (wtf8[start + 1] & 0x3f) << 6;
78 cp |= (wtf8[start + 2] & 0x3f);
79 start += 3;
80 } else {
81 cp = (b0 & 0x07) << 18;
82 cp |= (wtf8[start + 1] & 0x3f) << 12;
83 cp |= (wtf8[start + 2] & 0x3f) << 6;
84 cp |= (wtf8[start + 3] & 0x3f);
85 start += 4;
86 }
87 result += String.fromCodePoint(cp);
88 }
89 assertEquals(start, end);
90 return result;
91}
92
93// We iterate over every one of these strings and every substring of it,
94// so to keep test execution times fast on slow platforms, keep both this

Callers 1

stringrefs-exec.jsFile · 0.85

Calls 1

assertEqualsFunction · 0.50

Tested by

no test coverage detected