Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/engine/src/builtins/temporal/instant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ impl Instant {
None,
context,
)
.map(Into::into)
}

pub(crate) fn from_epoch_milliseconds(
Expand All @@ -172,7 +171,6 @@ impl Instant {
None,
context,
)
.map(Into::into)
}

pub(crate) fn from_epoch_nanoseconds(
Expand All @@ -190,7 +188,6 @@ impl Instant {
None,
context,
)
.map(Into::into)
}

pub(crate) fn compare(
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/temporal/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Now {
/// 2.2.2 `Temporal.Now.instant()`
fn instant(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let epoch_nanos = system_nanoseconds(context)?;
create_temporal_instant(Instant::from(epoch_nanos), None, context).map(Into::into)
create_temporal_instant(Instant::from(epoch_nanos), None, context)
}

/// 2.2.3 `Temporal.Now.plainDateTimeISO ( [ temporalTimeZoneLike ] )`
Expand Down
18 changes: 6 additions & 12 deletions core/engine/src/builtins/temporal/plain_date_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,7 @@ fn to_partial_datetime(
let finite = v.to_finitef64(context)?;
Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
})
.transpose()?
.map(Into::into);
.transpose()?;
// TODO: `temporal_rs` needs a `has_era` method
let (era, era_year) = if calendar == Calendar::default() {
(None, None)
Expand Down Expand Up @@ -1254,26 +1253,23 @@ fn to_partial_datetime(
let finite = v.to_finitef64(context)?;
Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let millisecond = partial_object
.get(js_string!("millisecond"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let minute = partial_object
.get(js_string!("minute"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let month = partial_object
.get(js_string!("month"), context)?
Expand Down Expand Up @@ -1305,17 +1301,15 @@ fn to_partial_datetime(
let finite = v.to_finitef64(context)?;
Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let second = partial_object
.get(js_string!("second"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let year = partial_object
.get(js_string!("year"), context)?
Expand Down
18 changes: 6 additions & 12 deletions core/engine/src/builtins/temporal/plain_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,53 +722,47 @@ pub(crate) fn to_partial_time_record(
let finite = v.to_finitef64(context)?;
Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let microsecond = partial_object
.get(js_string!("microsecond"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let millisecond = partial_object
.get(js_string!("millisecond"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let minute = partial_object
.get(js_string!("minute"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let nanosecond = partial_object
.get(js_string!("nanosecond"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u16, JsError>(finite.as_integer_with_truncation::<u16>())
})
.transpose()?
.map(Into::into);
.transpose()?;

let second = partial_object
.get(js_string!("second"), context)?
.map(|v| {
let finite = v.to_finitef64(context)?;
Ok::<u8, JsError>(finite.as_integer_with_truncation::<u8>())
})
.transpose()?
.map(Into::into);
.transpose()?;

Ok(PartialTime {
hour,
Expand Down
9 changes: 2 additions & 7 deletions core/engine/src/builtins/temporal/plain_year_month/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,8 @@ impl BuiltInConstructor for PlainYearMonth {
.transpose()?;

// 7. Return ? CreateTemporalYearMonth(y, m, calendar, ref, NewTarget).
let inner = InnerYearMonth::new_with_overflow(
y,
m,
ref_day.map(Into::into),
calendar,
ArithmeticOverflow::Reject,
)?;
let inner =
InnerYearMonth::new_with_overflow(y, m, ref_day, calendar, ArithmeticOverflow::Reject)?;

create_temporal_year_month(inner, Some(new_target), context)
}
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/temporal/zoneddatetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ impl ZonedDateTime {
JsNativeError::typ().with_message("the this object must be a ZonedDateTime object.")
})?;

create_temporal_instant(zdt.inner.to_instant(), None, context).map(Into::into)
create_temporal_instant(zdt.inner.to_instant(), None, context)
}

/// 6.3.48 `Temporal.ZonedDateTime.prototype.toPlainDate ( )`
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl JsError {
/// Is the [`JsError`] catchable in JavaScript.
#[inline]
pub(crate) fn is_catchable(&self) -> bool {
self.as_native().map_or(true, JsNativeError::is_catchable)
self.as_native().is_none_or(JsNativeError::is_catchable)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/module/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn module_namespace_exotic_define_own_property(

// 8. If Desc has a [[Value]] field, return SameValue(Desc.[[Value]], current.[[Value]]).
// 9. Return true.
Ok(desc.value().map_or(true, |v| v == current.expect_value()))
Ok(desc.value().is_none_or(|v| v == current.expect_value()))
}

/// [`[[HasProperty]] ( P )`][spec]
Expand Down
16 changes: 14 additions & 2 deletions core/engine/src/object/jsobject.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! This module implements the `JsObject` structure.
//!
//! The `JsObject` is a garbage collected Object.
#![allow(
unknown_lints,
reason = "unpredictable_function_pointer_comparisons doesn't exist on 1.84"
)]

use super::{
internal_methods::{InternalMethodContext, InternalObjectMethods, ORDINARY_INTERNAL_METHODS},
Expand Down Expand Up @@ -408,7 +412,7 @@ impl JsObject {
let get = if let Some(getter) = self.try_get(js_string!("get"), context)? {
// b. If IsCallable(getter) is false and getter is not undefined, throw a TypeError exception.
// todo: extract IsCallable to be callable from Value
if !getter.is_undefined() && getter.as_object().map_or(true, |o| !o.is_callable()) {
if !getter.is_undefined() && getter.as_object().is_none_or(|o| !o.is_callable()) {
return Err(JsNativeError::typ()
.with_message("Property descriptor getter must be callable")
.into());
Expand All @@ -425,7 +429,7 @@ impl JsObject {
let set = if let Some(setter) = self.try_get(js_string!("set"), context)? {
// 14.b. If IsCallable(setter) is false and setter is not undefined, throw a TypeError exception.
// todo: extract IsCallable to be callable from Value
if !setter.is_undefined() && setter.as_object().map_or(true, |o| !o.is_callable()) {
if !setter.is_undefined() && setter.as_object().is_none_or(|o| !o.is_callable()) {
return Err(JsNativeError::typ()
.with_message("Property descriptor setter must be callable")
.into());
Expand Down Expand Up @@ -748,6 +752,10 @@ impl<T: NativeObject + ?Sized> JsObject<T> {
/// [spec]: https://tc39.es/ecma262/#sec-iscallable
#[inline]
#[must_use]
#[expect(
unpredictable_function_pointer_comparisons,
reason = "can only use `ptr::fn_addr_eq` on rustc 1.85"
)]
pub fn is_callable(&self) -> bool {
self.inner.vtable.__call__ != ORDINARY_INTERNAL_METHODS.__call__
}
Expand All @@ -760,6 +768,10 @@ impl<T: NativeObject + ?Sized> JsObject<T> {
/// [spec]: https://tc39.es/ecma262/#sec-isconstructor
#[inline]
#[must_use]
#[expect(
unpredictable_function_pointer_comparisons,
reason = "can only use `ptr::fn_addr_eq` on rustc 1.85"
)]
pub fn is_constructor(&self) -> bool {
self.inner.vtable.__construct__ != ORDINARY_INTERNAL_METHODS.__construct__
}
Expand Down
8 changes: 1 addition & 7 deletions core/engine/src/vm/opcode/concat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ impl ConcatToString {
let val = registers.get(*value);
strings.push(val.to_string(context)?);
}
let s = JsString::concat_array(
&strings
.iter()
.map(JsString::as_str)
.map(Into::into)
.collect::<Vec<_>>(),
);
let s = JsString::concat_array(&strings.iter().map(JsString::as_str).collect::<Vec<_>>());
registers.set(string, s.into());
Ok(CompletionType::Normal)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ where

if let Some(position) = duplicate_proto_position {
if !cursor.json_parse()
&& cursor.peek(0, interner)?.map_or(true, |token| {
token.kind() != &TokenKind::Punctuator(Punctuator::Assign)
})
&& cursor
.peek(0, interner)?
.is_none_or(|token| token.kind() != &TokenKind::Punctuator(Punctuator::Assign))
{
return Err(Error::general(
"Duplicate __proto__ fields are not allowed in object literals.",
Expand Down
14 changes: 8 additions & 6 deletions core/parser/src/parser/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ where

params.push(next_param);

if cursor.peek(0, interner)?.map_or(true, |tok| {
tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen)
}) {
if cursor
.peek(0, interner)?
.is_none_or(|tok| tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen))
{
break;
}

Expand All @@ -120,9 +121,10 @@ where
}

cursor.expect(Punctuator::Comma, "parameter list", interner)?;
if cursor.peek(0, interner)?.map_or(true, |tok| {
tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen)
}) {
if cursor
.peek(0, interner)?
.is_none_or(|tok| tok.kind() == &TokenKind::Punctuator(Punctuator::CloseParen))
{
break;
}
}
Expand Down
1 change: 0 additions & 1 deletion core/parser/src/parser/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ where
TokenKind::Keyword((Keyword::For, _)) => {
ForStatement::new(self.allow_yield, self.allow_await, self.allow_return)
.parse(cursor, interner)
.map(ast::Statement::from)
}
TokenKind::Keyword((Keyword::Return, _)) => {
if self.allow_return.0 {
Expand Down
2 changes: 1 addition & 1 deletion core/parser/src/source/utf16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ fn is_low_surrogate(b: u16) -> bool {
}

fn code_point_from_surrogates(high: u16, low: u16) -> u32 {
((u32::from(high & 0x3ff)) << 10 | u32::from(low & 0x3ff)) + 0x1_0000
(((u32::from(high & 0x3ff)) << 10) | u32::from(low & 0x3ff)) + 0x1_0000
}
4 changes: 2 additions & 2 deletions core/parser/src/source/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ impl<R: Read> ReadChar for UTF8Input<R> {
// 5th bit in 0xE0 .. 0xEF is always clear, so `init` is still valid
let z = self.next_byte()?.unwrap_or(0);
let y_z = utf8_acc_cont_byte(u32::from(y & CONT_MASK), z);
ch = init << 12 | y_z;
ch = (init << 12) | y_z;
if x >= 0xF0 {
// [x y z w] case
// use only the lower 3 bits of `init`
let w = self.next_byte()?.unwrap_or(0);
ch = (init & 7) << 18 | utf8_acc_cont_byte(y_z, w);
ch = ((init & 7) << 18) | utf8_acc_cont_byte(y_z, w);
}
};

Expand Down
8 changes: 1 addition & 7 deletions core/string/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,13 +970,7 @@ impl From<JsStr<'_>> for JsString {
impl From<&[JsString]> for JsString {
#[inline]
fn from(value: &[JsString]) -> Self {
Self::concat_array(
&value
.iter()
.map(Self::as_str)
.map(Into::into)
.collect::<Vec<_>>()[..],
)
Self::concat_array(&value.iter().map(Self::as_str).collect::<Vec<_>>()[..])
}
}

Expand Down
Loading