Use dynamic dispatch in mozjs::panic::wrap_panic

Pick up https://github.com/servo/rust-mozjs/pull/512

Fixes https://github.com/servo/servo/issues/26585

This diff is best viewed with "ignore whitespace changes", because of indentation change.
This commit is contained in:
Simon Sapin 2020-05-25 20:29:18 +02:00
parent 6114b75403
commit d103e06ba9
3 changed files with 105 additions and 102 deletions

2
Cargo.lock generated
View file

@ -3572,7 +3572,7 @@ dependencies = [
[[package]]
name = "mozjs"
version = "0.13.0"
source = "git+https://github.com/servo/rust-mozjs#11cabdef2cbf0884a2cc33e3c73719646bd31ce5"
source = "git+https://github.com/servo/rust-mozjs#dbb9bee06e0b0168ccae0619c5077e302669d2fb"
dependencies = [
"cc",
"lazy_static",

View file

@ -2573,9 +2573,19 @@ class CGAbstractMethod(CGThing):
body = self.definition_body()
if self.catchPanic:
body = CGWrapper(CGIndenter(body),
pre="return wrap_panic(panic::AssertUnwindSafe(|| {\n",
post=("""\n}), %s);""" % ("()" if self.returnType == "void" else "false")))
if self.returnType == "void":
pre = "wrap_panic(&mut || {\n"
post = "\n})"
else:
pre = (
"let mut result = false;\n"
"wrap_panic(&mut || result = (|| {\n"
)
post = (
"\n})());\n"
"return result"
)
body = CGWrapper(CGIndenter(body), pre=pre, post=post)
return CGWrapper(CGIndenter(body),
pre=self.definition_prologue(),

View file

@ -81,7 +81,6 @@ use std::io::{stdout, Write};
use std::ops::Deref;
use std::os;
use std::os::raw::c_void;
use std::panic::AssertUnwindSafe;
use std::ptr;
use std::rc::Rc;
use std::sync::Mutex;
@ -169,29 +168,27 @@ pub trait ScriptPort {
#[allow(unsafe_code)]
unsafe extern "C" fn get_incumbent_global(_: *const c_void, _: *mut RawJSContext) -> *mut JSObject {
wrap_panic(
AssertUnwindSafe(|| {
let mut result = ptr::null_mut();
wrap_panic(&mut || {
let incumbent_global = GlobalScope::incumbent();
assert!(incumbent_global.is_some());
incumbent_global
result = incumbent_global
.map(|g| g.reflector().get_jsobject().get())
.unwrap_or(ptr::null_mut())
}),
ptr::null_mut(),
)
});
result
}
#[allow(unsafe_code)]
unsafe extern "C" fn empty(extra: *const c_void) -> bool {
wrap_panic(
AssertUnwindSafe(|| {
let mut result = false;
wrap_panic(&mut || {
let microtask_queue = &*(extra as *const MicrotaskQueue);
microtask_queue.empty()
}),
false,
)
result = microtask_queue.empty()
});
result
}
/// SM callback for promise job resolution. Adds a promise callback to the current
@ -206,8 +203,8 @@ unsafe extern "C" fn enqueue_promise_job(
incumbent_global: HandleObject,
) -> bool {
let cx = JSContext::from_ptr(cx);
wrap_panic(
AssertUnwindSafe(|| {
let mut result = false;
wrap_panic(&mut || {
let microtask_queue = &*(extra as *const MicrotaskQueue);
let global = GlobalScope::from_object(incumbent_global.get());
let pipeline = global.pipeline_id();
@ -226,10 +223,9 @@ unsafe extern "C" fn enqueue_promise_job(
}),
cx,
);
true
}),
false,
)
result = true
});
result
}
#[allow(unsafe_code, unrooted_must_root)]
@ -248,8 +244,7 @@ unsafe extern "C" fn promise_rejection_tracker(
let in_realm_proof = AlreadyInRealm::assert_for_cx(cx);
let global = GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof));
wrap_panic(
AssertUnwindSafe(|| {
wrap_panic(&mut || {
match state {
// Step 4.
PromiseRejectionHandlingState::Unhandled => {
@ -308,9 +303,7 @@ unsafe extern "C" fn promise_rejection_tracker(
).unwrap();
},
};
}),
(),
);
})
}
#[allow(unsafe_code, unrooted_must_root)]