mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
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:
@@ -77,6 +77,10 @@ const FunctionCallbackInfo = struct {
|
|||||||
v8.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv);
|
v8.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv);
|
||||||
return .{ .handle = rv };
|
return .{ .handle = rv };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn isConstructCall(self: FunctionCallbackInfo) bool {
|
||||||
|
return v8.v8__FunctionCallbackInfo__IsConstructCall(self.handle);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const PropertyCallbackInfo = struct {
|
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 {
|
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._constructor(func, info) catch |err| {
|
||||||
self.handleError(T, @TypeOf(func), err, info, opts);
|
self.handleError(T, @TypeOf(func), err, info, opts);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -630,3 +630,8 @@
|
|||||||
let bubbledEvent = new Event('bubble', {bubbles: true});
|
let bubbledEvent = new Event('bubble', {bubbles: true});
|
||||||
testing.expectEqual(false, bubbledEvent.isTrusted);
|
testing.expectEqual(false, bubbledEvent.isTrusted);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id=emptyMessageEvent>
|
||||||
|
// https://github.com/lightpanda-io/browser/pull/1316
|
||||||
|
testing.expectError('TypeError', () => MessageEvent(''));
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user