From 47760e00f75de86954ccfb88ee5b39ed20e9f2e2 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 15 Jan 2026 19:25:43 +0800 Subject: [PATCH] Reject constructor calls without new This was previously a fixed bug, but it got lost in the direct_v8 merging. https://github.com/lightpanda-io/browser/pull/1316 --- src/browser/js/bridge.zig | 9 +++++++++ src/browser/tests/events.html | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/browser/js/bridge.zig b/src/browser/js/bridge.zig index c875ad34..258e4396 100644 --- a/src/browser/js/bridge.zig +++ b/src/browser/js/bridge.zig @@ -77,6 +77,10 @@ const FunctionCallbackInfo = struct { v8.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv); return .{ .handle = rv }; } + + fn isConstructCall(self: FunctionCallbackInfo) bool { + return v8.v8__FunctionCallbackInfo__IsConstructCall(self.handle); + } }; const PropertyCallbackInfo = struct { @@ -171,6 +175,11 @@ pub const Caller = struct { }; pub fn constructor(self: *Caller, comptime T: type, func: anytype, info: 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); }; diff --git a/src/browser/tests/events.html b/src/browser/tests/events.html index a6706847..08319569 100644 --- a/src/browser/tests/events.html +++ b/src/browser/tests/events.html @@ -630,3 +630,8 @@ let bubbledEvent = new Event('bubble', {bubbles: true}); testing.expectEqual(false, bubbledEvent.isTrusted); + +