mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
dom: first draft for MutationObserver
This commit is contained in:
@@ -25,6 +25,7 @@ const NamedNodeMap = @import("namednodemap.zig").NamedNodeMap;
|
||||
const DOMTokenList = @import("token_list.zig").DOMTokenList;
|
||||
const NodeList = @import("nodelist.zig").NodeList;
|
||||
const Nod = @import("node.zig");
|
||||
const MutationObserver = @import("mutation_observer.zig");
|
||||
|
||||
pub const Interfaces = generate.Tuple(.{
|
||||
DOMException,
|
||||
@@ -35,4 +36,5 @@ pub const Interfaces = generate.Tuple(.{
|
||||
NodeList,
|
||||
Nod.Node,
|
||||
Nod.Interfaces,
|
||||
MutationObserver.Interfaces,
|
||||
});
|
||||
|
||||
77
src/dom/mutation_observer.zig
Normal file
77
src/dom/mutation_observer.zig
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright (C) 2023-2024 Lightpanda (Selecy SAS)
|
||||
//
|
||||
// Francis Bouvier <francis@lightpanda.io>
|
||||
// Pierre Tachoire <pierre@lightpanda.io>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const parser = @import("netsurf");
|
||||
|
||||
const jsruntime = @import("jsruntime");
|
||||
const Callback = jsruntime.Callback;
|
||||
const Case = jsruntime.test_utils.Case;
|
||||
const checkCases = jsruntime.test_utils.checkCases;
|
||||
|
||||
const generate = @import("../generate.zig");
|
||||
|
||||
const NodeList = @import("nodelist.zig").NodeList;
|
||||
|
||||
pub const Interfaces = generate.Tuple(.{
|
||||
MutationObserver,
|
||||
});
|
||||
|
||||
// WEB IDL https://dom.spec.whatwg.org/#interface-mutationobserver
|
||||
pub const MutationObserver = struct {
|
||||
cbk: Callback,
|
||||
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub const MutationObserverInit = struct {
|
||||
childList: bool = false,
|
||||
attributes: bool = false,
|
||||
characterData: bool = false,
|
||||
subtree: bool = false,
|
||||
attributeOldValue: bool = false,
|
||||
characterDataOldValue: bool = false,
|
||||
// TODO
|
||||
// attributeFilter: [][]const u8,
|
||||
};
|
||||
|
||||
pub fn constructor(cbk: Callback) !MutationObserver {
|
||||
return MutationObserver{
|
||||
.cbk = cbk,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn _observe(
|
||||
_: *MutationObserver,
|
||||
_: *parser.Node,
|
||||
_: ?MutationObserverInit,
|
||||
) !void {}
|
||||
|
||||
// TODO
|
||||
pub fn _disconnect(_: *MutationObserver) !void {}
|
||||
};
|
||||
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
) anyerror!void {
|
||||
var constructor = [_]Case{
|
||||
.{ .src = "new MutationObserver(() => {}).observe(document, { childList: true });", .ex = "undefined" },
|
||||
};
|
||||
try checkCases(js_env, &constructor);
|
||||
}
|
||||
@@ -55,6 +55,7 @@ const ProgressEventTestExecFn = @import("xhr/progress_event.zig").testExecFn;
|
||||
const StorageTestExecFn = storage.testExecFn;
|
||||
const URLTestExecFn = url.testExecFn;
|
||||
const HTMLElementTestExecFn = @import("html/elements.zig").testExecFn;
|
||||
const MutationObserverTestExecFn = @import("dom/mutation_observer.zig").testExecFn;
|
||||
|
||||
pub const Types = jsruntime.reflect(apiweb.Interfaces);
|
||||
pub const UserContext = @import("user_context.zig").UserContext;
|
||||
@@ -133,6 +134,7 @@ fn testsAllExecFn(
|
||||
StorageTestExecFn,
|
||||
URLTestExecFn,
|
||||
HTMLElementTestExecFn,
|
||||
MutationObserverTestExecFn,
|
||||
};
|
||||
|
||||
inline for (testFns) |testFn| {
|
||||
|
||||
Reference in New Issue
Block a user