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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
usingnamespace @import("./bindings.zig");
usingnamespace @import("./shared.zig");
pub const ZigGlobalObject = extern struct {
pub const shim = Shimmer("Zig", "GlobalObject", @This());
bytes: shim.Bytes,
pub const Type = *c_void;
pub const name = "Zig::GlobalObject";
pub const include = "\"ZigGlobalObject.h\"";
pub const namespace = shim.namespace;
pub const Interface: type = NewGlobalObject(std.meta.globalOption("JSGlobalObject", type) orelse struct {});
pub fn create(vm: ?*VM, console: *c_void) *JSGlobalObject {
return shim.cppFn("create", .{ vm, console });
}
pub fn import(global: *JSGlobalObject, loader: *JSModuleLoader, specifier: *JSString, referrer: JSValue, origin: *const SourceOrigin) callconv(.C) *JSInternalPromise {
// if (comptime is_bindgen) {
// unreachable;
// }
return @call(.{ .modifier = .always_inline }, Interface.import, .{ global, loader, specifier, referrer, origin });
}
pub fn resolve(global: *JSGlobalObject, loader: *JSModuleLoader, specifier: JSValue, value: JSValue, origin: *const SourceOrigin) callconv(.C) Identifier {
if (comptime is_bindgen) {
unreachable;
}
return @call(.{ .modifier = .always_inline }, Interface.resolve, .{ global, loader, specifier, value, origin });
}
pub fn fetch(global: *JSGlobalObject, loader: *JSModuleLoader, value1: JSValue, value2: JSValue, value3: JSValue) callconv(.C) *JSInternalPromise {
if (comptime is_bindgen) {
unreachable;
}
return @call(.{ .modifier = .always_inline }, Interface.fetch, .{ global, loader, value1, value2, value3 });
}
pub fn eval(global: *JSGlobalObject, loader: *JSModuleLoader, key: JSValue, moduleRecordValue: JSValue, scriptFetcher: JSValue, awaitedValue: JSValue, resumeMode: JSValue) callconv(.C) JSValue {
if (comptime is_bindgen) {
unreachable;
}
return @call(.{ .modifier = .always_inline }, Interface.eval, .{ global, loader, key, moduleRecordValue, scriptFetcher, awaitedValue, resumeMode });
}
pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, rejection: JSPromiseRejectionOperation) callconv(.C) JSValue {
if (comptime is_bindgen) {
unreachable;
}
return @call(.{ .modifier = .always_inline }, Interface.promiseRejectionTracker, .{ global, promise, rejection });
}
pub fn reportUncaughtException(global: *JSGlobalObject, exception: *Exception) callconv(.C) JSValue {
if (comptime is_bindgen) {
unreachable;
}
return @call(.{ .modifier = .always_inline }, Interface.reportUncaughtException, .{ global, exception });
}
pub fn createImportMetaProperties(global: *JSGlobalObject, loader: *JSModuleLoader, obj: JSValue, record: *JSModuleRecord, specifier: JSValue) callconv(.C) JSValue {
if (comptime is_bindgen) {
unreachable;
}
return @call(.{ .modifier = .always_inline }, Interface.createImportMetaProperties, .{ global, loader, obj, record, specifier });
}
pub const Export = shim.exportFunctions(.{
.@"import" = import,
.@"resolve" = resolve,
.@"fetch" = fetch,
.@"eval" = eval,
.@"promiseRejectionTracker" = promiseRejectionTracker,
.@"reportUncaughtException" = reportUncaughtException,
.@"createImportMetaProperties" = createImportMetaProperties,
});
pub const Extern = [_][]const u8{"create"};
comptime {
@export(import, .{ .name = Export[0].symbol_name });
@export(resolve, .{ .name = Export[1].symbol_name });
@export(fetch, .{ .name = Export[2].symbol_name });
@export(eval, .{ .name = Export[3].symbol_name });
@export(promiseRejectionTracker, .{ .name = Export[4].symbol_name });
@export(reportUncaughtException, .{ .name = Export[5].symbol_name });
@export(createImportMetaProperties, .{ .name = Export[6].symbol_name });
}
};
pub const ZigConsoleClient = struct {
pub const shim = Shimmer("Zig", "ConsoleClient", @This());
pub const Type = *c_void;
pub const name = "Zig::ConsoleClient";
pub const include = "\"ZigConsoleClient.h\"";
pub const namespace = shim.namespace;
pub const Counter = struct {
// if it turns out a hash table is a better idea we'll do that later
pub const Entry = struct {
hash: u32,
count: u32,
pub const List = std.MultiArrayList(Entry);
};
counts: Entry.List,
allocator: *std.mem.Allocator,
};
const BufferedWriter = std.io.BufferedWriter(4096, Output.WriterType);
error_writer: BufferedWriter,
writer: BufferedWriter,
pub fn init(allocator: *std.mem.Allocator) !*ZigConsoleClient {
var console = try allocator.create(ZigConsoleClient);
console.* = ZigConsoleClient{
.error_writer = BufferedWriter{ .unbuffered_writer = Output.errorWriter() },
.writer = BufferedWriter{ .unbuffered_writer = Output.writer() },
};
return console;
}
pub fn messageWithTypeAndLevel(
console_: ZigConsoleClient.Type,
message_type: u32,
message_level: u32,
global: *JSGlobalObject,
args: *ScriptArguments,
) callconv(.C) void {
var console = zigCast(ZigConsoleClient, console_);
var i: usize = 0;
const len = args.argumentCount();
defer args.release();
var writer = console.writer;
if (len == 1) {
var str = args.getFirstArgumentAsString();
_ = writer.unbuffered_writer.write(str.slice()) catch 0;
return;
}
defer writer.flush() catch {};
while (i < len) : (i += 1) {
var str = args.argumentAt(i).toWTFString(global);
_ = writer.write(str.slice()) catch 0;
}
}
pub fn count(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn countReset(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn time(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn timeLog(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize, args: *ScriptArguments) callconv(.C) void {}
pub fn timeEnd(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn profile(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn profileEnd(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn takeHeapSnapshot(console: ZigConsoleClient.Type, global: *JSGlobalObject, chars: [*]const u8, len: usize) callconv(.C) void {}
pub fn timeStamp(console: ZigConsoleClient.Type, global: *JSGlobalObject, args: *ScriptArguments) callconv(.C) void {}
pub fn record(console: ZigConsoleClient.Type, global: *JSGlobalObject, args: *ScriptArguments) callconv(.C) void {}
pub fn recordEnd(console: ZigConsoleClient.Type, global: *JSGlobalObject, args: *ScriptArguments) callconv(.C) void {}
pub fn screenshot(console: ZigConsoleClient.Type, global: *JSGlobalObject, args: *ScriptArguments) callconv(.C) void {}
pub const Export = shim.exportFunctions(.{
.@"messageWithTypeAndLevel" = messageWithTypeAndLevel,
.@"count" = count,
.@"countReset" = countReset,
.@"time" = time,
.@"timeLog" = timeLog,
.@"timeEnd" = timeEnd,
.@"profile" = profile,
.@"profileEnd" = profileEnd,
.@"takeHeapSnapshot" = takeHeapSnapshot,
.@"timeStamp" = timeStamp,
.@"record" = record,
.@"recordEnd" = recordEnd,
.@"screenshot" = screenshot,
});
comptime {
@export(messageWithTypeAndLevel, .{
.name = Export[0].symbol_name,
});
@export(count, .{
.name = Export[1].symbol_name,
});
@export(countReset, .{
.name = Export[2].symbol_name,
});
@export(time, .{
.name = Export[3].symbol_name,
});
@export(timeLog, .{
.name = Export[4].symbol_name,
});
@export(timeEnd, .{
.name = Export[5].symbol_name,
});
@export(profile, .{
.name = Export[6].symbol_name,
});
@export(profileEnd, .{
.name = Export[7].symbol_name,
});
@export(takeHeapSnapshot, .{
.name = Export[8].symbol_name,
});
@export(timeStamp, .{
.name = Export[9].symbol_name,
});
@export(record, .{
.name = Export[10].symbol_name,
});
@export(recordEnd, .{
.name = Export[11].symbol_name,
});
@export(screenshot, .{
.name = Export[12].symbol_name,
});
}
};
|