Skip to content

Commit

Permalink
Fixed Global Unrooting
Browse files Browse the repository at this point in the history
Reformatted Code
  • Loading branch information
Redfire75369 committed Dec 1, 2023
1 parent f6f0c1f commit 303831e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
6 changes: 2 additions & 4 deletions ion-proc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ fn impl_body(span: Span, data: &Data) -> Result<Block> {
match data {
Data::Struct(r#struct) => {
let (idents, skip) = field_idents(&r#struct.fields);
let traced = idents
.iter()
.enumerate()
.filter_map(|(index, ident)| (!skip.contains(&index)).then_some(ident));
let traced =
idents.iter().enumerate().filter_map(|(index, ident)| (!skip.contains(&index)).then_some(ident));
parse2(quote_spanned!(span => {
let Self { #(#idents),* } = self;
#(::mozjs::gc::Traceable::trace(#traced, __ion_tracer));*
Expand Down
6 changes: 1 addition & 5 deletions ion/src/string/byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ pub struct ByteString<T: BytePredicate = Latin1> {

impl<T: BytePredicate> ByteString<T> {
pub fn from(bytes: Vec<u8>) -> Option<ByteString<T>> {
bytes
.iter()
.copied()
.all(T::predicate)
.then(|| unsafe { ByteString::from_unchecked(bytes) })
bytes.iter().copied().all(T::predicate).then(|| unsafe { ByteString::from_unchecked(bytes) })
}

pub unsafe fn from_unchecked(bytes: Vec<u8>) -> ByteString<T> {
Expand Down
5 changes: 1 addition & 4 deletions runtime/src/globals/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ impl File {
pub fn constructor(parts: Vec<BlobPart>, name: String, options: Option<FileOptions>) -> File {
let options = options.unwrap_or_default();
let blob = Blob::constructor(Some(parts), Some(options.blob));
let modified = options
.modified
.and_then(|d| Utc.timestamp_millis_opt(d).single())
.unwrap_or_else(Utc::now);
let modified = options.modified.and_then(|d| Utc.timestamp_millis_opt(d).single()).unwrap_or_else(Utc::now);

File { blob, name, modified }
}
Expand Down
9 changes: 5 additions & 4 deletions runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl ContextExt for Context {
}

pub struct Runtime<'cx> {
global: Object,
global: Option<Object>,
cx: &'cx Context,
#[allow(dead_code)]
realm: JSAutoRealm,
Expand All @@ -49,11 +49,11 @@ impl<'cx> Runtime<'cx> {
}

pub fn global(&self) -> &Object {
&self.global
self.global.as_ref().unwrap()
}

pub fn global_mut(&mut self) -> &mut Object {
&mut self.global
self.global.as_mut().unwrap()
}

pub async fn run_event_loop(&self) -> Result<(), Option<ErrorReport>> {
Expand All @@ -64,6 +64,7 @@ impl<'cx> Runtime<'cx> {

impl Drop for Runtime<'_> {
fn drop(&mut self) {
let _ = self.global.take();
let private = self.cx.get_private();
let _ = unsafe { Box::from_raw(private.as_ptr()) };
let inner_private = self.cx.get_inner_data();
Expand Down Expand Up @@ -156,7 +157,7 @@ impl<ML: ModuleLoader + 'static, Std: StandardModules + 'static> RuntimeBuilder<
}
}

Runtime { global, cx, realm }
Runtime { global: Some(global), cx, realm }
}
}

Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
chain_width = 120
chain_width = 100
edition = "2021"
force_explicit_abi = true
fn_params_layout = "Compressed"
Expand Down

0 comments on commit 303831e

Please sign in to comment.