Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/browser/html/DataSet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const parser = @import("../netsurf.zig");
const Env = @import("../env.zig").Env;
const Page = @import("../page.zig").Page;

const Allocator = std.mem.Allocator;
Expand All @@ -25,16 +26,12 @@ const DataSet = @This();

element: *parser.Element,

const GetResult = union(enum) {
value: []const u8,
undefined: void,
};
pub fn named_get(self: *const DataSet, name: []const u8, _: *bool, page: *Page) !GetResult {
pub fn named_get(self: *const DataSet, name: []const u8, _: *bool, page: *Page) !Env.UndefinedOr([]const u8) {
const normalized_name = try normalize(page.call_arena, name);
if (try parser.elementGetAttribute(self.element, normalized_name)) |value| {
return .{ .value = value };
}
return .{ .undefined = {} };
return .undefined;
}

pub fn named_set(self: *DataSet, name: []const u8, value: []const u8, _: *bool, page: *Page) !void {
Expand Down
10 changes: 3 additions & 7 deletions src/browser/html/error_event.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ pub const ErrorEvent = struct {
return self.colno;
}

const ErrorValue = union(enum) {
obj: Env.JsObject,
undefined: void,
};
pub fn get_error(self: *const ErrorEvent) ErrorValue {
pub fn get_error(self: *const ErrorEvent) Env.UndefinedOr(Env.JsObject) {
if (self.@"error") |e| {
return .{ .obj = e };
return .{ .value = e };
}
return .{ .undefined = {} };
return .undefined;
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/runtime/js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,13 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
}
};

pub fn UndefinedOr(comptime T: type) type {
return union(enum) {
undefined: void,
value: T,
};
}

fn compileModule(isolate: v8.Isolate, src: []const u8, name: []const u8) !v8.Module {
// compile
const script_name = v8.String.initUtf8(isolate, name);
Expand Down