Skip to content

Commit

Permalink
Merge c3dd937 into f3db18f
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 authored May 19, 2022
2 parents f3db18f + c3dd937 commit ff6113f
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 478 deletions.
130 changes: 67 additions & 63 deletions boa_engine/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,68 +91,72 @@ impl BuiltIn for Date {
fn init(context: &mut Context) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");

ConstructorBuilder::new(context, Self::constructor)
.name(Self::NAME)
.length(Self::LENGTH)
.method(getter_method!(get_date), "getDate", 0)
.method(getter_method!(get_day), "getDay", 0)
.method(getter_method!(get_full_year), "getFullYear", 0)
.method(getter_method!(get_hours), "getHours", 0)
.method(getter_method!(get_milliseconds), "getMilliseconds", 0)
.method(getter_method!(get_minutes), "getMinutes", 0)
.method(getter_method!(get_month), "getMonth", 0)
.method(getter_method!(get_seconds), "getSeconds", 0)
.method(getter_method!(get_time), "getTime", 0)
.method(getter_method!(get_year), "getYear", 0)
.method(Self::get_timezone_offset, "getTimezoneOffset", 0)
.method(getter_method!(get_utc_date), "getUTCDate", 0)
.method(getter_method!(get_utc_day), "getUTCDay", 0)
.method(getter_method!(get_utc_full_year), "getUTCFullYear", 0)
.method(getter_method!(get_utc_hours), "getUTCHours", 0)
.method(
getter_method!(get_utc_milliseconds),
"getUTCMilliseconds",
0,
)
.method(getter_method!(get_utc_minutes), "getUTCMinutes", 0)
.method(getter_method!(get_utc_month), "getUTCMonth", 0)
.method(getter_method!(get_utc_seconds), "getUTCSeconds", 0)
.method(Self::set_date, "setDate", 1)
.method(Self::set_full_year, "setFullYear", 3)
.method(Self::set_hours, "setHours", 4)
.method(Self::set_milliseconds, "setMilliseconds", 1)
.method(Self::set_minutes, "setMinutes", 3)
.method(Self::set_month, "setMonth", 2)
.method(Self::set_seconds, "setSeconds", 2)
.method(Self::set_year, "setYear", 1)
.method(Self::set_time, "setTime", 1)
.method(Self::set_utc_date, "setUTCDate", 1)
.method(Self::set_utc_full_year, "setUTCFullYear", 3)
.method(Self::set_utc_hours, "setUTCHours", 4)
.method(Self::set_utc_milliseconds, "setUTCMilliseconds", 1)
.method(Self::set_utc_minutes, "setUTCMinutes", 3)
.method(Self::set_utc_month, "setUTCMonth", 2)
.method(Self::set_utc_seconds, "setUTCSeconds", 2)
.method(Self::to_date_string, "toDateString", 0)
.method(getter_method!(to_gmt_string), "toGMTString", 0)
.method(Self::to_iso_string, "toISOString", 0)
.method(Self::to_json, "toJSON", 1)
// Locale strings
.method(Self::to_string, "toString", 0)
.method(Self::to_time_string, "toTimeString", 0)
.method(getter_method!(to_utc_string), "toUTCString", 0)
.method(getter_method!(value_of), "valueOf", 0)
.method(
Self::to_primitive,
(WellKnownSymbols::to_primitive(), "[Symbol.toPrimitive]"),
1,
)
.static_method(Self::now, "now", 0)
.static_method(Self::parse, "parse", 1)
.static_method(Self::utc, "UTC", 7)
.build()
.conv::<JsValue>()
.pipe(Some)
ConstructorBuilder::with_standard_constructor(
context,
Self::constructor,
context.intrinsics().constructors().date().clone(),
)
.name(Self::NAME)
.length(Self::LENGTH)
.method(getter_method!(get_date), "getDate", 0)
.method(getter_method!(get_day), "getDay", 0)
.method(getter_method!(get_full_year), "getFullYear", 0)
.method(getter_method!(get_hours), "getHours", 0)
.method(getter_method!(get_milliseconds), "getMilliseconds", 0)
.method(getter_method!(get_minutes), "getMinutes", 0)
.method(getter_method!(get_month), "getMonth", 0)
.method(getter_method!(get_seconds), "getSeconds", 0)
.method(getter_method!(get_time), "getTime", 0)
.method(getter_method!(get_year), "getYear", 0)
.method(Self::get_timezone_offset, "getTimezoneOffset", 0)
.method(getter_method!(get_utc_date), "getUTCDate", 0)
.method(getter_method!(get_utc_day), "getUTCDay", 0)
.method(getter_method!(get_utc_full_year), "getUTCFullYear", 0)
.method(getter_method!(get_utc_hours), "getUTCHours", 0)
.method(
getter_method!(get_utc_milliseconds),
"getUTCMilliseconds",
0,
)
.method(getter_method!(get_utc_minutes), "getUTCMinutes", 0)
.method(getter_method!(get_utc_month), "getUTCMonth", 0)
.method(getter_method!(get_utc_seconds), "getUTCSeconds", 0)
.method(Self::set_date, "setDate", 1)
.method(Self::set_full_year, "setFullYear", 3)
.method(Self::set_hours, "setHours", 4)
.method(Self::set_milliseconds, "setMilliseconds", 1)
.method(Self::set_minutes, "setMinutes", 3)
.method(Self::set_month, "setMonth", 2)
.method(Self::set_seconds, "setSeconds", 2)
.method(Self::set_year, "setYear", 1)
.method(Self::set_time, "setTime", 1)
.method(Self::set_utc_date, "setUTCDate", 1)
.method(Self::set_utc_full_year, "setUTCFullYear", 3)
.method(Self::set_utc_hours, "setUTCHours", 4)
.method(Self::set_utc_milliseconds, "setUTCMilliseconds", 1)
.method(Self::set_utc_minutes, "setUTCMinutes", 3)
.method(Self::set_utc_month, "setUTCMonth", 2)
.method(Self::set_utc_seconds, "setUTCSeconds", 2)
.method(Self::to_date_string, "toDateString", 0)
.method(getter_method!(to_gmt_string), "toGMTString", 0)
.method(Self::to_iso_string, "toISOString", 0)
.method(Self::to_json, "toJSON", 1)
// Locale strings
.method(Self::to_string, "toString", 0)
.method(Self::to_time_string, "toTimeString", 0)
.method(getter_method!(to_utc_string), "toUTCString", 0)
.method(getter_method!(value_of), "valueOf", 0)
.method(
Self::to_primitive,
(WellKnownSymbols::to_primitive(), "[Symbol.toPrimitive]"),
1,
)
.static_method(Self::now, "now", 0)
.static_method(Self::parse, "parse", 1)
.static_method(Self::utc, "UTC", 7)
.build()
.conv::<JsValue>()
.pipe(Some)
}
}

