Skip to content

Commit

Permalink
Fix new merges from main
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Dec 16, 2024
1 parent d8eef06 commit 81e92b6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion core/engine/src/builtins/number/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(crate) fn f64_to_int32(number: f64) -> i32 {
"fjcvtzs {dst:w}, {src:d}",
src = in(vreg) number,
dst = out(reg) ret,
)
);
}
ret
}
Expand Down
9 changes: 5 additions & 4 deletions core/engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,11 @@ impl String {
let len = string.len() as i64;

// 7. If position is undefined, let pos be 0; else let pos be ? ToIntegerOrInfinity(position).
let pos = match args.get_or_undefined(1).as_defined() {
None => IntegerOrInfinity::Integer(0),
Some(pos) => pos.to_integer_or_infinity(context)?,
};
let pos = args
.get_or_undefined(1)
.map_or(Ok(IntegerOrInfinity::Integer(0)), |pos| {
pos.to_integer_or_infinity(context)
})?;

// 8. Let start be the result of clamping pos between 0 and len.
let start = pos.clamp_finite(0, len) as usize;
Expand Down
5 changes: 2 additions & 3 deletions core/engine/src/builtins/temporal/plain_month_day/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ fn to_temporal_month_day(
let month_code = item
.get_v(js_string!("monthCode"), context)?
.map(|v| {
let JsValue::String(month_code) =
v.to_primitive(context, crate::value::PreferredType::String)?
else {
let primitive = v.to_primitive(context, crate::value::PreferredType::String)?;
let Some(month_code) = primitive.as_string() else {
return Err(JsNativeError::typ()
.with_message("The monthCode field value must be a string.")
.into());
Expand Down
3 changes: 2 additions & 1 deletion core/engine/src/builtins/temporal/plain_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ pub(crate) fn to_temporal_time(
context: &mut Context,
) -> JsResult<PlainTimeInner> {
// 1.If overflow is not present, set overflow to "constrain".
let options = options.unwrap_or(&JsValue::Undefined);
let binding = JsValue::undefined();
let options = options.unwrap_or(&binding);
// 2. If item is an Object, then
match value.variant() {
JsVariant::Object(object) => {
Expand Down
18 changes: 9 additions & 9 deletions core/engine/src/builtins/temporal/zoneddatetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
string::StaticJsStrings,
value::{IntoOrUndefined, PreferredType},
Context, JsArgs, JsBigInt, JsData, JsError, JsNativeError, JsObject, JsResult, JsString,
JsSymbol, JsValue,
JsSymbol, JsValue, JsVariant,
};
use boa_gc::{Finalize, Trace};
use boa_profiler::Profiler;
Expand Down Expand Up @@ -359,7 +359,7 @@ impl BuiltInConstructor for ZonedDateTime {
};

// 4. If timeZone is not a String, throw a TypeError exception.
let JsValue::String(timezone_str) = args.get_or_undefined(1) else {
let Some(timezone_str) = args.get_or_undefined(1).as_string() else {
return Err(JsNativeError::typ()
.with_message("timeZone must be a string.")
.into());
Expand All @@ -383,7 +383,7 @@ impl BuiltInConstructor for ZonedDateTime {
let calendar = args
.get(2)
.map(|v| {
if let JsValue::String(calendar_str) = v {
if let Some(calendar_str) = v.as_string() {
Calendar::from_str(&calendar_str.to_std_string_escaped())
.map_err(Into::<JsError>::into)
} else {
Expand Down Expand Up @@ -610,7 +610,7 @@ impl ZonedDateTime {
JsNativeError::typ().with_message("the this object must be a ZonedDateTime object.")
})?;

Ok((zdt.inner.epoch_milliseconds()).into())
Ok(zdt.inner.epoch_milliseconds().into())
}

/// 6.3.18 get `Temporal.ZonedDateTime.prototype.epochNanosecond`
Expand Down Expand Up @@ -889,8 +889,8 @@ pub(crate) fn to_temporal_zoneddatetime(
// 2. Let offsetBehaviour be option.
// 3. Let matchBehaviour be match-exactly.
// 4. If item is an Object, then
match value {
JsValue::Object(object) => {
match value.variant() {
JsVariant::Object(object) => {
// a. If item has an [[InitializedTemporalZonedDateTime]] internal slot, then
if let Some(zdt) = object.downcast_ref::<ZonedDateTime>() {
// i. NOTE: The following steps, and similar ones below, read options
Expand Down Expand Up @@ -964,7 +964,7 @@ pub(crate) fn to_temporal_zoneddatetime(
context.tz_provider(),
)?)
}
JsValue::String(zdt_source) => {
JsVariant::String(zdt_source) => {
// b. Let result be ? ParseISODateTime(item, « TemporalDateTimeString[+Zoned] »).
// c. Let annotation be result.[[TimeZone]].[[TimeZoneAnnotation]].
// d. Assert: annotation is not empty.
Expand Down Expand Up @@ -1025,7 +1025,7 @@ pub(crate) fn to_temporal_timezone_identifier(
}

// 2. If temporalTimeZoneLike is not a String, throw a TypeError exception.
let JsValue::String(tz_string) = value else {
let Some(tz_string) = value.as_string() else {
return Err(JsNativeError::typ()
.with_message("timeZone must be a string or Temporal.ZonedDateTime")
.into());
Expand All @@ -1048,7 +1048,7 @@ fn to_offset_string(value: &JsValue, context: &mut Context) -> JsResult<String>
// 1. Let offset be ? ToPrimitive(argument, string).
let offset = value.to_primitive(context, PreferredType::String)?;
// 2. If offset is not a String, throw a TypeError exception.
let JsValue::String(offset_string) = offset else {
let Some(offset_string) = offset.as_string() else {
return Err(JsNativeError::typ()
.with_message("offset must be a String.")
.into());
Expand Down
15 changes: 4 additions & 11 deletions core/engine/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ impl JsValue {
Self::from_inner(InnerValue::Float64(f64::NEG_INFINITY))
}

/// Creates a new number from an integer.
#[inline]
#[must_use]
pub const fn integer(integer: i32) -> Self {
Self::from_inner(InnerValue::Integer32(integer))
}

/// Creates a new number from a float.
#[inline]
#[must_use]
Expand Down Expand Up @@ -1131,14 +1124,14 @@ impl JsValue {
/// let undefined = JsValue::undefined();
///
/// let defined_result = defined_value
/// .map_or(Ok(JsValue::Boolean(true)), |v| v.add(&JsValue::from(5), &mut context))
/// .map_or(Ok(JsValue::new(true)), |v| v.add(&JsValue::from(5), &mut context))
/// .unwrap();
/// let undefined_result = undefined
/// .map_or(Ok(JsValue::Boolean(true)), |v| v.add(&JsValue::from(5), &mut context))
/// .map_or(Ok(JsValue::new(true)), |v| v.add(&JsValue::from(5), &mut context))
/// .unwrap();
///
/// assert_eq!(defined_result, JsValue::Integer(10));
/// assert_eq!(undefined_result, JsValue::Boolean(true));
/// assert_eq!(defined_result, JsValue::new(10));
/// assert_eq!(undefined_result, JsValue::new(true));
///
/// ```
#[inline]
Expand Down

0 comments on commit 81e92b6

Please sign in to comment.