Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/browser/dom/event_target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,10 @@ test "Browser.DOM.EventTarget" {
.{ "content.dispatchEvent(new Event('he'));", null },
.{ "obj1.calls", "1" },
}, .{});

// doesn't crash on null receiver
try runner.testCases(&.{
.{ "content.addEventListener('he2', null);", null },
.{ "content.dispatchEvent(new Event('he2'));", null },
}, .{});
}
8 changes: 8 additions & 0 deletions src/runtime/js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,11 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
}

pub fn getFunction(self: JsObject, name: []const u8) !?Function {
if (self.isNullOrUndefined()) {
return null;
}
const scope = self.scope;

const js_name = v8.String.initUtf8(scope.isolate, name);

const js_value = try self.js_obj.getValue(scope.context, js_name.toName());
Expand All @@ -1409,6 +1413,10 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
}
return try scope.createFunction(js_value);
}

pub fn isNullOrUndefined(self: JsObject) bool {
return self.js_obj.toValue().isNullOrUndefined();
}
};

// This only exists so that we know whether a function wants the opaque
Expand Down