Correct exception on custom element re-definition

This commit is contained in:
Karl Seguin
2025-11-22 23:04:17 +08:00
parent d3c00cdd52
commit f536f16926
5 changed files with 7 additions and 12 deletions

View File

@@ -73,8 +73,8 @@ pub const JsApi = struct {
pub const empty_with_no_proto = true;
};
pub const getRandomValues = bridge.function(Crypto.getRandomValues, .{ });
pub const randomUUID = bridge.function(Crypto.randomUUID, .{ });
pub const getRandomValues = bridge.function(Crypto.getRandomValues, .{});
pub const randomUUID = bridge.function(Crypto.randomUUID, .{});
};
const testing = @import("../../testing.zig");

View File

@@ -51,7 +51,8 @@ pub fn define(self: *CustomElementRegistry, name: []const u8, constructor: js.Fu
const gop = try self._definitions.getOrPut(page.arena, name);
if (gop.found_existing) {
return error.AlreadyDefined;
// Yes, this is the correct error to return when trying to redefine a name
return error.NotSupported;
}
const owned_name = try page.dupeString(name);

View File

@@ -47,7 +47,7 @@ pub fn getName(self: *const DOMException) []const u8 {
.invalid_character_error => "InvalidCharacterError",
.syntax_error => "SyntaxError",
.not_found => "NotFoundError",
.not_supported => "NotSupported",
.not_supported => "NotSupportedError",
.hierarchy_error => "HierarchyError",
};
}

View File

@@ -53,7 +53,7 @@ var zero_rect: DOMRect = .{
pub const ObserverInit = struct {
root: ?*Element = null,
rootMargin: ?[]const u8 = null,
threshold: Threshold = .{.scalar = 0.0},
threshold: Threshold = .{ .scalar = 0.0 },
const Threshold = union(enum) {
scalar: f64,
@@ -74,12 +74,7 @@ pub fn init(callback: js.Function, options: ?ObserverInit, page: *Page) !*Inters
.array => |arr| try page.arena.dupe(f64, arr),
};
return page._factory.create(IntersectionObserver{
._callback = callback,
._root = opts.root,
._root_margin = root_margin,
._threshold = threshold
});
return page._factory.create(IntersectionObserver{ ._callback = callback, ._root = opts.root, ._root_margin = root_margin, ._threshold = threshold });
}
pub fn observe(self: *IntersectionObserver, target: *Element, page: *Page) !void {

View File

@@ -14,7 +14,6 @@ pub fn init(page: *Page) !*Headers {
});
}
pub fn append(self: *Headers, name: []const u8, value: []const u8, page: *Page) !void {
try self._list.append(page.arena, name, value);
}