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

@@ -51,7 +51,8 @@ pub fn define(self: *CustomElementRegistry, name: []const u8, constructor: js.Fu
const gop = try self._definitions.getOrPut(page.arena, name); const gop = try self._definitions.getOrPut(page.arena, name);
if (gop.found_existing) { 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); 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", .invalid_character_error => "InvalidCharacterError",
.syntax_error => "SyntaxError", .syntax_error => "SyntaxError",
.not_found => "NotFoundError", .not_found => "NotFoundError",
.not_supported => "NotSupported", .not_supported => "NotSupportedError",
.hierarchy_error => "HierarchyError", .hierarchy_error => "HierarchyError",
}; };
} }

View File

@@ -74,12 +74,7 @@ pub fn init(callback: js.Function, options: ?ObserverInit, page: *Page) !*Inters
.array => |arr| try page.arena.dupe(f64, arr), .array => |arr| try page.arena.dupe(f64, arr),
}; };
return page._factory.create(IntersectionObserver{ return page._factory.create(IntersectionObserver{ ._callback = callback, ._root = opts.root, ._root_margin = root_margin, ._threshold = threshold });
._callback = callback,
._root = opts.root,
._root_margin = root_margin,
._threshold = threshold
});
} }
pub fn observe(self: *IntersectionObserver, target: *Element, page: *Page) !void { 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 { pub fn append(self: *Headers, name: []const u8, value: []const u8, page: *Page) !void {
try self._list.append(page.arena, name, value); try self._list.append(page.arena, name, value);
} }