mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
add support for CustomEvent#initCustomEvent
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
const parser = @import("../netsurf.zig");
|
||||
const Event = @import("event.zig").Event;
|
||||
const JsObject = @import("../env.zig").JsObject;
|
||||
const netsurf = @import("../netsurf.zig");
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-customevent
|
||||
pub const CustomEvent = struct {
|
||||
@@ -55,6 +56,25 @@ pub const CustomEvent = struct {
|
||||
pub fn get_detail(self: *CustomEvent) ?JsObject {
|
||||
return self.detail;
|
||||
}
|
||||
|
||||
// Initializes an already created `CustomEvent`.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/initCustomEvent
|
||||
pub fn _initCustomEvent(
|
||||
self: *CustomEvent,
|
||||
event_type: []const u8,
|
||||
can_bubble: bool,
|
||||
cancelable: bool,
|
||||
detail: ?JsObject,
|
||||
) !void {
|
||||
// This function can only be called after the constructor has called.
|
||||
// So we assume proto is initialized already by constructor.
|
||||
self.proto.type = try netsurf.strFromData(event_type);
|
||||
self.proto.bubble = can_bubble;
|
||||
self.proto.cancelable = cancelable;
|
||||
self.proto.is_initialised = true;
|
||||
// Detail is stored separately.
|
||||
self.detail = detail;
|
||||
}
|
||||
};
|
||||
|
||||
const testing = @import("../../testing.zig");
|
||||
|
||||
@@ -106,7 +106,7 @@ inline fn strToData(s: *String) []const u8 {
|
||||
return data[0..c.dom_string_byte_length(s)];
|
||||
}
|
||||
|
||||
inline fn strFromData(data: []const u8) !*String {
|
||||
pub inline fn strFromData(data: []const u8) !*String {
|
||||
var s: ?*String = null;
|
||||
const err = c.dom_string_create(data.ptr, data.len, &s);
|
||||
try DOMErr(err);
|
||||
|
||||
Reference in New Issue
Block a user