use core::ffi::c_void;
use std::collections::{HashMap, HashSet};
use std::sync::{Mutex, OnceLock, RwLock};
use super::events;
use super::util::*;
use crate::glue;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum Capability {
Microphone,
Camera,
DisplayCapture,
Notifications,
ClipboardRead,
ClipboardWrite,
Geolocation,
}
impl Capability {
pub const ALL: &'static [Capability] = &[
Capability::Microphone,
Capability::Camera,
Capability::DisplayCapture,
Capability::Notifications,
Capability::ClipboardRead,
Capability::ClipboardWrite,
Capability::Geolocation,
];
pub fn web_name(self) -> &'static str {
match self {
Capability::Microphone => "microphone",
Capability::Camera => "camera",
Capability::DisplayCapture => "display-capture",
Capability::Notifications => "notifications",
Capability::ClipboardRead => "clipboard-read",
Capability::ClipboardWrite => "clipboard-write",
Capability::Geolocation => "geolocation",
}
}
pub fn from_web_name(name: &str) -> Option<Capability> {
Capability::ALL.iter().copied().find(|c| c.web_name() == name)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum PermissionState {
Granted,
Denied,
Prompt,
Unsupported,
}
impl PermissionState {
pub fn web_state(self) -> &'static str {
match self {
PermissionState::Granted => "granted",
PermissionState::Prompt => "prompt",
PermissionState::Denied | PermissionState::Unsupported => "denied",
}
}
pub fn as_str(self) -> &'static str {
match self {
PermissionState::Granted => "granted",
PermissionState::Denied => "denied",
PermissionState::Prompt => "prompt",
PermissionState::Unsupported => "unsupported",
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum RequestOutcome {
Settled(PermissionState),
Pending(u32),
}
pub trait PermissionHost: Send + Sync {
fn platform(&self) -> &'static str;
fn status(&self, cap: Capability) -> PermissionState;
fn has_native_prompt(&self, _cap: Capability) -> bool {
false
}
fn request(&self, cap: Capability) -> RequestOutcome {
RequestOutcome::Settled(self.status(cap))
}
fn drain_settled(&self) -> Vec<(u32, PermissionState)> {
Vec::new()
}
fn drain_changes(&self) -> Option<Vec<Capability>> {
None
}
fn denied_by_system(&self, _cap: Capability) -> bool {
true
}
}
static HOST: RwLock<Option<&'static dyn PermissionHost>> = RwLock::new(None);
pub fn set_host(host: &'static dyn PermissionHost) {
*HOST.write().unwrap() = Some(host);
}
pub fn host() -> Option<&'static dyn PermissionHost> {
#[cfg(test)]
if let Some(h) = THREAD_HOST.with(|c| c.get()) {
return Some(h);
}
*HOST.read().unwrap()
}
#[cfg(test)]
thread_local! {
static THREAD_HOST: core::cell::Cell<Option<&'static dyn PermissionHost>> = const { core::cell::Cell::new(None) };
}
#[cfg(test)]
pub(crate) fn set_thread_host(h: Option<&'static dyn PermissionHost>) {
THREAD_HOST.with(|c| c.set(h));
}
fn status_of(cap: Capability) -> PermissionState {
match host() {
Some(h) => h.status(cap),
None => {
static ONCE: OnceLock<()> = OnceLock::new();
ONCE.get_or_init(|| {
eprintln!(
"[redjs] navigator.permissions: no PermissionHost installed — every \
capability reads as denied. Call redjs::webapi::permissions::set_host()."
);
});
PermissionState::Unsupported
}
}
}
#[derive(Default)]
struct Settlements {
runtime: HashSet<u32>,
for_runtime: Vec<(u32, PermissionState)>,
for_embedder: Vec<(u32, PermissionState)>,
}
fn settlements() -> &'static Mutex<Settlements> {
static S: OnceLock<Mutex<Settlements>> = OnceLock::new();
S.get_or_init(|| Mutex::new(Settlements::default()))
}
impl Settlements {
fn drain(&mut self, h: &dyn PermissionHost) {
for (token, state) in h.drain_settled() {
if self.runtime.remove(&token) {
self.for_runtime.push((token, state));
} else {
self.for_embedder.push((token, state));
}
}
}
fn request(&mut self, h: &dyn PermissionHost, cap: Capability) -> RequestOutcome {
let out = h.request(cap);
if let RequestOutcome::Pending(token) = out {
self.runtime.insert(token);
}
out
}
fn take_embedder(&mut self, limit: usize) -> Vec<(u32, PermissionState)> {
let count = limit.min(self.for_embedder.len());
self.for_embedder.drain(..count).collect()
}
}
fn drain_host(s: &mut Settlements) {
if let Some(h) = host() {
s.drain(h);
}
}
pub(crate) fn request_for_runtime(cap: Capability) -> RequestOutcome {
let Some(h) = host() else {
return RequestOutcome::Settled(PermissionState::Unsupported);
};
settlements().lock().unwrap().request(h, cap)
}
pub(crate) fn take_runtime_settled() -> Vec<(u32, PermissionState)> {
let mut s = settlements().lock().unwrap();
drain_host(&mut s);
core::mem::take(&mut s.for_runtime)
}
pub fn take_settled() -> Vec<(u32, PermissionState)> {
take_settled_up_to(usize::MAX)
}
pub fn take_settled_up_to(limit: usize) -> Vec<(u32, PermissionState)> {
let mut s = settlements().lock().unwrap();
drain_host(&mut s);
s.take_embedder(limit)
}
struct PermClasses {
status: Class,
s_perm: *mut c_void,
}
unsafe impl Send for PermClasses {}
unsafe impl Sync for PermClasses {}
fn classes_reg() -> &'static Mutex<HashMap<usize, &'static PermClasses>> {
static R: OnceLock<Mutex<HashMap<usize, &'static PermClasses>>> = OnceLock::new();
R.get_or_init(|| Mutex::new(HashMap::new()))
}
fn classes(g: *mut c_void) -> &'static PermClasses {
classes_reg().lock().unwrap().get(&(g as usize)).copied().expect("webapi::permissions not installed")
}
#[derive(Clone, Copy)]
struct Live {
obj: u64,
seen: PermissionState,
}
fn live() -> &'static Mutex<HashMap<usize, HashMap<Capability, Live>>> {
static L: OnceLock<Mutex<HashMap<usize, HashMap<Capability, Live>>>> = OnceLock::new();
L.get_or_init(|| Mutex::new(HashMap::new()))
}
fn pending() -> &'static Mutex<HashMap<u64, Vec<Capability>>> {
static P: OnceLock<Mutex<HashMap<u64, Vec<Capability>>>> = OnceLock::new();
P.get_or_init(|| Mutex::new(HashMap::new()))
}
pub(crate) fn forget(gone: crate::context::Gone) {
classes_reg().lock().unwrap().remove(&gone.key);
live().lock().unwrap().remove(&gone.key);
pending().lock().unwrap().remove(&gone.id.0);
}
unsafe fn status_slots(g: *mut c_void, obj: u64) -> u64 {
get_a(g, obj, classes(g).s_perm)
}
unsafe fn status_cap(g: *mut c_void, obj: u64) -> Option<Capability> {
let slots = status_slots(g, obj);
if !is_cell(slots) {
return None;
}
read_string(g, get(g, slots, "name")).as_deref().and_then(Capability::from_web_name)
}
#[crate::host_fn]
unsafe fn status_get_name(g: *mut c_void, cf: *mut c_void) -> u64 {
match status_cap(g, cf_this(cf)) {
Some(cap) => js_string(g, cap.web_name()),
None => throw_type_error(g, "PermissionStatus.name on wrong this"),
}
}
#[crate::host_fn]
unsafe fn status_get_state(g: *mut c_void, cf: *mut c_void) -> u64 {
match status_cap(g, cf_this(cf)) {
Some(cap) => js_string(g, status_of(cap).web_state()),
None => throw_type_error(g, "PermissionStatus.state on wrong this"),
}
}
unsafe fn status_for(g: *mut c_void, cap: Capability) -> u64 {
if let Some(l) = live().lock().unwrap().get(&(g as usize)).and_then(|m| m.get(&cap)).copied() {
return l.obj;
}
let seen = status_of(cap);
let c = classes(g);
let obj = new_object(g, c.status.proto);
let slots = new_object(g, UNDEF);
define(g, slots, "name", js_string(g, cap.web_name()), 0);
glue::rjs_define(g, obj, c.s_perm, slots, 0);
crate::ffi::redjs_protect(g, obj);
live().lock().unwrap().entry(g as usize).or_default().insert(cap, Live { obj, seen });
obj
}
pub unsafe fn status_object(g: *mut c_void, cap: Capability) -> Option<u64> {
let installed = classes_reg().lock().unwrap().contains_key(&(g as usize));
installed.then(|| status_for(g, cap))
}
#[crate::host_fn]
unsafe fn perms_query(g: *mut c_void, cf: *mut c_void) -> u64 {
const KIND_OBJECT: u32 = 8;
let desc = cf_arg(cf, 0);
if !is_cell(desc) || glue::rjs_kind(g, desc) != KIND_OBJECT {
return rejected_promise(
g,
1, "Failed to execute 'query' on 'Permissions': parameter 1 is not of type \
'PermissionDescriptor'.",
);
}
const KIND_UNDEFINED: u32 = 0;
let raw = get(g, desc, "name");
if glue::rjs_kind(g, raw) == KIND_UNDEFINED {
return rejected_promise(
g,
1,
"Failed to read the 'name' property from 'PermissionDescriptor': Required member is \
undefined.",
);
}
let Some(name) = read_string(g, raw) else {
return rejected_promise(
g,
1,
"Failed to read the 'name' property from 'PermissionDescriptor': Required member is \
undefined.",
);
};
let Some(cap) = Capability::from_web_name(&name) else {
let known: Vec<&str> = Capability::ALL.iter().map(|c| c.web_name()).collect();
return rejected_promise(
g,
1,
&format!(
"Failed to read the 'name' property from 'PermissionDescriptor': The provided \
value '{name}' is not a valid enum value of type PermissionName. Known names: {}.",
known.join(", ")
),
);
};
resolved_promise(g, status_for(g, cap))
}
pub unsafe fn pump(g: *mut c_void) {
let Some(h) = host() else { return };
let Some(id) = crate::context::id_of(g) else { return };
let mine = {
let mut pend = pending().lock().unwrap();
if let Some(changed) = h.drain_changes() {
for cap in changed {
for q in pend.values_mut() {
if !q.contains(&cap) {
q.push(cap);
}
}
}
}
match pend.get_mut(&id.0) {
Some(q) if !q.is_empty() => core::mem::take(q),
_ => return,
}
};
for cap in mine {
let l = live().lock().unwrap().get(&(g as usize)).and_then(|m| m.get(&cap)).copied();
let Some(l) = l else { continue };
let now = status_of(cap);
if now == l.seen {
continue;
}
if let Some(entry) = live().lock().unwrap().get_mut(&(g as usize)).and_then(|m| m.get_mut(&cap)) {
entry.seen = now;
}
let ev = events::new_trusted_event(g, "change");
events::dispatch(g, l.obj, ev);
}
}
pub unsafe fn install(g: *mut c_void, event_target_proto: u64) {
let s_perm = atom_priv(g, "redjs#permissionStatus");
let status = define_class(g, &ClassSpec {
name: "PermissionStatus",
arity: 0,
construct: None,
parent_proto: event_target_proto,
methods: &[],
getters: &[("name", status_get_name), ("state", status_get_state)],
accessors: &[],
});
let perms_class = define_class(g, &ClassSpec {
name: "Permissions",
arity: 0,
construct: None,
parent_proto: 0,
methods: &[("query", 1, perms_query)],
getters: &[],
accessors: &[],
});
let boxed: &'static PermClasses = Box::leak(Box::new(PermClasses { status, s_perm }));
classes_reg().lock().unwrap().insert(g as usize, boxed);
let id = crate::context::ensure(g);
pending().lock().unwrap().entry(id.0).or_default();
let perms = new_object(g, perms_class.proto);
crate::ffi::redjs_protect(g, perms);
let global = glue::rjs_global(g);
let existing = get(g, global, "navigator");
let navigator = if is_cell(existing) {
existing
} else {
let n = new_object(g, UNDEF);
define(g, global, "navigator", n, 2 );
n
};
define(g, navigator, "permissions", perms, 2);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_capability_round_trips_through_its_web_name() {
for cap in Capability::ALL {
assert_eq!(Capability::from_web_name(cap.web_name()), Some(*cap), "{cap:?}");
}
assert_eq!(Capability::ALL.len(), 7);
}
#[test]
fn the_w3c_names_are_the_w3c_spellings() {
assert_eq!(Capability::Microphone.web_name(), "microphone");
assert_eq!(Capability::Camera.web_name(), "camera");
assert_eq!(Capability::DisplayCapture.web_name(), "display-capture");
assert_eq!(Capability::Notifications.web_name(), "notifications");
assert_eq!(Capability::ClipboardRead.web_name(), "clipboard-read");
assert_eq!(Capability::ClipboardWrite.web_name(), "clipboard-write");
assert_eq!(Capability::Geolocation.web_name(), "geolocation");
}
#[test]
fn unknown_names_do_not_parse() {
for bad in ["Microphone", "mic", "displayCapture", "clipboard", "", "midi"] {
assert_eq!(Capability::from_web_name(bad), None, "{bad:?} must not parse");
}
}
#[test]
fn unsupported_projects_to_denied_on_the_web_surface_and_keeps_its_own_name() {
assert_eq!(PermissionState::Unsupported.web_state(), "denied");
assert_eq!(PermissionState::Denied.web_state(), "denied");
assert_eq!(PermissionState::Unsupported.as_str(), "unsupported");
assert_eq!(PermissionState::Denied.as_str(), "denied");
assert_eq!(PermissionState::Granted.web_state(), "granted");
assert_eq!(PermissionState::Prompt.web_state(), "prompt");
}
struct TableHost(&'static [(Capability, PermissionState)]);
impl PermissionHost for TableHost {
fn platform(&self) -> &'static str {
"test"
}
fn status(&self, cap: Capability) -> PermissionState {
self.0.iter().find(|(c, _)| *c == cap).map(|(_, s)| *s).unwrap_or(PermissionState::Unsupported)
}
}
#[test]
fn the_default_request_reports_what_is_already_true() {
let h = TableHost(&[
(Capability::Microphone, PermissionState::Granted),
(Capability::Camera, PermissionState::Denied),
]);
assert_eq!(h.request(Capability::Microphone), RequestOutcome::Settled(PermissionState::Granted));
assert_eq!(h.request(Capability::Camera), RequestOutcome::Settled(PermissionState::Denied));
assert_eq!(
h.request(Capability::Geolocation),
RequestOutcome::Settled(PermissionState::Unsupported)
);
}
struct QueueHost {
next: Mutex<u32>,
settled: Mutex<Vec<(u32, PermissionState)>>,
}
impl PermissionHost for QueueHost {
fn platform(&self) -> &'static str {
"queue"
}
fn status(&self, _: Capability) -> PermissionState {
PermissionState::Prompt
}
fn request(&self, _: Capability) -> RequestOutcome {
let mut n = self.next.lock().unwrap();
*n += 1;
self.settled.lock().unwrap().push((*n, PermissionState::Granted));
RequestOutcome::Pending(*n)
}
fn drain_settled(&self) -> Vec<(u32, PermissionState)> {
core::mem::take(&mut *self.settled.lock().unwrap())
}
}
#[test]
fn the_runtimes_settlements_and_the_embedders_are_sorted_apart() {
let h = QueueHost { next: Mutex::new(0), settled: Mutex::new(Vec::new()) };
let mut s = Settlements::default();
assert_eq!(s.request(&h, Capability::Microphone), RequestOutcome::Pending(1));
assert_eq!(h.request(Capability::Microphone), RequestOutcome::Pending(2));
assert_eq!(s.request(&h, Capability::Microphone), RequestOutcome::Pending(3));
s.drain(&h);
assert_eq!(core::mem::take(&mut s.for_runtime), vec![(1, PermissionState::Granted), (3, PermissionState::Granted)]);
assert_eq!(core::mem::take(&mut s.for_embedder), vec![(2, PermissionState::Granted)]);
assert!(s.runtime.is_empty(), "a settled runtime token is forgotten");
s.drain(&h);
assert!(s.for_runtime.is_empty() && s.for_embedder.is_empty());
}
#[test]
fn capped_embedder_delivery_preserves_every_waiter_across_waves() {
let h = QueueHost { next: Mutex::new(0), settled: Mutex::new(Vec::new()) };
let mut s = Settlements::default();
let mut expected = Vec::new();
for i in 0..19 {
let RequestOutcome::Pending(token) = h.request(Capability::Microphone) else { panic!("pending"); };
expected.push((token, PermissionState::Granted));
if i == 8 {
assert_eq!(s.request(&h, Capability::Microphone), RequestOutcome::Pending(10));
}
}
s.drain(&h);
let mut delivered = s.take_embedder(16);
assert_eq!(delivered, expected[..16]);
assert_eq!(s.for_embedder, expected[16..]);
assert!(s.take_embedder(0).is_empty(), "a zero budget leaves the backlog alone");
assert_eq!(h.request(Capability::Microphone), RequestOutcome::Pending(21));
expected.push((21, PermissionState::Granted));
s.drain(&h);
delivered.extend(s.take_embedder(16));
assert_eq!(delivered, expected);
assert!(s.take_embedder(16).is_empty(), "each token is delivered exactly once");
assert_eq!(s.for_runtime, vec![(10, PermissionState::Granted)], "the runtime's request never enters the embedder wave");
}
#[test]
fn a_host_without_a_prompt_has_only_the_system_to_deny() {
assert!(TableHost(&[]).denied_by_system(Capability::Microphone));
}
#[test]
fn no_subscription_is_distinguishable_from_no_changes() {
let h = TableHost(&[]);
assert!(h.drain_changes().is_none());
}
}
#[cfg(test)]
mod jsc_tests {
use super::*;
use crate::api::Context;
use crate::webapi::testing::*;
fn run(c: &Context, body: &str) -> String {
s(
c,
&format!(
"globalThis.__out = '<pending>'; (async () => {{ {body} }})().then(\
v => {{ globalThis.__out = String(v); }}, \
e => {{ globalThis.__out = 'ERROR: ' + ((e && e.message) || e); }}); 'started'"
),
);
for _ in 0..64 {
c.drain_microtasks();
}
s(c, "globalThis.__out")
}
fn install_scripted_host() {
static H: ScriptedHost = ScriptedHost;
set_host(&H);
}
struct ScriptedHost;
impl PermissionHost for ScriptedHost {
fn platform(&self) -> &'static str {
"scripted"
}
fn status(&self, cap: Capability) -> PermissionState {
match cap {
Capability::Microphone => PermissionState::Granted,
Capability::Camera => PermissionState::Denied,
Capability::DisplayCapture => PermissionState::Prompt,
Capability::Notifications => *NOTIFICATIONS.lock().unwrap(),
Capability::ClipboardRead => *CLIPBOARD_READ.lock().unwrap(),
_ => PermissionState::Unsupported,
}
}
fn drain_changes(&self) -> Option<Vec<Capability>> {
Some(core::mem::take(&mut *CHANGES.lock().unwrap()))
}
}
static CHANGES: Mutex<Vec<Capability>> = Mutex::new(Vec::new());
static NOTIFICATIONS: Mutex<PermissionState> = Mutex::new(PermissionState::Prompt);
static CLIPBOARD_READ: Mutex<PermissionState> = Mutex::new(PermissionState::Prompt);
unsafe fn pump_all(c: &Context) {
crate::web::pump(c.raw(), crate::web::PUMP_TIMERS | crate::web::PUMP_MICROTASKS, core::ptr::null_mut());
}
#[test]
fn a_change_reaches_every_context_whichever_pumps_first() {
install_scripted_host();
let a = ctx();
let b = ctx();
for c in [&a, &b] {
run(
c,
"const st = await navigator.permissions.query({ name: 'notifications' });
globalThis.__n = 0;
st.addEventListener('change', () => { globalThis.__n++; });
return 'ok';",
);
}
*NOTIFICATIONS.lock().unwrap() = PermissionState::Granted;
CHANGES.lock().unwrap().push(Capability::Notifications);
unsafe {
pump_all(&a);
pump_all(&b);
}
ok(&a, "globalThis.__n === 1");
ok(&b, "globalThis.__n === 1");
unsafe {
pump_all(&b);
pump_all(&a);
}
ok(&a, "globalThis.__n === 1");
ok(&b, "globalThis.__n === 1");
}
#[test]
fn change_fires_only_when_the_state_really_changed() {
install_scripted_host();
let c = ctx();
run(
&c,
"const st = await navigator.permissions.query({ name: 'clipboard-read' });
globalThis.__seen = [];
st.addEventListener('change', () => { globalThis.__seen.push(st.state); });
return 'ok';",
);
CHANGES.lock().unwrap().push(Capability::ClipboardRead);
unsafe { pump_all(&c) };
ok(&c, "globalThis.__seen.length === 0");
*CLIPBOARD_READ.lock().unwrap() = PermissionState::Granted;
CHANGES.lock().unwrap().push(Capability::ClipboardRead);
unsafe { pump_all(&c) };
CHANGES.lock().unwrap().push(Capability::ClipboardRead);
unsafe { pump_all(&c) };
ok(&c, "globalThis.__seen.join() === 'granted'");
*CLIPBOARD_READ.lock().unwrap() = PermissionState::Prompt;
CHANGES.lock().unwrap().push(Capability::ClipboardRead);
unsafe { pump_all(&c) };
ok(&c, "globalThis.__seen.join() === 'granted,prompt'");
}
#[test]
fn permissions_is_a_singleton_on_navigator() {
let c = ctx();
ok(&c, "navigator.permissions === navigator.permissions");
ok(&c, "navigator.permissions instanceof Permissions");
ok(&c, "typeof navigator.permissions.query === 'function'");
ok(&c, "typeof navigator === 'object' && navigator !== null");
}
#[test]
fn query_resolves_a_permission_status_that_is_an_event_target() {
install_scripted_host();
let c = ctx();
assert_eq!(
run(
&c,
"const st = await navigator.permissions.query({ name: 'microphone' });
if (!(st instanceof PermissionStatus)) return 'not a PermissionStatus';
if (st.name !== 'microphone') return 'name: ' + st.name;
if (typeof st.addEventListener !== 'function') return 'not an EventTarget';
return 'ok';"
),
"ok"
);
}
#[test]
fn the_three_web_states_come_through_and_unsupported_reads_as_denied() {
install_scripted_host();
let c = ctx();
assert_eq!(
run(
&c,
"const q = n => navigator.permissions.query({ name: n }).then(s => s.state);
return [await q('microphone'), await q('camera'), await q('display-capture'),
await q('geolocation')].join(',');"
),
"granted,denied,prompt,denied"
);
}
#[test]
fn an_unknown_name_is_a_type_error_not_a_denial() {
let c = ctx();
let got = run(&c, "const s = await navigator.permissions.query({ name: 'mic' }); return s.state;");
assert!(got.starts_with("ERROR:"), "{got}");
assert!(got.contains("not a valid enum value"), "{got}");
assert!(got.contains("microphone"), "the message must list the known names: {got}");
let got = run(&c, "return (await navigator.permissions.query('microphone')).state;");
assert!(got.contains("PermissionDescriptor"), "{got}");
let got = run(&c, "return (await navigator.permissions.query({})).state;");
assert!(got.contains("Required member is undefined"), "{got}");
let got = run(&c, "return (await navigator.permissions.query({ name: undefined })).state;");
assert!(got.contains("Required member is undefined"), "{got}");
}
#[test]
fn the_documented_divergence_is_exactly_one_status_per_name() {
install_scripted_host();
let c = ctx();
assert_eq!(
run(
&c,
"const a = await navigator.permissions.query({ name: 'microphone' });
const b = await navigator.permissions.query({ name: 'microphone' });
const d = await navigator.permissions.query({ name: 'camera' });
return (a === b) + ',' + (a === d);"
),
"true,false"
);
}
#[test]
fn both_change_listener_shapes_fire() {
install_scripted_host();
let c = ctx();
assert_eq!(
run(
&c,
"const st = await navigator.permissions.query({ name: 'microphone' });
let n = 0;
st.addEventListener('change', () => { n++; });
st.onchange = () => { n += 10; };
st.dispatchEvent(new Event('change'));
return n;"
),
"11"
);
}
#[test]
fn the_classes_are_not_constructible_and_the_getters_refuse_a_foreign_this() {
let c = ctx();
assert!(throws(&c, "new PermissionStatus()").contains("Illegal constructor"));
assert!(throws(&c, "new Permissions()").contains("Illegal constructor"));
let msg = throws(
&c,
"Object.getOwnPropertyDescriptor(PermissionStatus.prototype, 'state').get.call({})",
);
assert!(msg.contains("wrong this"), "{msg}");
}
}