1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
interface PropertyAttribute {
enumerable?: boolean;
configurable?: boolean;
}
export type Field =
| ({ getter: string; cache?: true | string; this?: boolean } & PropertyAttribute)
| { value: string }
| ({ setter: string; this?: boolean } & PropertyAttribute)
| ({
accessor: { getter: string; setter: string };
cache?: true | string;
this?: boolean;
} & PropertyAttribute)
| ({
fn: string;
length?: number;
DOMJIT?: {
returns: string;
args?: [string, string] | [string, string, string] | [string] | [];
pure?: boolean;
};
} & PropertyAttribute)
| { internal: true };
export interface ClassDefinition {
name: string;
construct?: boolean;
call?: boolean;
finalize?: boolean;
klass: Record<string, Field>;
proto: Record<string, Field>;
values?: string[];
JSType?: string;
noConstructor?: boolean;
estimatedSize?: boolean;
hasPendingActivity?: boolean;
isEventEmitter?: boolean;
getInternalProperties?: boolean;
custom?: Record<string, CustomField>;
configurable?: boolean;
enumerable?: boolean;
structuredClone?: boolean | { transferable: boolean; tag: number };
}
export interface CustomField {
header?: string;
extraHeaderIncludes?: string[];
impl?: string;
type?: string;
}
export function define(
{
klass = {},
proto = {},
values = [],
estimatedSize = false,
call = false,
construct = false,
structuredClone = false,
...rest
} = {} as ClassDefinition,
): ClassDefinition {
return {
...rest,
call,
construct,
estimatedSize,
structuredClone,
values,
klass: Object.fromEntries(Object.entries(klass).sort(([a], [b]) => a.localeCompare(b))),
proto: Object.fromEntries(Object.entries(proto).sort(([a], [b]) => a.localeCompare(b))),
};
}
|