@tlockney/cdp-kernel 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/browser/channels.d.ts +27 -0
- package/dist/browser/channels.js +90 -0
- package/dist/browser/kernel.js +29674 -0
- package/dist/browser/kernel.js.map +7 -0
- package/dist/browser/mod.d.ts +20 -0
- package/dist/browser/mod.js +38 -0
- package/dist/browser/target.d.ts +71 -0
- package/dist/browser/target.js +206 -0
- package/dist/browser/worker.js +1000 -0
- package/dist/browser/worker.js.map +7 -0
- package/dist/cdp.d.ts +9 -0
- package/dist/debugger.d.ts +2 -0
- package/dist/debugger.js +12 -6
- package/dist/kernel-core.d.ts +69 -0
- package/dist/kernel-core.js +754 -0
- package/dist/kernel.d.ts +6 -1
- package/dist/kernel.js +92 -723
- package/dist/message.d.ts +34 -0
- package/dist/message.js +14 -0
- package/dist/package.d.ts +2 -2
- package/dist/package.js +2 -2
- package/dist/target-api.d.ts +80 -0
- package/dist/target-api.js +22 -0
- package/dist/target.d.ts +4 -76
- package/dist/target.js +39 -22
- package/dist/traceback.d.ts +75 -0
- package/dist/traceback.js +200 -0
- package/dist/transform.d.ts +1 -0
- package/dist/transform.js +8 -1
- package/dist/wire.d.ts +4 -24
- package/dist/wire.js +3 -12
- package/dist/zmq-channels.d.ts +14 -0
- package/dist/zmq-channels.js +59 -0
- package/package.json +7 -2
- package/runtime/browser-worker.mjs +119 -0
- package/runtime/cdn.d.mts +2 -0
- package/runtime/cdn.mjs +17 -0
- package/runtime/display.mjs +202 -1
- package/runtime/format.d.mts +2 -0
- package/runtime/format.mjs +125 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// A small stand-in for util.inspect and util.format, for targets that have
|
|
2
|
+
// neither: the browser Worker (runtime/browser-worker.mjs). Output follows
|
|
3
|
+
// Node's for the common cases (strings quoted when nested, objects and
|
|
4
|
+
// arrays on one line, Map, Set, Date, Error, class names, circular
|
|
5
|
+
// references), without colours.
|
|
6
|
+
//
|
|
7
|
+
// No imports: this file must load in every target.
|
|
8
|
+
|
|
9
|
+
const MAX_ITEMS = 100;
|
|
10
|
+
|
|
11
|
+
// Single quotes, unless the string has some and double quotes or
|
|
12
|
+
// backticks would need no escapes, as util.inspect picks.
|
|
13
|
+
function quote(s) {
|
|
14
|
+
const q = !s.includes("'") ? "'" : !s.includes('"') ? '"' : !s.includes("`") && !s.includes("${") ? "`" : "'";
|
|
15
|
+
const escaped = s.replaceAll("\\", "\\\\").replaceAll("\n", "\\n").replaceAll(q, `\\${q}`);
|
|
16
|
+
return `${q}${escaped}${q}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function key(k) {
|
|
20
|
+
return typeof k === "symbol" ? `[${k.toString()}]` : /^[A-Za-z_$][\w$]*$/.test(k) ? k : quote(k);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function className(value) {
|
|
24
|
+
const proto = Object.getPrototypeOf(value);
|
|
25
|
+
if (proto === null) return "[Object: null prototype]";
|
|
26
|
+
const name = proto.constructor?.name;
|
|
27
|
+
return name && name !== "Object" ? name : "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function list(open, items, close, more) {
|
|
31
|
+
if (more > 0) items.push(`... ${more} more item${more === 1 ? "" : "s"}`);
|
|
32
|
+
return items.length === 0 ? `${open}${close}` : `${open} ${items.join(", ")} ${close}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** `value` as Node's util.inspect would show it, to `depth` levels. */
|
|
36
|
+
export function inspect(value, { depth = 2 } = {}) {
|
|
37
|
+
const seen = [];
|
|
38
|
+
const show = (v, level) => {
|
|
39
|
+
switch (typeof v) {
|
|
40
|
+
case "string":
|
|
41
|
+
return quote(v);
|
|
42
|
+
case "bigint":
|
|
43
|
+
return `${v}n`;
|
|
44
|
+
case "symbol":
|
|
45
|
+
return v.toString();
|
|
46
|
+
case "undefined":
|
|
47
|
+
return "undefined";
|
|
48
|
+
case "function": {
|
|
49
|
+
const isClass = /^class\b/.test(Function.prototype.toString.call(v));
|
|
50
|
+
return isClass ? `[class ${v.name || "(anonymous)"}]` : `[Function${v.name ? `: ${v.name}` : " (anonymous)"}]`;
|
|
51
|
+
}
|
|
52
|
+
case "number":
|
|
53
|
+
return Object.is(v, -0) ? "-0" : String(v);
|
|
54
|
+
case "boolean":
|
|
55
|
+
return String(v);
|
|
56
|
+
}
|
|
57
|
+
if (v === null) return "null";
|
|
58
|
+
if (seen.includes(v)) return "[Circular *1]";
|
|
59
|
+
if (v instanceof Date) return Number.isNaN(v.getTime()) ? "Invalid Date" : v.toISOString();
|
|
60
|
+
if (v instanceof RegExp) return String(v);
|
|
61
|
+
if (v instanceof Error) return v.stack ?? `${v.name}: ${v.message}`;
|
|
62
|
+
if (v instanceof Promise) return "Promise { <unknown> }";
|
|
63
|
+
if (level > depth) return Array.isArray(v) ? "[Array]" : `[${className(v) || "Object"}]`;
|
|
64
|
+
seen.push(v);
|
|
65
|
+
try {
|
|
66
|
+
if (Array.isArray(v) || ArrayBuffer.isView(v)) {
|
|
67
|
+
const items = Array.from(v).slice(0, MAX_ITEMS).map((x) => show(x, level + 1));
|
|
68
|
+
const prefix = Array.isArray(v) ? "" : `${v.constructor.name}(${v.length}) `;
|
|
69
|
+
return prefix + list("[", items, "]", v.length - items.length);
|
|
70
|
+
}
|
|
71
|
+
if (v instanceof Map) {
|
|
72
|
+
const items = [...v].slice(0, MAX_ITEMS).map(([k, x]) => `${show(k, level + 1)} => ${show(x, level + 1)}`);
|
|
73
|
+
return `Map(${v.size}) ` + list("{", items, "}", v.size - items.length);
|
|
74
|
+
}
|
|
75
|
+
if (v instanceof Set) {
|
|
76
|
+
const items = [...v].slice(0, MAX_ITEMS).map((x) => show(x, level + 1));
|
|
77
|
+
return `Set(${v.size}) ` + list("{", items, "}", v.size - items.length);
|
|
78
|
+
}
|
|
79
|
+
const keys = Reflect.ownKeys(v).filter((k) => Object.getOwnPropertyDescriptor(v, k)?.enumerable);
|
|
80
|
+
const items = keys.slice(0, MAX_ITEMS).map((k) => {
|
|
81
|
+
const d = Object.getOwnPropertyDescriptor(v, k);
|
|
82
|
+
const shown = d.get || d.set ? `[${d.get ? "Getter" : ""}${d.get && d.set ? "/" : ""}${d.set ? "Setter" : ""}]` : show(d.value, level + 1);
|
|
83
|
+
return `${key(k)}: ${shown}`;
|
|
84
|
+
});
|
|
85
|
+
const name = className(v);
|
|
86
|
+
return (name ? `${name} ` : "") + list("{", items, "}", keys.length - items.length);
|
|
87
|
+
} finally {
|
|
88
|
+
seen.pop();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return show(value, 0);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** console.log's formatting: strings as they are, everything else inspected, %s/%d/%i/%f/%o/%O/%j substituted. */
|
|
95
|
+
export function format(...args) {
|
|
96
|
+
let out = [];
|
|
97
|
+
let rest = args;
|
|
98
|
+
if (typeof args[0] === "string" && args.length > 1 && args[0].includes("%")) {
|
|
99
|
+
let i = 1;
|
|
100
|
+
const text = args[0].replace(/%[sdifoOjc%]/g, (spec) => {
|
|
101
|
+
if (spec === "%%") return "%";
|
|
102
|
+
if (i >= args.length) return spec;
|
|
103
|
+
const a = args[i++];
|
|
104
|
+
switch (spec) {
|
|
105
|
+
case "%s":
|
|
106
|
+
return typeof a === "string" ? a : inspect(a, { depth: 1 });
|
|
107
|
+
case "%d":
|
|
108
|
+
case "%i":
|
|
109
|
+
return typeof a === "bigint" ? `${a}n` : String(spec === "%i" ? Math.trunc(Number(a)) : Number(a));
|
|
110
|
+
case "%f":
|
|
111
|
+
return String(Number(a));
|
|
112
|
+
case "%j":
|
|
113
|
+
return JSON.stringify(a);
|
|
114
|
+
case "%c":
|
|
115
|
+
return "";
|
|
116
|
+
default:
|
|
117
|
+
return inspect(a, { depth: 4 });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
out = [text];
|
|
121
|
+
rest = args.slice(i);
|
|
122
|
+
}
|
|
123
|
+
for (const a of rest) out.push(typeof a === "string" ? a : inspect(a));
|
|
124
|
+
return out.join(" ");
|
|
125
|
+
}
|