Skip to content

Commit e010d0b

Browse files
committed
fix unset heap_ptr
1 parent b8b3f0e commit e010d0b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/browser/html/document.zig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,22 @@ pub const HTMLDocument = struct {
211211
pub fn _elementFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, state: *SessionState) !?*parser.Element {
212212
const ix: i32 = @intFromFloat(@floor(x));
213213
const iy: i32 = @intFromFloat(@floor(y));
214-
return state.renderer.getElementAtPosition(ix, iy) orelse return null;
214+
const element = state.renderer.getElementAtPosition(ix, iy) orelse return null;
215+
// TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
216+
return element;
215217
}
216218

217-
pub fn _elementsFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, state: *SessionState) ![]*parser.Element { // empty array or optional array?
219+
pub fn _elementsFromPoint(_: *parser.DocumentHTML, x: f32, y: f32, state: *SessionState) ![]*parser.Element {
218220
const ix: i32 = @intFromFloat(@floor(x));
219221
const iy: i32 = @intFromFloat(@floor(y));
220-
const element = state.renderer.getElementAtPosition(ix, iy) orelse return &.{}; // Or should we return the window element instead of empty -> parser.documentGetDocumentElement(self);
222+
const element = state.renderer.getElementAtPosition(ix, iy) orelse return &.{};
223+
// TODO if pointer-events set to none the underlying element should be returned (parser.documentGetDocumentElement(self.document);?)
224+
221225
// We need to return either 0 or 1 item, so we cannot fix the size to [1]*parser.Element
222226
// Converting the pointer to a slice []parser.Element is not supported by our framework.
223227
// So instead we just need to allocate the pointer to create a slice of 1.
224-
const heap_ptr = try state.arena.create(@TypeOf(element));
228+
const heap_ptr = try state.call_arena.create(@TypeOf(element));
229+
heap_ptr.* = element;
225230
return heap_ptr[0..1];
226231
}
227232
};
@@ -281,10 +286,10 @@ test "Browser.HTML.Document" {
281286
try runner.testCases(&.{
282287
.{ "document.elementFromPoint(0.5, 0.5)", "null" },
283288
.{ "document.elementsFromPoint(0.5, 0.5)", "" },
284-
.{ "document.createElement('div').getClientRects()", "[object Object]" },
289+
.{ "document.createElement('div').getClientRects()", null },
285290
.{ "document.elementFromPoint(0.5, 0.5)", "[object HTMLDivElement]" },
286-
.{ "let elems = document.elementsFromPoint(0.5, 0.5)", "undefined" },
291+
.{ "let elems = document.elementsFromPoint(0.5, 0.5)", null },
287292
.{ "elems.length", "1" },
288-
.{ "elems[0]", "[object Element]" }, // TBD why is this not: HTMLDivElement?
293+
.{ "elems[0]", "[object HTMLDivElement]" },
289294
}, .{});
290295
}

0 commit comments

Comments
 (0)