script: make throw_invalid_this and throw_constructor_without_new safe (#35360)

Signed-off-by: Stephen Muss <stephenmuss@gmail.com>
This commit is contained in:
Stephen Muss 2025-02-08 00:07:50 +11:00 committed by GitHub
parent 643885e6f1
commit 3c1cce825d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 14 deletions

View file

@ -310,19 +310,19 @@ pub(crate) unsafe fn report_pending_exception(
/// Throw an exception to signal that a `JSObject` can not be converted to a
/// given DOM type.
pub(crate) unsafe fn throw_invalid_this(cx: *mut JSContext, proto_id: u16) {
debug_assert!(!JS_IsExceptionPending(cx));
pub(crate) fn throw_invalid_this(cx: SafeJSContext, proto_id: u16) {
debug_assert!(unsafe { !JS_IsExceptionPending(*cx) });
let error = format!(
"\"this\" object does not implement interface {}.",
proto_id_to_name(proto_id)
);
throw_type_error(cx, &error);
unsafe { throw_type_error(*cx, &error) };
}
pub(crate) unsafe fn throw_constructor_without_new(cx: *mut JSContext, name: &str) {
debug_assert!(!JS_IsExceptionPending(cx));
pub(crate) fn throw_constructor_without_new(cx: SafeJSContext, name: &str) {
debug_assert!(unsafe { !JS_IsExceptionPending(*cx) });
let error = format!("{} constructor: 'new' is required", name);
throw_type_error(cx, &error);
unsafe { throw_type_error(*cx, &error) };
}
impl Error {