Skip to content

Commit a60d06a

Browse files
authored
Merge pull request #1114 from lightpanda-io/extract_js_structs_to_files
Start extract JS structs into their own files
2 parents 66f82fd + dab8012 commit a60d06a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4027
-3962
lines changed

src/app.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;
44

55
const log = @import("log.zig");
66
const Http = @import("http/Http.zig");
7-
const Platform = @import("browser/js/js.zig").Platform;
7+
const Platform = @import("browser/js/Platform.zig");
88

99
const Telemetry = @import("telemetry/telemetry.zig").Telemetry;
1010
const Notification = @import("notification.zig").Notification;

src/browser/State.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ style_sheet: ?*StyleSheet = null,
5353

5454
// for dom/document
5555
active_element: ?*parser.Element = null,
56-
adopted_style_sheets: ?js.JsObject = null,
56+
adopted_style_sheets: ?js.Object = null,
5757

5858
// for HTMLSelectElement
5959
// By default, if no option is explicitly selected, the first option should

src/browser/console/console.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,39 @@ pub const Console = struct {
2828
timers: std.StringHashMapUnmanaged(u32) = .{},
2929
counts: std.StringHashMapUnmanaged(u32) = .{},
3030

31-
pub fn _lp(values: []js.JsObject, page: *Page) !void {
31+
pub fn _lp(values: []js.Object, page: *Page) !void {
3232
if (values.len == 0) {
3333
return;
3434
}
3535
log.fatal(.console, "lightpanda", .{ .args = try serializeValues(values, page) });
3636
}
3737

38-
pub fn _log(values: []js.JsObject, page: *Page) !void {
38+
pub fn _log(values: []js.Object, page: *Page) !void {
3939
if (values.len == 0) {
4040
return;
4141
}
4242
log.info(.console, "info", .{ .args = try serializeValues(values, page) });
4343
}
4444

45-
pub fn _info(values: []js.JsObject, page: *Page) !void {
45+
pub fn _info(values: []js.Object, page: *Page) !void {
4646
return _log(values, page);
4747
}
4848

49-
pub fn _debug(values: []js.JsObject, page: *Page) !void {
49+
pub fn _debug(values: []js.Object, page: *Page) !void {
5050
if (values.len == 0) {
5151
return;
5252
}
5353
log.debug(.console, "debug", .{ .args = try serializeValues(values, page) });
5454
}
5555

56-
pub fn _warn(values: []js.JsObject, page: *Page) !void {
56+
pub fn _warn(values: []js.Object, page: *Page) !void {
5757
if (values.len == 0) {
5858
return;
5959
}
6060
log.warn(.console, "warn", .{ .args = try serializeValues(values, page) });
6161
}
6262

63-
pub fn _error(values: []js.JsObject, page: *Page) !void {
63+
pub fn _error(values: []js.Object, page: *Page) !void {
6464
if (values.len == 0) {
6565
return;
6666
}
@@ -132,7 +132,7 @@ pub const Console = struct {
132132
log.warn(.console, "timer stop", .{ .label = label, .elapsed = elapsed - kv.value });
133133
}
134134

135-
pub fn _assert(assertion: js.JsObject, values: []js.JsObject, page: *Page) !void {
135+
pub fn _assert(assertion: js.Object, values: []js.Object, page: *Page) !void {
136136
if (assertion.isTruthy()) {
137137
return;
138138
}
@@ -143,7 +143,7 @@ pub const Console = struct {
143143
log.info(.console, "assertion failed", .{ .values = serialized_values });
144144
}
145145

146-
fn serializeValues(values: []js.JsObject, page: *Page) ![]const u8 {
146+
fn serializeValues(values: []js.Object, page: *Page) ![]const u8 {
147147
if (values.len == 0) {
148148
return "";
149149
}

src/browser/crypto/crypto.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const uuidv4 = @import("../../id.zig").uuidv4;
2424
pub const Crypto = struct {
2525
_not_empty: bool = true,
2626

27-
pub fn _getRandomValues(_: *const Crypto, js_obj: js.JsObject) !js.JsObject {
27+
pub fn _getRandomValues(_: *const Crypto, js_obj: js.Object) !js.Object {
2828
var into = try js_obj.toZig(Crypto, "getRandomValues", RandomValues);
2929
const buf = into.asBuffer();
3030
if (buf.len > 65_536) {

src/browser/dom/Animation.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ const Page = @import("../page.zig").Page;
2323

2424
const Animation = @This();
2525

26-
effect: ?js.JsObject,
27-
timeline: ?js.JsObject,
26+
effect: ?js.Object,
27+
timeline: ?js.Object,
2828
ready_resolver: ?js.PromiseResolver,
2929
finished_resolver: ?js.PromiseResolver,
3030

31-
pub fn constructor(effect: ?js.JsObject, timeline: ?js.JsObject) !Animation {
31+
pub fn constructor(effect: ?js.Object, timeline: ?js.Object) !Animation {
3232
return .{
3333
.effect = if (effect) |eo| try eo.persist() else null,
3434
.timeline = if (timeline) |to| try to.persist() else null,
@@ -65,19 +65,19 @@ pub fn get_ready(self: *Animation, page: *Page) !js.Promise {
6565
return self.ready_resolver.?.promise();
6666
}
6767

68-
pub fn get_effect(self: *const Animation) ?js.JsObject {
68+
pub fn get_effect(self: *const Animation) ?js.Object {
6969
return self.effect;
7070
}
7171

72-
pub fn set_effect(self: *Animation, effect: js.JsObject) !void {
72+
pub fn set_effect(self: *Animation, effect: js.Object) !void {
7373
self.effect = try effect.persist();
7474
}
7575

76-
pub fn get_timeline(self: *const Animation) ?js.JsObject {
76+
pub fn get_timeline(self: *const Animation) ?js.Object {
7777
return self.timeline;
7878
}
7979

80-
pub fn set_timeline(self: *Animation, timeline: js.JsObject) !void {
80+
pub fn set_timeline(self: *Animation, timeline: js.Object) !void {
8181
self.timeline = try timeline.persist();
8282
}
8383

src/browser/dom/MessageChannel.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ pub const MessagePort = struct {
7474
onmessageerror_cbk: ?js.Function = null,
7575
// This is the queue of messages to dispatch to THIS MessagePort when the
7676
// MessagePort is started.
77-
queue: std.ArrayListUnmanaged(js.JsObject) = .empty,
77+
queue: std.ArrayListUnmanaged(js.Object) = .empty,
7878

7979
pub const PostMessageOption = union(enum) {
80-
transfer: js.JsObject,
80+
transfer: js.Object,
8181
options: Opts,
8282

8383
pub const Opts = struct {
84-
transfer: js.JsObject,
84+
transfer: js.Object,
8585
};
8686
};
8787

88-
pub fn _postMessage(self: *MessagePort, obj: js.JsObject, opts_: ?PostMessageOption, page: *Page) !void {
88+
pub fn _postMessage(self: *MessagePort, obj: js.Object, opts_: ?PostMessageOption, page: *Page) !void {
8989
if (self.closed) {
9090
return;
9191
}
@@ -150,7 +150,7 @@ pub const MessagePort = struct {
150150

151151
// called from our pair. If port1.postMessage("x") is called, then this
152152
// will be called on port2.
153-
fn dispatchOrQueue(self: *MessagePort, obj: js.JsObject, arena: Allocator) !void {
153+
fn dispatchOrQueue(self: *MessagePort, obj: js.Object, arena: Allocator) !void {
154154
// our pair should have checked this already
155155
std.debug.assert(self.closed == false);
156156

@@ -165,7 +165,7 @@ pub const MessagePort = struct {
165165
return self.queue.append(arena, try obj.persist());
166166
}
167167

168-
fn dispatch(self: *MessagePort, obj: js.JsObject) !void {
168+
fn dispatch(self: *MessagePort, obj: js.Object) !void {
169169
// obj is already persisted, don't use `MessageEvent.constructor`, but
170170
// go directly to `init`, which assumes persisted objects.
171171
var evt = try MessageEvent.init(.{ .data = obj });
@@ -205,12 +205,12 @@ pub const MessageEvent = struct {
205205
pub const union_make_copy = true;
206206

207207
proto: parser.Event,
208-
data: ?js.JsObject,
208+
data: ?js.Object,
209209

210210
// You would think if port1 sends to port2, the source would be port2
211211
// (which is how I read the documentation), but it appears to always be
212212
// null. It can always be set explicitly via the constructor;
213-
source: ?js.JsObject,
213+
source: ?js.Object,
214214

215215
origin: []const u8,
216216

@@ -224,8 +224,8 @@ pub const MessageEvent = struct {
224224
ports: []*MessagePort,
225225

226226
const Options = struct {
227-
data: ?js.JsObject = null,
228-
source: ?js.JsObject = null,
227+
data: ?js.Object = null,
228+
source: ?js.Object = null,
229229
origin: []const u8 = "",
230230
lastEventId: []const u8 = "",
231231
ports: []*MessagePort = &.{},
@@ -241,7 +241,7 @@ pub const MessageEvent = struct {
241241
});
242242
}
243243

244-
// This is like "constructor", but it assumes js.JsObjects have already been
244+
// This is like "constructor", but it assumes js.Objects have already been
245245
// persisted. Necessary because this `new MessageEvent()` can be called
246246
// directly from JS OR from a port.postMessage. In the latter case, data
247247
// may have already been persisted (as it might need to be queued);
@@ -261,15 +261,15 @@ pub const MessageEvent = struct {
261261
};
262262
}
263263

264-
pub fn get_data(self: *const MessageEvent) !?js.JsObject {
264+
pub fn get_data(self: *const MessageEvent) !?js.Object {
265265
return self.data;
266266
}
267267

268268
pub fn get_origin(self: *const MessageEvent) []const u8 {
269269
return self.origin;
270270
}
271271

272-
pub fn get_source(self: *const MessageEvent) ?js.JsObject {
272+
pub fn get_source(self: *const MessageEvent) ?js.Object {
273273
return self.source;
274274
}
275275

src/browser/dom/document.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub const Document = struct {
298298
return &.{};
299299
}
300300

301-
pub fn get_adoptedStyleSheets(self: *parser.Document, page: *Page) !js.JsObject {
301+
pub fn get_adoptedStyleSheets(self: *parser.Document, page: *Page) !js.Object {
302302
const state = try page.getOrCreateNodeState(@ptrCast(@alignCast(self)));
303303
if (state.adopted_style_sheets) |obj| {
304304
return obj;
@@ -309,7 +309,7 @@ pub const Document = struct {
309309
return obj;
310310
}
311311

312-
pub fn set_adoptedStyleSheets(self: *parser.Document, sheets: js.JsObject, page: *Page) !void {
312+
pub fn set_adoptedStyleSheets(self: *parser.Document, sheets: js.Object, page: *Page) !void {
313313
const state = try page.getOrCreateNodeState(@ptrCast(@alignCast(self)));
314314
state.adopted_style_sheets = try sheets.persist();
315315
}

src/browser/dom/element.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub const Element = struct {
660660
return sr;
661661
}
662662

663-
pub fn _animate(self: *parser.Element, effect: js.JsObject, opts: js.JsObject) !Animation {
663+
pub fn _animate(self: *parser.Element, effect: js.Object, opts: js.Object) !Animation {
664664
_ = self;
665665
_ = opts;
666666
return Animation.constructor(effect, null);

src/browser/dom/node_iterator.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub const NodeIterator = struct {
4545
// One of the few cases where null and undefined resolve to different default.
4646
// We need the raw JsObject so that we can probe the tri state:
4747
// null, undefined or i32.
48-
pub const WhatToShow = js.JsObject;
48+
pub const WhatToShow = js.Object;
4949

5050
pub const NodeIteratorOpts = union(enum) {
5151
function: js.Function,

src/browser/dom/nodelist.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const js = @import("../js/js.zig");
2323
const log = @import("../../log.zig");
2424
const parser = @import("../netsurf.zig");
2525

26-
2726
const NodeUnion = @import("node.zig").Union;
2827
const Node = @import("node.zig").Node;
2928

@@ -174,7 +173,7 @@ pub const NodeList = struct {
174173
}
175174

176175
// TODO entries() https://developer.mozilla.org/en-US/docs/Web/API/NodeList/entries
177-
pub fn postAttach(self: *NodeList, js_this: js.JsThis) !void {
176+
pub fn postAttach(self: *NodeList, js_this: js.This) !void {
178177
const len = self.get_length();
179178
for (0..len) |i| {
180179
const node = try self._item(@intCast(i)) orelse unreachable;

0 commit comments

Comments
 (0)