Reject constructors called as function (i.e. without 'new')

Previously, `MessageEvent('')` would have been allowed, but invalid. This caused
problems as the receiver was the window. All such calls are now rejected.

Depends on https://github.com/lightpanda-io/zig-v8-fork/pull/131
This commit is contained in:
Karl Seguin
2026-01-06 16:03:37 +08:00
parent 0b221615b7
commit a1bf92c07f
2 changed files with 6 additions and 2 deletions

View File

@@ -89,6 +89,10 @@ pub const CallOpts = struct {
};
pub fn constructor(self: *Caller, comptime T: type, func: anytype, info: v8.FunctionCallbackInfo, comptime opts: CallOpts) void {
if (!info.isConstructCall()) {
self.handleError(T, @TypeOf(func), error.InvalidArgument, info, opts);
return;
}
self._constructor(func, info) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts);
};