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:
Samson 2024-08-06 19:12:31 +02:00 committed by GitHub
parent 1d464a576a
commit 68f4b359c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 62 additions and 76 deletions

View file

@ -2,10 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::ptr::NonNull;
use std::rc::Rc;
use dom_struct::dom_struct;
use js::jsapi::Heap;
use js::jsapi::{Heap, JSObject};
use js::jsval::JSVal;
use js::rust::{HandleObject, HandleValue};
use servo_atoms::Atom;
@ -27,18 +28,18 @@ use crate::script_runtime::JSContext;
#[dom_struct]
pub struct PromiseRejectionEvent {
event: Event,
#[ignore_malloc_size_of = "Rc"]
promise: Rc<Promise>,
#[ignore_malloc_size_of = "Defined in rust-mozjs"]
#[ignore_malloc_size_of = "Defined in mozjs"]
promise: Heap<*mut JSObject>,
#[ignore_malloc_size_of = "Defined in mozjs"]
reason: Heap<JSVal>,
}
impl PromiseRejectionEvent {
#[allow(crown::unrooted_must_root)]
fn new_inherited(promise: Rc<Promise>) -> Self {
fn new_inherited() -> Self {
PromiseRejectionEvent {
event: Event::new_inherited(),
promise,
promise: Heap::default(),
reason: Heap::default(),
}
}
@ -51,7 +52,15 @@ impl PromiseRejectionEvent {
promise: Rc<Promise>,
reason: HandleValue,
) -> DomRoot<Self> {
Self::new_with_proto(global, None, type_, bubbles, cancelable, promise, reason)
Self::new_with_proto(
global,
None,
type_,
bubbles,
cancelable,
promise.promise_obj(),
reason,
)
}
#[allow(crown::unrooted_must_root)]
@ -61,14 +70,15 @@ impl PromiseRejectionEvent {
type_: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable,
promise: Rc<Promise>,
promise: HandleObject,
reason: HandleValue,
) -> DomRoot<Self> {
let ev = reflect_dom_object_with_proto(
Box::new(PromiseRejectionEvent::new_inherited(promise)),
Box::new(PromiseRejectionEvent::new_inherited()),
global,
proto,
);
ev.promise.set(promise.get());
{
let event = ev.upcast::<Event>();
@ -87,7 +97,6 @@ impl PromiseRejectionEvent {
init: RootedTraceableBox<PromiseRejectionEventBinding::PromiseRejectionEventInit>,
) -> Fallible<DomRoot<Self>> {
let reason = init.reason.handle();
let promise = init.promise.clone();
let bubbles = EventBubbles::from(init.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.cancelable);
@ -97,7 +106,7 @@ impl PromiseRejectionEvent {
Atom::from(type_),
bubbles,
cancelable,
promise,
init.promise.handle(),
reason,
);
Ok(event)
@ -106,8 +115,8 @@ impl PromiseRejectionEvent {
impl PromiseRejectionEventMethods for PromiseRejectionEvent {
// https://html.spec.whatwg.org/multipage/#dom-promiserejectionevent-promise
fn Promise(&self) -> Rc<Promise> {
self.promise.clone()
fn Promise(&self, _cx: JSContext) -> NonNull<JSObject> {
NonNull::new(self.promise.get()).unwrap()
}
// https://html.spec.whatwg.org/multipage/#dom-promiserejectionevent-reason