Skip to content

Commit

Permalink
Replace cfg(test) with allow(unused)
Browse files Browse the repository at this point in the history
  • Loading branch information
NorbertGarfield committed May 13, 2022
1 parent bd5287d commit 051d3c9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 136 deletions.
30 changes: 15 additions & 15 deletions boa_engine/src/builtins/intl/date_time_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ impl DateTimeFormat {
}
}

/// Enumeration for `required` and `defaults` arguments in `toDateTimeOptions` subroutine
/// `required` can take Date/Time/Any values, `defaults` can take Date/Time/All
/// `Any` and `All` are merged into one `AnyAll` value.
#[cfg(test)]
/// Represents the `required` and `defaults` arguments in the abstract operation
/// `toDateTimeOptions`.
///
/// Since `required` and `defaults` differ only in the `any` and `all` variants,
/// we combine both in a single variant `AnyAll`.
#[allow(unused)]
#[derive(Debug, PartialEq)]
pub(crate) enum DateTimeReqs {
Date,
Expand All @@ -133,7 +135,7 @@ pub(crate) enum DateTimeReqs {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-todatetimeoptions
#[cfg(test)]
#[allow(unused)]
pub(crate) fn to_date_time_options(
options: &JsValue,
required: &DateTimeReqs,
Expand All @@ -144,17 +146,17 @@ pub(crate) fn to_date_time_options(
// otherwise let options be ? ToObject(options).
// 2. Let options be ! OrdinaryObjectCreate(options).
let options = if options.is_undefined() {
JsObject::from_proto_and_data(None, ObjectData::ordinary())
None
} else {
let opt = options.to_object(context)?;
JsObject::from_proto_and_data(opt, ObjectData::ordinary())
Some(options.to_object(context)?)
};
let options = JsObject::from_proto_and_data(options, ObjectData::ordinary());

// 3. Let needDefaults be true.
let mut need_defaults = true;

// 4. If required is "date" or "any", then
if [DateTimeReqs::Date, DateTimeReqs::AnyAll].contains(&required) {
if [DateTimeReqs::Date, DateTimeReqs::AnyAll].contains(required) {
// a. For each property name prop of « "weekday", "year", "month", "day" », do
for property in ["weekday", "year", "month", "day"] {
// i. Let value be ? Get(options, prop).
Expand All @@ -168,7 +170,7 @@ pub(crate) fn to_date_time_options(
}

// 5. If required is "time" or "any", then
if [DateTimeReqs::Time, DateTimeReqs::AnyAll].contains(&required) {
if [DateTimeReqs::Time, DateTimeReqs::AnyAll].contains(required) {
// a. For each property name prop of « "dayPeriod", "hour", "minute", "second",
// "fractionalSecondDigits" », do
for property in [
Expand All @@ -189,9 +191,7 @@ pub(crate) fn to_date_time_options(
}

// 6. Let dateStyle be ? Get(options, "dateStyle").
let date_style = options
.get("dateStyle", context)
.unwrap_or_else(|_| JsValue::undefined());
let date_style = options.get("dateStyle", context)?;

// 7. Let timeStyle be ? Get(options, "timeStyle").
let time_style = options.get("timeStyle", context)?;
Expand All @@ -214,7 +214,7 @@ pub(crate) fn to_date_time_options(
}

// 11. If needDefaults is true and defaults is either "date" or "all", then
if need_defaults && [DateTimeReqs::Date, DateTimeReqs::AnyAll].contains(&defaults) {
if need_defaults && [DateTimeReqs::Date, DateTimeReqs::AnyAll].contains(defaults) {
// a. For each property name prop of « "year", "month", "day" », do
for property in ["year", "month", "day"] {
// i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric").
Expand All @@ -223,7 +223,7 @@ pub(crate) fn to_date_time_options(
}

// 12. If needDefaults is true and defaults is either "time" or "all", then
if need_defaults && [DateTimeReqs::Time, DateTimeReqs::AnyAll].contains(&defaults) {
if need_defaults && [DateTimeReqs::Time, DateTimeReqs::AnyAll].contains(defaults) {
// a. For each property name prop of « "hour", "minute", "second" », do
for property in ["hour", "minute", "second"] {
// i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric").
Expand Down
15 changes: 6 additions & 9 deletions boa_engine/src/builtins/intl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
use crate::{
builtins::intl::date_time_format::DateTimeFormat,
builtins::{Array, BuiltIn, JsArgs},
object::ObjectInitializer,
object::{JsObject, ObjectInitializer},
property::Attribute,
symbol::WellKnownSymbols,
Context, JsResult, JsString, JsValue,
};

#[cfg(test)]
use crate::object::JsObject;

pub mod date_time_format;
#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -657,7 +654,7 @@ fn resolve_locale(
result
}

#[cfg(test)]
#[allow(unused)]
pub(crate) enum GetOptionType {
String,
Boolean,
Expand All @@ -672,7 +669,7 @@ pub(crate) enum GetOptionType {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-getoption
#[cfg(test)]
#[allow(unused)]
pub(crate) fn get_option(
options: &JsObject,
property: &str,
Expand Down Expand Up @@ -720,7 +717,7 @@ pub(crate) fn get_option(
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-getnumberoption
#[cfg(test)]
#[allow(unused)]
pub(crate) fn get_number_option(
options: &JsObject,
property: &str,
Expand All @@ -744,7 +741,7 @@ pub(crate) fn get_number_option(
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-defaultnumberoption
#[cfg(test)]
#[allow(unused)]
pub(crate) fn default_number_option(
value: &JsValue,
minimum: f64,
Expand All @@ -761,7 +758,7 @@ pub(crate) fn default_number_option(
let value = value.to_number(context)?;

// 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception.
if value.is_nan() || value.lt(&minimum) || value.gt(&maximum) {
if value.is_nan() || value < minimum || value > maximum {
return context.throw_range_error("DefaultNumberOption: value is out of range.");
}

Expand Down
Loading

0 comments on commit 051d3c9

Please sign in to comment.