Debian Codegraph @

debian/tests/test_modules/llparse-test-fixture/src/binding.js

raw symbols SCIP
1 import { format } from 'util';
2
3 export default (binding, inBench) => {
4 // Just a random value, really
5 binding.LLPARSE__ERROR_PAUSE = 0x7fa73caa;
6
7 let globalOff = 0;
8 binding.setGlobalOff = (value) => globalOff = value;
9
10 const translate = (off) => off + globalOff;
11
12 const nop = () => 0;
13 binding.llparse__print = inBench ? nop : (off, fmt, ...params) => {
14 const parts = [
15 format('off=%d', translate(off)),
16 format(fmt, ...params),
17 ];
18 console.log(parts.join(' ').trim());
19 return 0;
20 };
21
22 binding.llparse__print_span = inBench ? nop : (name, buf, off, end) => {
23 let last = off;
24
25 const printRegular = (current) => {
26 if (last !== current) {
27 binding.llparse__print(last, 'len=%d span[%s]="%s"',
28 current - last, name, buf.slice(last, current).toString());
29 }
30 };
31
32 // Empty span
33 if (off === end) {
34 binding.llparse__print(off, 'len=0 span[%s]=""', name);
35 return 0;
36 }
37
38 for (let i = off; i < end; i++) {
39 const ch = buf[i];
40
41 if (ch === 0xd) {
42 printRegular(i);
43
44 binding.llparse__print(i, 'len=1 span[%s]=cr', name);
45 last = i + 1;
46 continue;
47
48 // LF
49 } else if (ch === 0xa) {
50 printRegular(i);
51
52 binding.llparse__print(i, 'len=1 span[%s]=lf', name);
53 last = i + 1;
54 continue;
55 }
56
57 // Nothing to do here
58 }
59
60 // Trailing data
61 printRegular(end);
62
63 return 0;
64 };
65
66 binding.debug = inBench ? nop : (_, buf, off, msg) => {
67 if (off === buf.length) {
68 // tslint:disable-next-line:no-console
69 console.error(format('off=%d next=null debug=%s', translate(off), msg));
70 } else {
71 let next = buf[off + 1].toString(16);
72 if (next.length < 2) {
73 next = '0' + next;
74 }
75 // tslint:disable-next-line:no-console
76 console.error(format('off=%d next=%s debug=%s', translate(off),
77 next, msg));
78 }
79 };
80 };