Expand Down Expand Up @@ -337,7 +341,7 @@ impl Date {
Ok(Self::make_date_string())
} else {
let prototype =
get_prototype_from_constructor(new_target, StandardConstructors::object, context)?;
get_prototype_from_constructor(new_target, StandardConstructors::date, context)?;
Ok(if args.is_empty() {
Self::make_date_now(prototype)
} else if args.len() == 1 {
Expand Down
60 changes: 24 additions & 36 deletions boa_engine/src/builtins/intl/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn best_avail_loc() {
);

let locale_part = "fr".to_string();
let no_extensions_locale = JsString::new(locale_part.clone() + &"-CA".to_string());
let no_extensions_locale = JsString::new(locale_part.clone() + "-CA");
let available_locales = vec![JsString::new(locale_part.clone())];
assert_eq!(
best_available_locale(&available_locales, &no_extensions_locale,),
Expand All @@ -38,7 +38,7 @@ fn best_avail_loc() {
let ja_kana_t = JsString::new("ja-Kana-JP-t");
let ja_kana = JsString::new("ja-Kana-JP");
let no_extensions_locale = JsString::new("ja-Kana-JP-t-it-latn-it");
let available_locales = vec![ja_kana_t.clone(), ja_kana.clone()];
let available_locales = vec![ja_kana_t, ja_kana.clone()];
assert_eq!(
best_available_locale(&available_locales, &no_extensions_locale,),
Some(ja_kana)
Expand Down Expand Up @@ -108,7 +108,7 @@ fn insert_unicode_ext() {
fn uni_ext_comp() {
let ext = JsString::new("-u-ca-japanese-hc-h12");
let components = unicode_extension_components(&ext);
assert_eq!(components.attributes.is_empty(), true);
assert!(components.attributes.is_empty());
assert_eq!(components.keywords.len(), 2);
assert_eq!(components.keywords[0].key, "ca");
assert_eq!(components.keywords[0].value, "japanese");
Expand All @@ -126,7 +126,7 @@ fn uni_ext_comp() {

let ext = JsString::new("-u-ca-buddhist-kk-nu-thai");
let components = unicode_extension_components(&ext);
assert_eq!(components.attributes.is_empty(), true);
assert!(components.attributes.is_empty());
assert_eq!(components.keywords.len(), 3);
assert_eq!(components.keywords[0].key, "ca");
assert_eq!(components.keywords[0].value, "buddhist");
Expand All @@ -137,7 +137,7 @@ fn uni_ext_comp() {

let ext = JsString::new("-u-ca-islamic-civil");
let components = unicode_extension_components(&ext);
assert_eq!(components.attributes.is_empty(), true);
assert!(components.attributes.is_empty());
assert_eq!(components.keywords.len(), 1);
assert_eq!(components.keywords[0].key, "ca");
assert_eq!(components.keywords[0].value, "islamic-civil");
Expand Down Expand Up @@ -167,7 +167,7 @@ fn locale_resolution() {
);
assert_eq!(locale_record.locale, default_locale());
assert_eq!(locale_record.data_locale, default_locale());
assert_eq!(locale_record.properties.is_empty(), true);
assert!(locale_record.properties.is_empty());

// test best fit
let available_locales = Vec::<JsString>::new();
Expand All @@ -189,7 +189,7 @@ fn locale_resolution() {
);
assert_eq!(locale_record.locale, default_locale());
assert_eq!(locale_record.data_locale, default_locale());
assert_eq!(locale_record.properties.is_empty(), true);
assert!(locale_record.properties.is_empty());

// available: [es-ES], requested: [es-ES]
let available_locales = vec![JsString::new("es-ES")];
Expand All @@ -211,7 +211,7 @@ fn locale_resolution() {
);
assert_eq!(locale_record.locale, "es-ES");
assert_eq!(locale_record.data_locale, "es-ES");
assert_eq!(locale_record.properties.is_empty(), true);
assert!(locale_record.properties.is_empty());

// available: [zh-CN], requested: []
let available_locales = vec![JsString::new("zh-CN")];
Expand All @@ -233,7 +233,7 @@ fn locale_resolution() {
);
assert_eq!(locale_record.locale, default_locale());
assert_eq!(locale_record.data_locale, default_locale());
assert_eq!(locale_record.properties.is_empty(), true);
assert!(locale_record.properties.is_empty());
}

#[test]
Expand Down Expand Up @@ -319,7 +319,7 @@ fn get_opt() {
let other_locale_str = JsString::new("de-DE");
let values = vec![other_locale_str];
options_obj
.set("Locale", locale_value.clone(), true, &mut context)
.set("Locale", locale_value, true, &mut context)
.expect("Setting a property should not fail");
let option_type = GetOptionType::String;
let get_option_result = get_option(
Expand All @@ -330,7 +330,7 @@ fn get_opt() {
&fallback,
&mut context,
);
assert_eq!(get_option_result.is_err(), true);
assert!(get_option_result.is_err());

let value = JsValue::undefined();
let minimum = 1.0;
Expand All @@ -345,21 +345,21 @@ fn get_opt() {
let maximum = 10.0;
let fallback = Some(5.0);
let get_option_result = default_number_option(&value, minimum, maximum, fallback, &mut context);
assert_eq!(get_option_result.is_err(), true);
assert!(get_option_result.is_err());

let value = JsValue::new(0);
let minimum = 1.0;
let maximum = 10.0;
let fallback = Some(5.0);
let get_option_result = default_number_option(&value, minimum, maximum, fallback, &mut context);
assert_eq!(get_option_result.is_err(), true);
assert!(get_option_result.is_err());

let value = JsValue::new(11);
let minimum = 1.0;
let maximum = 10.0;
let fallback = Some(5.0);
let get_option_result = default_number_option(&value, minimum, maximum, fallback, &mut context);
assert_eq!(get_option_result.is_err(), true);
assert!(get_option_result.is_err());

let value_f64 = 7.0;
let value = JsValue::new(value_f64);
Expand All @@ -375,34 +375,22 @@ fn get_opt() {
let maximum = 10.0;
let fallback_val = 5.0;
let fallback = Some(fallback_val);
let get_option_result = get_number_option(
&options,
&property,
minimum,
maximum,
fallback,
&mut context,
);
let get_option_result =
get_number_option(&options, property, minimum, maximum, fallback, &mut context);
assert_eq!(get_option_result, Ok(fallback));

let options = JsObject::empty();
let value_f64 = 8.0;
let value = JsValue::new(value_f64);
let property = "fractionalSecondDigits";
options
.set(property, value.clone(), true, &mut context)
.set(property, value, true, &mut context)
.expect("Setting a property should not fail");
let minimum = 1.0;
let maximum = 10.0;
let fallback = Some(5.0);
let get_option_result = get_number_option(
&options,
&property,
minimum,
maximum,
fallback,
&mut context,
);
let get_option_result =
get_number_option(&options, property, minimum, maximum, fallback, &mut context);
assert_eq!(get_option_result, Ok(Some(value_f64)));
}

Expand All @@ -420,7 +408,7 @@ fn to_date_time_opts() {
&DateTimeReqs::Date,
&mut context,
);
assert_eq!(date_time_opts.is_err(), true);
assert!(date_time_opts.is_err());

let options_obj = JsObject::empty();
options_obj
Expand All @@ -432,7 +420,7 @@ fn to_date_time_opts() {
&DateTimeReqs::Time,
&mut context,
);
assert_eq!(date_time_opts.is_err(), true);
assert!(date_time_opts.is_err());

let date_time_opts = to_date_time_options(
&JsValue::undefined(),
Expand All @@ -453,7 +441,7 @@ fn to_date_time_opts() {
);
assert_eq!(
date_time_opts.get("day", &mut context),
Ok(numeric_jsstring.clone())
Ok(numeric_jsstring)
);

let date_time_opts = to_date_time_options(
Expand All @@ -475,7 +463,7 @@ fn to_date_time_opts() {
);
assert_eq!(
date_time_opts.get("second", &mut context),
Ok(numeric_jsstring.clone())
Ok(numeric_jsstring)
);

let date_time_opts = to_date_time_options(
Expand Down Expand Up @@ -509,6 +497,6 @@ fn to_date_time_opts() {
);
assert_eq!(
date_time_opts.get("second", &mut context),
Ok(numeric_jsstring.clone())
Ok(numeric_jsstring)
);
}
24 changes: 12 additions & 12 deletions boa_engine/src/builtins/typed_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3438,22 +3438,22 @@ impl TypedArrayKind {
#[inline]
pub(crate) const fn name(&self) -> &str {
match self {
TypedArrayKind::Int8 => "Int8Array",
TypedArrayKind::Uint8 => "Uint8Array",
TypedArrayKind::Uint8Clamped => "Uint8ClampedArray",
TypedArrayKind::Int16 => "Int16Array",
TypedArrayKind::Uint16 => "Uint16Array",
TypedArrayKind::Int32 => "Int32Array",
TypedArrayKind::Uint32 => "Uint32Array",
TypedArrayKind::BigInt64 => "BigInt64Array",
TypedArrayKind::BigUint64 => "BigUint64Array",
TypedArrayKind::Float32 => "Float32Array",
TypedArrayKind::Float64 => "Float64Array",
Self::Int8 => "Int8Array",
Self::Uint8 => "Uint8Array",
Self::Uint8Clamped => "Uint8ClampedArray",
Self::Int16 => "Int16Array",
Self::Uint16 => "Uint16Array",
Self::Int32 => "Int32Array",
Self::Uint32 => "Uint32Array",
Self::BigInt64 => "BigInt64Array",
Self::BigUint64 => "BigUint64Array",
Self::Float32 => "Float32Array",
Self::Float64 => "Float64Array",
}
}

pub(crate) fn is_big_int_element_type(self) -> bool {
matches!(self, TypedArrayKind::BigUint64 | TypedArrayKind::BigInt64)
matches!(self, Self::BigUint64 | Self::BigInt64)
}
}

Expand Down
Loading

0 comments on commit ff6113f

Please sign in to comment.