Browse Source

Fix rust 1.75 lints (#3540)

pull/3541/head
raskad 11 months ago committed by GitHub
parent
commit
6ac435ffea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      cli/src/debug/function.rs
  2. 2
      cli/src/debug/object.rs
  3. 6
      core/engine/src/builtins/array/mod.rs
  4. 2
      core/engine/src/builtins/boolean/mod.rs
  5. 2
      core/engine/src/builtins/date/mod.rs
  6. 1
      core/engine/src/builtins/intl/collator/mod.rs
  7. 4
      core/engine/src/builtins/intl/date_time_format.rs
  8. 6
      core/engine/src/builtins/iterable/async_from_sync_iterator.rs
  9. 2
      core/engine/src/builtins/json/mod.rs
  10. 8
      core/engine/src/builtins/number/globals.rs
  11. 12
      core/engine/src/builtins/number/mod.rs
  12. 10
      core/engine/src/builtins/object/mod.rs
  13. 22
      core/engine/src/builtins/reflect/mod.rs
  14. 2
      core/engine/src/builtins/regexp/mod.rs
  15. 2
      core/engine/src/builtins/string/mod.rs
  16. 4
      core/engine/src/builtins/symbol/mod.rs
  17. 2
      core/engine/src/builtins/temporal/duration/mod.rs
  18. 4
      core/engine/src/builtins/typed_array/builtin.rs
  19. 2
      core/engine/src/builtins/weak/weak_ref.rs
  20. 5
      core/engine/src/module/synthetic.rs
  21. 2
      core/engine/src/native_function.rs
  22. 2
      core/engine/src/object/internal_methods/mod.rs
  23. 4
      core/engine/src/small_map/mod.rs
  24. 14
      core/engine/src/vm/flowgraph/graph.rs
  25. 4
      core/engine/src/vm/opcode/call/mod.rs
  26. 3
      core/parser/src/lib.rs
  27. 52
      core/parser/src/parser/expression/assignment/arrow_function.rs
  28. 48
      core/parser/src/parser/expression/assignment/async_arrow_function.rs
  29. 12
      core/runtime/src/console/mod.rs
  30. 7
      core/temporal/src/components/duration.rs
  31. 2
      examples/src/bin/classes.rs
  32. 6
      examples/src/bin/jsarray.rs
  33. 2
      examples/src/bin/jstypedarray.rs
  34. 4
      tests/tester/src/exec/js262.rs

4
cli/src/debug/function.rs

@ -52,7 +52,7 @@ fn flowgraph_parse_direction_option(value: &JsValue) -> JsResult<Direction> {
/// Get functions instruction flowgraph
fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
let Some(value) = args.first() else {
return Err(JsNativeError::typ()
.with_message("expected function argument")
.into());
@ -100,7 +100,7 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResu
}
fn bytecode(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
let Some(value) = args.first() else {
return Err(JsNativeError::typ()
.with_message("expected function argument")
.into());

2
cli/src/debug/object.rs

@ -5,7 +5,7 @@ use boa_engine::{
/// Returns objects pointer in memory.
fn id(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
let Some(value) = args.first() else {
return Err(JsNativeError::typ()
.with_message("expected object argument")
.into());

6
core/engine/src/builtins/array/mod.rs

@ -1769,7 +1769,7 @@ impl Array {
let mut depth_num = 1;
// 4. If depth is not undefined, then set depthNum to IntegerOrInfinity(depth)
if let Some(depth) = args.get(0) {
if let Some(depth) = args.first() {
// a. Set depthNum to ? ToIntegerOrInfinity(depth).
// b. If depthNum < 0, set depthNum to 0.
match depth.to_integer_or_infinity(context)? {
@ -2270,7 +2270,7 @@ impl Array {
// 2. Let len be ? LengthOfArrayLike(O).
let len = o.length_of_array_like(context)?;
let start = args.get(0);
let start = args.first();
let delete_count = args.get(1);
let items = args.get(2..).unwrap_or_default();
@ -2410,7 +2410,7 @@ impl Array {
// 2. Let len be ? LengthOfArrayLike(O).
let len = o.length_of_array_like(context)?;
let start = args.get(0);
let start = args.first();
let skip_count = args.get(1);
let items = args.get(2..).unwrap_or_default();

2
core/engine/src/builtins/boolean/mod.rs

@ -64,7 +64,7 @@ impl BuiltInConstructor for Boolean {
context: &mut Context,
) -> JsResult<JsValue> {
// Get the argument, if any
let data = args.get(0).map_or(false, JsValue::to_boolean);
let data = args.first().map_or(false, JsValue::to_boolean);
if new_target.is_undefined() {
return Ok(JsValue::new(data));
}

2
core/engine/src/builtins/date/mod.rs

@ -448,7 +448,7 @@ impl Date {
// This method is implementation-defined and discouraged, so we just require the same format as the string
// constructor.
let date = some_or_nan!(args.get(0));
let date = some_or_nan!(args.first());
let date = date.to_string(context)?;

1
core/engine/src/builtins/intl/collator/mod.rs

@ -43,6 +43,7 @@ mod options;
pub(crate) use options::*;
#[derive(Debug, Finalize, JsData)]
#[allow(clippy::struct_field_names)]
pub(crate) struct Collator {
locale: Locale,
collation: Value,

4
core/engine/src/builtins/intl/date_time_format.rs

@ -42,7 +42,7 @@ impl OptionType for HourCycle {
/// JavaScript `Intl.DateTimeFormat` object.
#[derive(Debug, Clone, Trace, Finalize, JsData)]
pub(crate) struct DateTimeFormat {
initialized_date_time_format: bool,
initialized: bool,
locale: JsString,
calendar: JsString,
numbering_system: JsString,
@ -125,7 +125,7 @@ impl BuiltInConstructor for DateTimeFormat {
context.root_shape(),
prototype,
Self {
initialized_date_time_format: true,
initialized: true,
locale: js_string!("en-US"),
calendar: js_string!("gregory"),
numbering_system: js_string!("arab"),

6
core/engine/src/builtins/iterable/async_from_sync_iterator.rs

@ -121,7 +121,7 @@ impl AsyncFromSyncIterator {
let result = next
.call(
&iterator.into(),
args.get(0).map_or(&[], std::slice::from_ref),
args.first().map_or(&[], std::slice::from_ref),
context,
)
.and_then(IteratorResult::from_value);
@ -164,7 +164,7 @@ impl AsyncFromSyncIterator {
// 6. IfAbruptRejectPromise(return, promiseCapability).
let r#return = if_abrupt_reject_promise!(r#return, promise_capability, context);
let result = match (r#return, args.get(0)) {
let result = match (r#return, args.first()) {
// 7. If return is undefined, then
(None, _) => {
// a. Let iterResult be CreateIterResultObject(value, true).
@ -234,7 +234,7 @@ impl AsyncFromSyncIterator {
// 6. IfAbruptRejectPromise(throw, promiseCapability).
let throw = if_abrupt_reject_promise!(throw, promise_capability, context);
let result = match (throw, args.get(0)) {
let result = match (throw, args.first()) {
// 7. If throw is undefined, then
(None, _) => {
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »).

2
core/engine/src/builtins/json/mod.rs

@ -84,7 +84,7 @@ impl Json {
pub(crate) fn parse(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let jsonString be ? ToString(text).
let json_string = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_string(context)?

8
core/engine/src/builtins/number/globals.rs

@ -26,7 +26,7 @@ use num_traits::Num;
/// [spec]: https://tc39.es/ecma262/#sec-isfinite-number
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite
fn is_finite(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
if let Some(value) = args.get(0) {
if let Some(value) = args.first() {
let number = value.to_number(context)?;
Ok(number.is_finite().into())
} else {
@ -68,7 +68,7 @@ impl BuiltInObject for IsFinite {
/// [spec]: https://tc39.es/ecma262/#sec-isnan-number
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
pub(crate) fn is_nan(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
if let Some(value) = args.get(0) {
if let Some(value) = args.first() {
let number = value.to_number(context)?;
Ok(number.is_nan().into())
} else {
@ -110,7 +110,7 @@ impl BuiltInObject for IsNaN {
/// [spec]: https://tc39.es/ecma262/#sec-parseint-string-radix
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
pub(crate) fn parse_int(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
if let (Some(val), radix) = (args.get(0), args.get_or_undefined(1)) {
if let (Some(val), radix) = (args.first(), args.get_or_undefined(1)) {
// 1. Let inputString be ? ToString(string).
let input_string = val.to_string(context)?;
@ -252,7 +252,7 @@ pub(crate) fn parse_float(
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
if let Some(val) = args.get(0) {
if let Some(val) = args.first() {
// TODO: parse float with optimal utf16 algorithm
let input_string = val.to_string(context)?.to_std_string_escaped();
let s = input_string.trim_start_matches(is_trimmable_whitespace);

12
core/engine/src/builtins/number/mod.rs

@ -117,7 +117,7 @@ impl BuiltInConstructor for Number {
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
let data = match args.get(0) {
let data = match args.first() {
Some(value) => value.to_numeric_number(context)?,
None => 0.0,
};
@ -221,7 +221,7 @@ impl Number {
) -> JsResult<JsValue> {
// 1. Let x be ? thisNumberValue(this value).
let this_num = Self::this_number_value(this)?;
let precision = match args.get(0) {
let precision = match args.first() {
None | Some(JsValue::Undefined) => None,
// 2. Let f be ? ToIntegerOrInfinity(fractionDigits).
Some(n) => Some(n.to_integer_or_infinity(context)?),
@ -748,7 +748,7 @@ impl Number {
// 1. If number is not a Number, return false.
// 2. If number is not finite, return false.
// 3. Otherwise, return true.
Ok(JsValue::new(args.get(0).map_or(false, |val| match val {
Ok(JsValue::new(args.first().map_or(false, |val| match val {
JsValue::Integer(_) => true,
JsValue::Rational(number) => number.is_finite(),
_ => false,
@ -771,7 +771,7 @@ impl Number {
args: &[JsValue],
_ctx: &mut Context,
) -> JsResult<JsValue> {
Ok(args.get(0).map_or(false, Self::is_integer).into())
Ok(args.first().map_or(false, Self::is_integer).into())
}
/// `Number.isNaN( number )`
@ -795,7 +795,7 @@ impl Number {
_ctx: &mut Context,
) -> JsResult<JsValue> {
Ok(JsValue::new(
if let Some(&JsValue::Rational(number)) = args.get(0) {
if let Some(&JsValue::Rational(number)) = args.first() {
number.is_nan()
} else {
false
@ -823,7 +823,7 @@ impl Number {
args: &[JsValue],
_ctx: &mut Context,
) -> JsResult<JsValue> {
Ok(JsValue::new(match args.get(0) {
Ok(JsValue::new(match args.first() {
Some(JsValue::Integer(_)) => true,
Some(JsValue::Rational(number)) if Self::is_float_integer(*number) => {
number.abs() <= Self::MAX_SAFE_INTEGER

10
core/engine/src/builtins/object/mod.rs

@ -676,7 +676,7 @@ impl OrdinaryObject {
// 1. Set O to ? RequireObjectCoercible(O).
let o = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.require_object_coercible()?
@ -945,7 +945,7 @@ impl OrdinaryObject {
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
let Some(key) = args.get(0) else {
let Some(key) = args.first() else {
return Ok(JsValue::new(false));
};
@ -1030,7 +1030,7 @@ impl OrdinaryObject {
pub fn keys(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_object(context)?;
@ -1055,7 +1055,7 @@ impl OrdinaryObject {
pub fn values(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_object(context)?;
@ -1084,7 +1084,7 @@ impl OrdinaryObject {
pub fn entries(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_object(context)?;

22
core/engine/src/builtins/reflect/mod.rs

@ -84,7 +84,7 @@ impl Reflect {
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply
pub(crate) fn apply(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be a function"))?;
let this_arg = args.get_or_undefined(1);
@ -153,7 +153,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
let key = args.get_or_undefined(1).to_property_key(context)?;
@ -188,7 +188,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
let key = args.get_or_undefined(1).to_property_key(context)?;
@ -209,7 +209,7 @@ impl Reflect {
pub(crate) fn get(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. If Type(target) is not Object, throw a TypeError exception.
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
// 2. Let key be ? ToPropertyKey(propertyKey).
@ -267,7 +267,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
Ok(target
@ -285,7 +285,7 @@ impl Reflect {
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has
pub(crate) fn has(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
let key = args
@ -312,7 +312,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
Ok(target
@ -334,7 +334,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
@ -361,7 +361,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
@ -380,7 +380,7 @@ impl Reflect {
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set
pub(crate) fn set(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
let key = args.get_or_undefined(1).to_property_key(context)?;
@ -414,7 +414,7 @@ impl Reflect {
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(|| JsNativeError::typ().with_message("target must be an object"))?;
let proto = match args.get_or_undefined(1) {

2
core/engine/src/builtins/regexp/mod.rs

@ -760,7 +760,7 @@ impl RegExp {
// 3. Let string be ? ToString(S).
let arg_str = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_string(context)?;

2
core/engine/src/builtins/string/mod.rs

@ -209,7 +209,7 @@ impl BuiltInConstructor for String {
) -> JsResult<JsValue> {
// This value is used by console.log and other routines to match Object type
// to its Javascript Identifier (global constructor method name)
let string = match args.get(0) {
let string = match args.first() {
// 2. Else,
// a. If NewTarget is undefined and Type(value) is Symbol, return SymbolDescriptiveString(value).
Some(JsValue::Symbol(ref sym)) if new_target.is_undefined() => {

4
core/engine/src/builtins/symbol/mod.rs

@ -213,7 +213,7 @@ impl BuiltInConstructor for Symbol {
// 2. If description is undefined, let descString be undefined.
// 3. Else, let descString be ? ToString(description).
let description = match args.get(0) {
let description = match args.first() {
Some(value) if !value.is_undefined() => Some(value.to_string(context)?),
_ => None,
};
@ -315,7 +315,7 @@ impl Symbol {
pub(crate) fn for_(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let stringKey be ? ToString(key).
let string_key = args
.get(0)
.first()
.cloned()
.unwrap_or_default()
.to_string(context)?;

2
core/engine/src/builtins/temporal/duration/mod.rs

@ -186,7 +186,7 @@ impl BuiltInConstructor for Duration {
// 2. If years is undefined, let y be 0; else let y be ? ToIntegerIfIntegral(years).
let years = f64::from(
args.get(0)
args.first()
.map_or(Ok(0), |y| to_integer_if_integral(y, context))?,
);

4
core/engine/src/builtins/typed_array/builtin.rs

@ -2510,7 +2510,7 @@ impl BuiltinTypedArray {
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception.
let compare_fn = match args.get(0) {
let compare_fn = match args.first() {
None | Some(JsValue::Undefined) => None,
Some(JsValue::Object(obj)) if obj.is_callable() => Some(obj),
_ => {
@ -2577,7 +2577,7 @@ impl BuiltinTypedArray {
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception.
let compare_fn = match args.get(0) {
let compare_fn = match args.first() {
None | Some(JsValue::Undefined) => None,
Some(JsValue::Object(obj)) if obj.is_callable() => Some(obj),
_ => {

2
core/engine/src/builtins/weak/weak_ref.rs

@ -73,7 +73,7 @@ impl BuiltInConstructor for WeakRef {
}
// 2. If target is not an Object, throw a TypeError exception.
let target = args.get(0).and_then(JsValue::as_object).ok_or_else(|| {
let target = args.first().and_then(JsValue::as_object).ok_or_else(|| {
JsNativeError::typ().with_message(format!(
"WeakRef: expected target argument of type `object`, got target of type `{}`",
args.get_or_undefined(0).type_of()

5
core/engine/src/module/synthetic.rs

@ -97,7 +97,10 @@ impl SyntheticModuleInitializer {
{
// SAFETY: The caller must ensure the invariants of the closure hold.
unsafe {
Self::from_closure_with_captures(move |module, _, context| closure(module, context), ())
Self::from_closure_with_captures(
move |module, (), context| closure(module, context),
(),
)
}
}

2
core/engine/src/native_function.rs

@ -275,7 +275,7 @@ impl NativeFunction {
// SAFETY: The caller must ensure the invariants of the closure hold.
unsafe {
Self::from_closure_with_captures(
move |this, args, _, context| closure(this, args, context),
move |this, args, (), context| closure(this, args, context),
(),
)
}

2
core/engine/src/object/internal_methods/mod.rs

@ -324,7 +324,7 @@ pub(crate) static ORDINARY_INTERNAL_METHODS: InternalObjectMethods = InternalObj
///
/// For a guide on how to implement exotic internal methods, see `ORDINARY_INTERNAL_METHODS`.
#[derive(Debug, Clone, Copy)]
#[allow(clippy::type_complexity)]
#[allow(clippy::type_complexity, clippy::struct_field_names)]
pub struct InternalObjectMethods {
pub(crate) __get_prototype_of__: fn(&JsObject, &mut Context) -> JsResult<JsPrototype>,
pub(crate) __set_prototype_of__: fn(&JsObject, JsPrototype, &mut Context) -> JsResult<bool>,

4
core/engine/src/small_map/mod.rs

@ -173,6 +173,7 @@ impl<K, V, const ARRAY_SIZE: usize> SmallMap<K, V, ARRAY_SIZE> {
///
/// The supplied key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
#[allow(clippy::map_identity)]
pub fn get_key_value<Q: ?Sized>(&self, key: &Q) -> Option<(&K, &V)>
where
K: Borrow<Q> + Ord + Eq,
@ -371,6 +372,7 @@ impl<'a, K, V, const ARRAY_SIZE: usize> IntoIterator for &'a SmallMap<K, V, ARRA
impl<'a, K, V> Iterator for Iter<'a, K, V> {
type Item = (&'a K, &'a V);
#[allow(clippy::map_identity)]
fn next(&mut self) -> Option<Self::Item> {
match &mut self.inner {
InnerIter::Inline(i) => i.next().map(|(k, v)| (k, v)),
@ -385,6 +387,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
}
}
#[allow(clippy::map_identity)]
fn last(self) -> Option<(&'a K, &'a V)> {
match self.inner {
InnerIter::Inline(i) => i.last().map(|(k, v)| (k, v)),
@ -396,6 +399,7 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
impl<K, V> FusedIterator for Iter<'_, K, V> {}
impl<'a, K: 'a, V: 'a> DoubleEndedIterator for Iter<'a, K, V> {
#[allow(clippy::map_identity)]
fn next_back(&mut self) -> Option<(&'a K, &'a V)> {
match &mut self.inner {
InnerIter::Inline(i) => i.next_back().map(|(k, v)| (k, v)),

14
core/engine/src/vm/flowgraph/graph.rs

@ -1,9 +1,5 @@
use std::{
collections::hash_map::RandomState,
hash::{BuildHasher, Hash, Hasher},
};
use crate::vm::flowgraph::{Color, Edge, EdgeStyle, EdgeType, Node, NodeShape};
use std::{collections::hash_map::RandomState, hash::BuildHasher};
/// This represents the direction of flow in the flowgraph.
#[derive(Debug, Clone, Copy)]
@ -100,9 +96,7 @@ impl SubGraph {
/// Format into the graphviz format.
fn graphviz_format(&self, result: &mut String, prefix: &str) {
let mut hasher = RandomState::new().build_hasher();
self.label.hash(&mut hasher);
let label = format!("{}", hasher.finish());
let label = format!("{}", RandomState::new().hash_one(&self.label));
result.push_str(&format!("\tsubgraph cluster_{prefix}_{label} {{\n"));
result.push_str("\t\tstyle = filled;\n");
result.push_str(&format!(
@ -164,9 +158,7 @@ impl SubGraph {
/// Format into the mermaid format.
fn mermaid_format(&self, result: &mut String, prefix: &str) {
let mut hasher = RandomState::new().build_hasher();
self.label.hash(&mut hasher);
let label = format!("{}", hasher.finish());
let label = format!("{}", RandomState::new().hash_one(&self.label));
let rankdir = match self.direction {
Direction::TopToBottom => "TB",
Direction::BottomToTop => "BT",

4
core/engine/src/vm/opcode/call/mod.rs

@ -37,7 +37,7 @@ impl CallEval {
let arguments = context.vm.pop_n_values(argument_count);
let _func = context.vm.pop();
let _this = context.vm.pop();
if let Some(x) = arguments.get(0) {
if let Some(x) = arguments.first() {
// i. Let argList be ? ArgumentListEvaluation of arguments.
// ii. If argList has no elements, return undefined.
// iii. Let evalArg be the first element of argList.
@ -130,7 +130,7 @@ impl Operation for CallEvalSpread {
if JsObject::equals(object, &eval) {
let _func = context.vm.pop();
let _this = context.vm.pop();
if let Some(x) = arguments.get(0) {
if let Some(x) = arguments.first() {
// i. Let argList be ? ArgumentListEvaluation of arguments.
// ii. If argList has no elements, return undefined.
// iii. Let evalArg be the first element of argList.

3
core/parser/src/lib.rs

@ -21,7 +21,8 @@
clippy::too_many_lines,
clippy::cognitive_complexity,
clippy::let_unit_value,
clippy::redundant_pub_crate
clippy::redundant_pub_crate,
clippy::struct_field_names
)]
pub mod error;

52
core/parser/src/parser/expression/assignment/arrow_function.rs

@ -81,33 +81,31 @@ where
let _timer = Profiler::global().start_event("ArrowFunction", "Parsing");
let next_token = cursor.peek(0, interner).or_abrupt()?;
let (params, params_start_position) = if next_token.kind()
== &TokenKind::Punctuator(Punctuator::OpenParen)
{
// CoverParenthesizedExpressionAndArrowParameterList
let params_start_position = cursor
.expect(Punctuator::OpenParen, "arrow function", interner)?
.span()
.end();
let params = FormalParameters::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)?;
cursor.expect(Punctuator::CloseParen, "arrow function", interner)?;
(params, params_start_position)
} else {
let params_start_position = next_token.span().start();
let param = BindingIdentifier::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)
.set_context("arrow function")?;
(
FormalParameterList::try_from(FormalParameter::new(
Variable::from_identifier(param, None),
false,
))
.expect("a single binding identifier without init is always a valid param list"),
params_start_position,
)
};
let (params, params_start_position) =
if next_token.kind() == &TokenKind::Punctuator(Punctuator::OpenParen) {
// CoverParenthesizedExpressionAndArrowParameterList
let params_start_position = cursor
.expect(Punctuator::OpenParen, "arrow function", interner)?
.span()
.end();
let params = FormalParameters::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)?;
cursor.expect(Punctuator::CloseParen, "arrow function", interner)?;
(params, params_start_position)
} else {
let params_start_position = next_token.span().start();
let param = BindingIdentifier::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)
.set_context("arrow function")?;
(
FormalParameterList::from(FormalParameter::new(
Variable::from_identifier(param, None),
false,
)),
params_start_position,
)
};
cursor.peek_expect_no_lineterminator(0, "arrow function", interner)?;

48
core/parser/src/parser/expression/assignment/async_arrow_function.rs

@ -77,31 +77,29 @@ where
cursor.peek_expect_no_lineterminator(0, "async arrow function", interner)?;
let next_token = cursor.peek(0, interner).or_abrupt()?;
let (params, params_start_position) = if next_token.kind()
== &TokenKind::Punctuator(Punctuator::OpenParen)
{
let params_start_position = cursor
.expect(Punctuator::OpenParen, "async arrow function", interner)?
.span()
.end();
let params = FormalParameters::new(false, true).parse(cursor, interner)?;
cursor.expect(Punctuator::CloseParen, "async arrow function", interner)?;
(params, params_start_position)
} else {
let params_start_position = next_token.span().start();
let param = BindingIdentifier::new(self.allow_yield, true)
.parse(cursor, interner)
.set_context("async arrow function")?;
(
FormalParameterList::try_from(FormalParameter::new(
Variable::from_identifier(param, None),
false,
))
.expect("a single binding identifier without init is always a valid param list"),
params_start_position,
)
};
let (params, params_start_position) =
if next_token.kind() == &TokenKind::Punctuator(Punctuator::OpenParen) {
let params_start_position = cursor
.expect(Punctuator::OpenParen, "async arrow function", interner)?
.span()
.end();
let params = FormalParameters::new(false, true).parse(cursor, interner)?;
cursor.expect(Punctuator::CloseParen, "async arrow function", interner)?;
(params, params_start_position)
} else {
let params_start_position = next_token.span().start();
let param = BindingIdentifier::new(self.allow_yield, true)
.parse(cursor, interner)
.set_context("async arrow function")?;
(
FormalParameterList::from(FormalParameter::new(
Variable::from_identifier(param, None),
false,
)),
params_start_position,
)
};
cursor.peek_expect_no_lineterminator(0, "async arrow function", interner)?;
cursor.expect(Punctuator::Arrow, "async arrow function", interner)?;

12
core/runtime/src/console/mod.rs

@ -270,7 +270,7 @@ impl Console {
console: &Self,
context: &mut Context,
) -> JsResult<JsValue> {
let assertion = args.get(0).map_or(false, JsValue::to_boolean);
let assertion = args.first().map_or(false, JsValue::to_boolean);
if !assertion {
let mut args: Vec<JsValue> = args.iter().skip(1).cloned().collect();
@ -456,7 +456,7 @@ impl Console {
console: &mut Self,
context: &mut Context,
) -> JsResult<JsValue> {
let label = match args.get(0) {
let label = match args.first() {
Some(value) => value.to_string(context)?,
None => "default".into(),
};
@ -485,7 +485,7 @@ impl Console {
console: &mut Self,
context: &mut Context,
) -> JsResult<JsValue> {
let label = match args.get(0) {
let label = match args.first() {
Some(value) => value.to_string(context)?,
None => "default".into(),
};
@ -524,7 +524,7 @@ impl Console {
console: &mut Self,
context: &mut Context,
) -> JsResult<JsValue> {
let label = match args.get(0) {
let label = match args.first() {
Some(value) => value.to_string(context)?,
None => "default".into(),
};
@ -561,7 +561,7 @@ impl Console {
console: &Self,
context: &mut Context,
) -> JsResult<JsValue> {
let label = match args.get(0) {
let label = match args.first() {
Some(value) => value.to_string(context)?,
None => "default".into(),
};
@ -605,7 +605,7 @@ impl Console {
console: &mut Self,
context: &mut Context,
) -> JsResult<JsValue> {
let label = match args.get(0) {
let label = match args.first() {
Some(value) => value.to_string(context)?,
None => "default".into(),
};

7
core/temporal/src/components/duration.rs

@ -361,6 +361,13 @@ impl Duration {
pub fn is_time_within_range(&self) -> bool {
self.time.is_within_range()
}
/// Return an iterator over the `Duration`'s values.
#[inline]
#[must_use]
pub fn iter(&self) -> DurationIter<'_> {
<&Self as IntoIterator>::into_iter(self)
}
}
// ==== Public `Duration` Getters/Setters ====

2
examples/src/bin/classes.rs

@ -107,7 +107,7 @@ impl Class for Person {
js_string!("is"),
1,
NativeFunction::from_fn_ptr(|_this, args, _ctx| {
if let Some(arg) = args.get(0) {
if let Some(arg) = args.first() {
if let Some(object) = arg.as_object() {
// We check if the type of `args[0]` is `Person`
if object.is::<Person>() {

6
examples/src/bin/jsarray.rs

@ -68,7 +68,7 @@ fn main() -> JsResult<()> {
let filter_callback = FunctionObjectBuilder::new(
context.realm(),
NativeFunction::from_fn_ptr(|_this, args, _context| {
Ok(args.get(0).cloned().unwrap_or_default().is_number().into())
Ok(args.first().cloned().unwrap_or_default().is_number().into())
}),
)
.build();
@ -76,7 +76,7 @@ fn main() -> JsResult<()> {
let map_callback = FunctionObjectBuilder::new(
context.realm(),
NativeFunction::from_fn_ptr(|_this, args, context| {
args.get(0)
args.first()
.cloned()
.unwrap_or_default()
.pow(&JsValue::new(2), context)
@ -102,7 +102,7 @@ fn main() -> JsResult<()> {
let reduce_callback = FunctionObjectBuilder::new(
context.realm(),
NativeFunction::from_fn_ptr(|_this, args, context| {
let accumulator = args.get(0).cloned().unwrap_or_default();
let accumulator = args.first().cloned().unwrap_or_default();
let value = args.get(1).cloned().unwrap_or_default();
accumulator.add(&value, context)

2
examples/src/bin/jstypedarray.rs

@ -28,7 +28,7 @@ fn main() -> JsResult<()> {
let callback = FunctionObjectBuilder::new(
context.realm(),
NativeFunction::from_fn_ptr(|_this, args, context| {
let accumulator = args.get(0).cloned().unwrap_or_default();
let accumulator = args.first().cloned().unwrap_or_default();
let value = args.get(1).cloned().unwrap_or_default();
accumulator.add(&value, context)

4
tests/tester/src/exec/js262.rs

@ -136,7 +136,7 @@ fn detach_array_buffer(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResu
}
let array_buffer = args
.get(0)
.first()
.and_then(JsValue::as_object)
.ok_or_else(type_err)?;
let mut array_buffer = array_buffer.borrow_mut();
@ -162,7 +162,7 @@ fn detach_array_buffer(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResu
///
/// Accepts a string value as its first argument and executes it as an ECMAScript script.
fn eval_script(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
args.get(0).and_then(JsValue::as_string).map_or_else(
args.first().and_then(JsValue::as_string).map_or_else(
|| Ok(JsValue::undefined()),
|source_text| context.eval(Source::from_bytes(&source_text.to_std_string_escaped())),
)

Loading…
Cancel
Save