mirror of
https://github.com/denoland/deno.git
synced 2025-02-12 16:59:32 -05:00
![David Sherret](/assets/img/avatar_default.png)
This slightly degrades the performance of CJS export analysis on
subsequent runs because I changed it to no longer cache in the DENO_DIR
with this PR (denort now properly has no idea about the DENO_DIR). We'll
have to change it to embed this data in the binary and that will also
allow us to get rid of swc in denort (will do that in a follow-up PR).
(cherry picked from commit 57dd66ec3d
)
43 lines
1,004 B
Rust
43 lines
1,004 B
Rust
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
|
|
use std::convert::Infallible;
|
|
use std::fmt::Debug;
|
|
use std::fmt::Display;
|
|
|
|
use deno_error::JsErrorBox;
|
|
use deno_error::JsErrorClass;
|
|
use deno_runtime::deno_core::error::AnyError;
|
|
use deno_runtime::deno_core::error::CoreError;
|
|
|
|
pub trait InfallibleResultExt<T> {
|
|
fn unwrap_infallible(self) -> T;
|
|
}
|
|
|
|
impl<T> InfallibleResultExt<T> for Result<T, Infallible> {
|
|
fn unwrap_infallible(self) -> T {
|
|
match self {
|
|
Ok(value) => value,
|
|
Err(never) => match never {},
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn any_and_jserrorbox_downcast_ref<
|
|
E: Display + Debug + Send + Sync + 'static,
|
|
>(
|
|
err: &AnyError,
|
|
) -> Option<&E> {
|
|
err
|
|
.downcast_ref::<E>()
|
|
.or_else(|| {
|
|
err
|
|
.downcast_ref::<JsErrorBox>()
|
|
.and_then(|e| e.as_any().downcast_ref::<E>())
|
|
})
|
|
.or_else(|| {
|
|
err.downcast_ref::<CoreError>().and_then(|e| match e {
|
|
CoreError::JsBox(e) => e.as_any().downcast_ref::<E>(),
|
|
_ => None,
|
|
})
|
|
})
|
|
}
|