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
This commit is contained in:
Karl Seguin
2026-01-15 19:25:43 +08:00
parent 72e8421099
commit 47760e00f7
2 changed files with 14 additions and 0 deletions

View File

@@ -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);
};