|
18 | 18 |
|
19 | 19 | const std = @import("std"); |
20 | 20 |
|
| 21 | +const log = @import("../../log.zig"); |
21 | 22 | const parser = @import("../netsurf.zig"); |
22 | 23 | const Page = @import("../page.zig").Page; |
23 | 24 |
|
@@ -120,9 +121,28 @@ pub const Document = struct { |
120 | 121 | return try Element.toInterface(e); |
121 | 122 | } |
122 | 123 |
|
123 | | - pub fn _createElement(self: *parser.Document, tag_name: []const u8) !ElementUnion { |
124 | | - const e = try parser.documentCreateElement(self, tag_name); |
125 | | - return try Element.toInterface(e); |
| 124 | + const CreateElementResult = union(enum) { |
| 125 | + element: ElementUnion, |
| 126 | + custom: Env.JsObject, |
| 127 | + }; |
| 128 | + |
| 129 | + pub fn _createElement(self: *parser.Document, tag_name: []const u8, page: *Page) !CreateElementResult { |
| 130 | + const custom_element = page.window.custom_elements._get(tag_name) orelse { |
| 131 | + const e = try parser.documentCreateElement(self, tag_name); |
| 132 | + return .{ .element = try Element.toInterface(e) }; |
| 133 | + }; |
| 134 | + |
| 135 | + var result: Env.Function.Result = undefined; |
| 136 | + const js_obj = custom_element.newInstance(&result) catch |err| { |
| 137 | + log.fatal(.user_script, "newInstance error", .{ |
| 138 | + .err = result.exception, |
| 139 | + .stack = result.stack, |
| 140 | + .tag_name = tag_name, |
| 141 | + .source = "createElement", |
| 142 | + }); |
| 143 | + return err; |
| 144 | + }; |
| 145 | + return .{ .custom = js_obj }; |
126 | 146 | } |
127 | 147 |
|
128 | 148 | pub fn _createElementNS(self: *parser.Document, ns: []const u8, tag_name: []const u8) !ElementUnion { |
|
0 commit comments