0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-02-21 21:02:53 -05:00

chore: fix map_unwrap_or clippy lint (#1690)

auto-fixed trailing semicolons by running

```
clippy --fix --all-features --all-targets --workspace -- -W clippy::map_unwrap_or
```

See [`map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or) clippy lint.
This commit is contained in:
Yuri Astrakhan 2025-02-10 13:53:51 -05:00 committed by GitHub
parent a8732245a7
commit db6e8a4c1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 26 additions and 43 deletions

View file

@ -67,8 +67,7 @@ fn main() {
.as_ref() .as_ref()
.and_then(|p| p.file_stem()) .and_then(|p| p.file_stem())
.and_then(|f| f.to_str()) .and_then(|f| f.to_str())
.map(|s| s.starts_with("rls")) .is_some_and(|s| s.starts_with("rls"));
.unwrap_or(false);
// Early exit // Early exit
if is_cargo_doc || is_rls { if is_cargo_doc || is_rls {

View file

@ -117,8 +117,10 @@ fn execute_script(
let exception_string = try_catch let exception_string = try_catch
.stack_trace() .stack_trace()
.or_else(|| try_catch.exception()) .or_else(|| try_catch.exception())
.map(|value| value.to_rust_string_lossy(try_catch)) .map_or_else(
.unwrap_or_else(|| "no stack trace".into()); || "no stack trace".into(),
|value| value.to_rust_string_lossy(try_catch),
);
panic!("{}", exception_string); panic!("{}", exception_string);
} }

View file

@ -482,7 +482,7 @@ impl ArrayBuffer {
// V8 terminates when the ArrayBuffer is not detachable. Non-detachable // V8 terminates when the ArrayBuffer is not detachable. Non-detachable
// buffers are buffers that are in use by WebAssembly or asm.js. // buffers are buffers that are in use by WebAssembly or asm.js.
if self.is_detachable() { if self.is_detachable() {
let key = key.map(|v| &*v as *const Value).unwrap_or(null()); let key = key.map_or(null(), |v| &*v as *const Value);
unsafe { v8__ArrayBuffer__Detach(self, key) }.into() unsafe { v8__ArrayBuffer__Detach(self, key) }.into()
} else { } else {
Some(true) Some(true)

View file

@ -99,12 +99,8 @@ impl Context {
sd.get_isolate_ptr(), sd.get_isolate_ptr(),
options options
.global_template .global_template
.map(|t| &*t as *const _) .map_or_else(null, |t| &*t as *const _),
.unwrap_or_else(null), options.global_object.map_or_else(null, |o| &*o as *const _),
options
.global_object
.map(|o| &*o as *const _)
.unwrap_or_else(null),
options.microtask_queue.unwrap_or_else(null_mut), options.microtask_queue.unwrap_or_else(null_mut),
) )
}) })
@ -358,10 +354,7 @@ impl Context {
v8__Context__FromSnapshot( v8__Context__FromSnapshot(
sd.get_isolate_mut(), sd.get_isolate_mut(),
context_snapshot_index, context_snapshot_index,
options options.global_object.map_or_else(null, |o| &*o as *const _),
.global_object
.map(|o| &*o as *const _)
.unwrap_or_else(null),
options.microtask_queue.unwrap_or_else(null_mut), options.microtask_queue.unwrap_or_else(null_mut),
) )
}) })

View file

@ -508,8 +508,7 @@ impl From<&'_ mut Isolate> for HandleHost {
impl From<&'_ IsolateHandle> for HandleHost { impl From<&'_ IsolateHandle> for HandleHost {
fn from(isolate_handle: &IsolateHandle) -> Self { fn from(isolate_handle: &IsolateHandle) -> Self {
NonNull::new(unsafe { isolate_handle.get_isolate_ptr() }) NonNull::new(unsafe { isolate_handle.get_isolate_ptr() })
.map(Self::Isolate) .map_or(Self::DisposedIsolate, Self::Isolate)
.unwrap_or(Self::DisposedIsolate)
} }
} }
@ -1097,8 +1096,7 @@ impl<T> TracedReference<T> {
self as *mut Self as *mut TracedReference<Data>, self as *mut Self as *mut TracedReference<Data>,
scope.get_isolate_ptr(), scope.get_isolate_ptr(),
data data
.map(|h| h.as_non_null().as_ptr()) .map_or(std::ptr::null_mut(), |h| h.as_non_null().as_ptr())
.unwrap_or(std::ptr::null_mut())
.cast(), .cast(),
); );
} }

View file

@ -306,8 +306,7 @@ where
specifier, specifier,
import_attributes, import_attributes,
) )
.map(|return_value| return_value.as_non_null().as_ptr()) .map_or_else(null_mut, |return_value| return_value.as_non_null().as_ptr())
.unwrap_or_else(null_mut)
} }
#[cfg(all(target_family = "windows", target_arch = "x86_64"))] #[cfg(all(target_family = "windows", target_arch = "x86_64"))]
@ -846,8 +845,7 @@ impl Isolate {
) { ) {
let scope_data_ptr = scope_data let scope_data_ptr = scope_data
.map(NonNull::cast) .map(NonNull::cast)
.map(NonNull::as_ptr) .map_or_else(null_mut, NonNull::as_ptr);
.unwrap_or_else(null_mut);
self.set_data_internal(Self::CURRENT_SCOPE_DATA_SLOT, scope_data_ptr); self.set_data_internal(Self::CURRENT_SCOPE_DATA_SLOT, scope_data_ptr);
} }
@ -1105,9 +1103,7 @@ impl Isolate {
.get_slot::<HostCreateShadowRealmContextCallback>() .get_slot::<HostCreateShadowRealmContextCallback>()
.unwrap(); .unwrap();
let context = callback(&mut scope); let context = callback(&mut scope);
context context.map_or_else(null_mut, |l| l.as_non_null().as_ptr())
.map(|l| l.as_non_null().as_ptr())
.unwrap_or_else(null_mut)
} }
// Windows x64 ABI: MaybeLocal<Context> must be returned on the stack. // Windows x64 ABI: MaybeLocal<Context> must be returned on the stack.

View file

@ -127,9 +127,7 @@ where
fn mapping() -> Self { fn mapping() -> Self {
let f = |context, module| { let f = |context, module| {
SyntheticModuleEvaluationStepsRet( SyntheticModuleEvaluationStepsRet(
(F::get())(context, module) (F::get())(context, module).map_or(null(), |r| -> *const Value { &*r }),
.map(|r| -> *const Value { &*r })
.unwrap_or(null()),
) )
}; };
f.to_c_fn() f.to_c_fn()

View file

@ -68,7 +68,7 @@ impl Script {
v8__Script__Compile( v8__Script__Compile(
sd.get_current_context(), sd.get_current_context(),
&*source, &*source,
origin.map(|r| r as *const _).unwrap_or_else(null), origin.map_or_else(null, |r| r as *const _),
) )
}) })
} }
@ -128,15 +128,11 @@ impl<'s> ScriptOrigin<'s> {
resource_column_offset, resource_column_offset,
resource_is_shared_cross_origin, resource_is_shared_cross_origin,
script_id, script_id,
source_map_url source_map_url.map_or_else(null, |l| &*l as *const Value),
.map(|l| &*l as *const Value)
.unwrap_or_else(null),
resource_is_opaque, resource_is_opaque,
is_wasm, is_wasm,
is_module, is_module,
host_defined_options host_defined_options.map_or_else(null, |l| &*l as *const Data),
.map(|l| &*l as *const Data)
.unwrap_or_else(null),
); );
buf.assume_init() buf.assume_init()
} }

View file

@ -151,7 +151,7 @@ impl Source {
v8__ScriptCompiler__Source__CONSTRUCT( v8__ScriptCompiler__Source__CONSTRUCT(
&mut buf, &mut buf,
&*source_string, &*source_string,
origin.map(|x| x as *const _).unwrap_or(std::ptr::null()), origin.map_or(std::ptr::null(), |x| x as *const _),
std::ptr::null_mut(), std::ptr::null_mut(),
); );
buf.assume_init() buf.assume_init()
@ -169,7 +169,7 @@ impl Source {
v8__ScriptCompiler__Source__CONSTRUCT( v8__ScriptCompiler__Source__CONSTRUCT(
&mut buf, &mut buf,
&*source_string, &*source_string,
origin.map(|x| x as *const _).unwrap_or(std::ptr::null()), origin.map_or(std::ptr::null(), |x| x as *const _),
cached_data.into_raw(), // Source constructor takes ownership. cached_data.into_raw(), // Source constructor takes ownership.
); );
buf.assume_init() buf.assume_init()

View file

@ -77,8 +77,7 @@ impl<T> UniquePtr<T> {
pub fn into_raw(self) -> *mut T { pub fn into_raw(self) -> *mut T {
self self
.0 .0
.map(|unique_ref| unique_ref.into_raw()) .map_or_else(null_mut, |unique_ref| unique_ref.into_raw())
.unwrap_or_else(null_mut)
} }
} }

View file

@ -59,7 +59,7 @@ impl WasmStreaming {
/// {exception} does not have value, the promise does not get rejected. /// {exception} does not have value, the promise does not get rejected.
#[inline(always)] #[inline(always)]
pub fn abort(mut self, exception: Option<Local<Value>>) { pub fn abort(mut self, exception: Option<Local<Value>>) {
let exception = exception.map(|v| &*v as *const Value).unwrap_or(null()); let exception = exception.map_or(null(), |v| &*v as *const Value);
unsafe { v8__WasmStreaming__Abort(&mut self.0, exception) } unsafe { v8__WasmStreaming__Abort(&mut self.0, exception) }
} }

View file

@ -233,8 +233,10 @@ fn execute_script(
let exception_string = scope let exception_string = scope
.stack_trace() .stack_trace()
.or_else(|| scope.exception()) .or_else(|| scope.exception())
.map(|value| value.to_rust_string_lossy(scope)) .map_or_else(
.unwrap_or_else(|| "no stack trace".into()); || "no stack trace".into(),
|value| value.to_rust_string_lossy(scope),
);
panic!("{}", exception_string); panic!("{}", exception_string);
} }