cache document.implementation for object identity

getImplementation() now returns a cached *DOMImplementation pointer
per Document, matching the getStyleSheets() pattern. This ensures
document.implementation === document.implementation holds true.

Flips dom/nodes/Document-implementation.html (1/2 → 2/2).
This commit is contained in:
egrs
2026-02-21 14:43:41 +01:00
parent eb9b706ebc
commit 5f459c0901

View File

@@ -52,6 +52,7 @@ _elements_by_id: std.StringHashMapUnmanaged(*Element) = .empty,
_removed_ids: std.StringHashMapUnmanaged(void) = .empty,
_active_element: ?*Element = null,
_style_sheets: ?*StyleSheetList = null,
_implementation: ?*DOMImplementation = null,
_write_insertion_point: ?*Node = null,
_script_created_parser: ?Parser.Streaming = null,
_adopted_style_sheets: ?js.Object.Global = null,
@@ -272,8 +273,11 @@ pub fn querySelectorAll(self: *Document, input: String, page: *Page) !*Selector.
return Selector.querySelectorAll(self.asNode(), input.str(), page);
}
pub fn getImplementation(_: *const Document) DOMImplementation {
return .{};
pub fn getImplementation(self: *Document, page: *Page) !*DOMImplementation {
if (self._implementation) |impl| return impl;
const impl = try page._factory.create(DOMImplementation{});
self._implementation = impl;
return impl;
}
pub fn createDocumentFragment(self: *Document, page: *Page) !*Node.DocumentFragment {
@@ -726,6 +730,7 @@ pub fn open(self: *Document, page: *Page) !*Document {
self._elements_by_id.clearAndFree(page.arena);
self._active_element = null;
self._style_sheets = null;
self._implementation = null;
self._ready_state = .loading;
self._script_created_parser = Parser.Streaming.init(page.arena, doc_node, page);