mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add exception to rejection logic in generic_call
(#32950)
* exception in JS Promise Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * EXCEPTION_TO_REJECTION on generic_call Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * PromiseRejectionEvent should handle promise as object Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * expectations Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
1d464a576a
commit
68f4b359c5
16 changed files with 62 additions and 76 deletions
|
@ -1870,13 +1870,17 @@ class MethodDefiner(PropertyDefiner):
|
|||
else:
|
||||
selfHostedName = "0 as *const libc::c_char"
|
||||
if m.get("methodInfo", True):
|
||||
if m.get("returnsPromise", False):
|
||||
exceptionToRejection = "true"
|
||||
else:
|
||||
exceptionToRejection = "false"
|
||||
identifier = m.get("nativeName", m["name"])
|
||||
# Go through an intermediate type here, because it's not
|
||||
# easy to tell whether the methodinfo is a JSJitInfo or
|
||||
# a JSTypedMethodJitInfo here. The compiler knows, though,
|
||||
# so let it do the work.
|
||||
jitinfo = "&%s_methodinfo as *const _ as *const JSJitInfo" % identifier
|
||||
accessor = "Some(generic_method)"
|
||||
accessor = f"Some(generic_method::<{exceptionToRejection}>)"
|
||||
else:
|
||||
if m.get("returnsPromise", False):
|
||||
jitinfo = "&%s_methodinfo" % m.get("nativeName", m["name"])
|
||||
|
@ -1977,10 +1981,14 @@ class AttrDefiner(PropertyDefiner):
|
|||
accessor = 'get_' + self.descriptor.internalNameFor(attr.identifier.name)
|
||||
jitinfo = "0 as *const JSJitInfo"
|
||||
else:
|
||||
if attr.hasLegacyLenientThis():
|
||||
accessor = "generic_lenient_getter"
|
||||
if attr.type.isPromise():
|
||||
exceptionToRejection = "true"
|
||||
else:
|
||||
accessor = "generic_getter"
|
||||
exceptionToRejection = "false"
|
||||
if attr.hasLegacyLenientThis():
|
||||
accessor = f"generic_lenient_getter::<{exceptionToRejection}>"
|
||||
else:
|
||||
accessor = f"generic_getter::<{exceptionToRejection}>"
|
||||
jitinfo = "&%s_getterinfo" % self.descriptor.internalNameFor(attr.identifier.name)
|
||||
|
||||
return ("JSNativeWrapper { op: Some(%(native)s), info: %(info)s }"
|
||||
|
|
|
@ -466,7 +466,7 @@ pub unsafe fn delete_property_by_id(
|
|||
JS_DeletePropertyById(cx, object, id, bp)
|
||||
}
|
||||
|
||||
unsafe fn generic_call(
|
||||
unsafe fn generic_call<const EXCEPTION_TO_REJECTION: bool>(
|
||||
cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal,
|
||||
|
@ -488,7 +488,11 @@ unsafe fn generic_call(
|
|||
let thisobj = args.thisv();
|
||||
if !thisobj.get().is_null_or_undefined() && !thisobj.get().is_object() {
|
||||
throw_invalid_this(cx, proto_id);
|
||||
return false;
|
||||
return if EXCEPTION_TO_REJECTION {
|
||||
exception_to_promise(cx, args.rval())
|
||||
} else {
|
||||
false
|
||||
};
|
||||
}
|
||||
|
||||
rooted!(in(cx) let obj = if thisobj.get().is_object() {
|
||||
|
@ -507,7 +511,11 @@ unsafe fn generic_call(
|
|||
return true;
|
||||
} else {
|
||||
throw_invalid_this(cx, proto_id);
|
||||
return false;
|
||||
return if EXCEPTION_TO_REJECTION {
|
||||
exception_to_promise(cx, args.rval())
|
||||
} else {
|
||||
false
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -522,30 +530,30 @@ unsafe fn generic_call(
|
|||
}
|
||||
|
||||
/// Generic method of IDL interface.
|
||||
pub unsafe extern "C" fn generic_method(
|
||||
pub unsafe extern "C" fn generic_method<const EXCEPTION_TO_REJECTION: bool>(
|
||||
cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal,
|
||||
) -> bool {
|
||||
generic_call(cx, argc, vp, false, CallJitMethodOp)
|
||||
generic_call::<EXCEPTION_TO_REJECTION>(cx, argc, vp, false, CallJitMethodOp)
|
||||
}
|
||||
|
||||
/// Generic getter of IDL interface.
|
||||
pub unsafe extern "C" fn generic_getter(
|
||||
pub unsafe extern "C" fn generic_getter<const EXCEPTION_TO_REJECTION: bool>(
|
||||
cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal,
|
||||
) -> bool {
|
||||
generic_call(cx, argc, vp, false, CallJitGetterOp)
|
||||
generic_call::<EXCEPTION_TO_REJECTION>(cx, argc, vp, false, CallJitGetterOp)
|
||||
}
|
||||
|
||||
/// Generic lenient getter of IDL interface.
|
||||
pub unsafe extern "C" fn generic_lenient_getter(
|
||||
pub unsafe extern "C" fn generic_lenient_getter<const EXCEPTION_TO_REJECTION: bool>(
|
||||
cx: *mut JSContext,
|
||||
argc: libc::c_uint,
|
||||
vp: *mut JSVal,
|
||||
) -> bool {
|
||||
generic_call(cx, argc, vp, true, CallJitGetterOp)
|
||||
generic_call::<EXCEPTION_TO_REJECTION>(cx, argc, vp, true, CallJitGetterOp)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn call_setter(
|
||||
|
@ -569,7 +577,7 @@ pub unsafe extern "C" fn generic_setter(
|
|||
argc: libc::c_uint,
|
||||
vp: *mut JSVal,
|
||||
) -> bool {
|
||||
generic_call(cx, argc, vp, false, call_setter)
|
||||
generic_call::<false>(cx, argc, vp, false, call_setter)
|
||||
}
|
||||
|
||||
/// Generic lenient setter of IDL interface.
|
||||
|
@ -578,7 +586,7 @@ pub unsafe extern "C" fn generic_lenient_setter(
|
|||
argc: libc::c_uint,
|
||||
vp: *mut JSVal,
|
||||
) -> bool {
|
||||
generic_call(cx, argc, vp, true, call_setter)
|
||||
generic_call::<false>(cx, argc, vp, true, call_setter)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn instance_class_has_proto_at_depth(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue