|
| 1 | +// Copyright (C) 2023-2024 Lightpanda (Selecy SAS) |
| 2 | +// |
| 3 | +// Francis Bouvier <francis@lightpanda.io> |
| 4 | +// Pierre Tachoire <pierre@lightpanda.io> |
| 5 | +// |
| 6 | +// This program is free software: you can redistribute it and/or modify |
| 7 | +// it under the terms of the GNU Affero General Public License as |
| 8 | +// published by the Free Software Foundation, either version 3 of the |
| 9 | +// License, or (at your option) any later version. |
| 10 | +// |
| 11 | +// This program is distributed in the hope that it will be useful, |
| 12 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +// GNU Affero General Public License for more details. |
| 15 | +// |
| 16 | +// You should have received a copy of the GNU Affero General Public License |
| 17 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +const std = @import("std"); |
| 20 | + |
| 21 | +const parser = @import("netsurf"); |
| 22 | + |
| 23 | +const jsruntime = @import("jsruntime"); |
| 24 | +const Callback = jsruntime.Callback; |
| 25 | +const Case = jsruntime.test_utils.Case; |
| 26 | +const checkCases = jsruntime.test_utils.checkCases; |
| 27 | + |
| 28 | +const generate = @import("../generate.zig"); |
| 29 | + |
| 30 | +const NodeList = @import("nodelist.zig").NodeList; |
| 31 | + |
| 32 | +pub const Interfaces = generate.Tuple(.{ |
| 33 | + MutationObserver, |
| 34 | +}); |
| 35 | + |
| 36 | +// WEB IDL https://dom.spec.whatwg.org/#interface-mutationobserver |
| 37 | +pub const MutationObserver = struct { |
| 38 | + cbk: Callback, |
| 39 | + |
| 40 | + pub const mem_guarantied = true; |
| 41 | + |
| 42 | + pub const MutationObserverInit = struct { |
| 43 | + childList: bool = false, |
| 44 | + attributes: bool = false, |
| 45 | + characterData: bool = false, |
| 46 | + subtree: bool = false, |
| 47 | + attributeOldValue: bool = false, |
| 48 | + characterDataOldValue: bool = false, |
| 49 | + // TODO |
| 50 | + // attributeFilter: [][]const u8, |
| 51 | + }; |
| 52 | + |
| 53 | + pub fn constructor(cbk: Callback) !MutationObserver { |
| 54 | + return MutationObserver{ |
| 55 | + .cbk = cbk, |
| 56 | + }; |
| 57 | + } |
| 58 | + |
| 59 | + pub fn _observe( |
| 60 | + _: *MutationObserver, |
| 61 | + _: *parser.Node, |
| 62 | + _: ?MutationObserverInit, |
| 63 | + ) !void {} |
| 64 | + |
| 65 | + // TODO |
| 66 | + pub fn _disconnect(_: *MutationObserver) !void {} |
| 67 | +}; |
| 68 | + |
| 69 | +pub fn testExecFn( |
| 70 | + _: std.mem.Allocator, |
| 71 | + js_env: *jsruntime.Env, |
| 72 | +) anyerror!void { |
| 73 | + var constructor = [_]Case{ |
| 74 | + .{ .src = "new MutationObserver(() => {}).observe(document, { childList: true });", .ex = "undefined" }, |
| 75 | + }; |
| 76 | + try checkCases(js_env, &constructor); |
| 77 | +} |
0 commit comments