diff --git a/boa_engine/src/builtins/array_buffer/mod.rs b/boa_engine/src/builtins/array_buffer/mod.rs index 9bc118f6b9c..b485fd78f6f 100644 --- a/boa_engine/src/builtins/array_buffer/mod.rs +++ b/boa_engine/src/builtins/array_buffer/mod.rs @@ -2,7 +2,7 @@ mod tests; use crate::{ - builtins::{typed_array::TypedArrayName, BuiltIn, JsArgs}, + builtins::{typed_array::TypedArrayKind, BuiltIn, JsArgs}, context::StandardObjects, object::{ internal_methods::get_prototype_from_constructor, ConstructorBuilder, FunctionBuilder, @@ -397,17 +397,17 @@ impl ArrayBuffer { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-isunclampedintegerelementtype - fn is_unclamped_integer_element_type(t: TypedArrayName) -> bool { + fn is_unclamped_integer_element_type(t: TypedArrayKind) -> bool { // 1. If type is Int8, Uint8, Int16, Uint16, Int32, or Uint32, return true. // 2. Return false. matches!( t, - TypedArrayName::Int8Array - | TypedArrayName::Uint8Array - | TypedArrayName::Int16Array - | TypedArrayName::Uint16Array - | TypedArrayName::Int32Array - | TypedArrayName::Uint32Array + TypedArrayKind::Int8 + | TypedArrayKind::Uint8 + | TypedArrayKind::Int16 + | TypedArrayKind::Uint16 + | TypedArrayKind::Int32 + | TypedArrayKind::Uint32 ) } @@ -417,13 +417,10 @@ impl ArrayBuffer { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-isbigintelementtype - fn is_big_int_element_type(t: TypedArrayName) -> bool { + fn is_big_int_element_type(t: TypedArrayKind) -> bool { // 1. If type is BigUint64 or BigInt64, return true. // 2. Return false. - matches!( - t, - TypedArrayName::BigUint64Array | TypedArrayName::BigInt64Array - ) + matches!(t, TypedArrayKind::BigUint64 | TypedArrayKind::BigInt64) } /// `25.1.2.8 IsNoTearConfiguration ( type, order )` @@ -434,7 +431,7 @@ impl ArrayBuffer { /// [spec]: https://tc39.es/ecma262/#sec-isnotearconfiguration // TODO: Allow unused function until shared array buffers are implemented. #[allow(dead_code)] - fn is_no_tear_configuration(t: TypedArrayName, order: SharedMemoryOrder) -> bool { + fn is_no_tear_configuration(t: TypedArrayKind, order: SharedMemoryOrder) -> bool { // 1. If ! IsUnclampedIntegerElementType(type) is true, return true. if Self::is_unclamped_integer_element_type(t) { return true; @@ -460,23 +457,23 @@ impl ArrayBuffer { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-rawbytestonumeric - fn raw_bytes_to_numeric(t: TypedArrayName, bytes: &[u8], is_little_endian: bool) -> JsValue { + fn raw_bytes_to_numeric(t: TypedArrayKind, bytes: &[u8], is_little_endian: bool) -> JsValue { let n: Numeric = match t { - TypedArrayName::Int8Array => { + TypedArrayKind::Int8 => { if is_little_endian { i8::from_le_bytes(bytes.try_into().expect("slice with incorrect length")).into() } else { i8::from_be_bytes(bytes.try_into().expect("slice with incorrect length")).into() } } - TypedArrayName::Uint8Array | TypedArrayName::Uint8ClampedArray => { + TypedArrayKind::Uint8 | TypedArrayKind::Uint8Clamped => { if is_little_endian { u8::from_le_bytes(bytes.try_into().expect("slice with incorrect length")).into() } else { u8::from_be_bytes(bytes.try_into().expect("slice with incorrect length")).into() } } - TypedArrayName::Int16Array => { + TypedArrayKind::Int16 => { if is_little_endian { i16::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -485,7 +482,7 @@ impl ArrayBuffer { .into() } } - TypedArrayName::Uint16Array => { + TypedArrayKind::Uint16 => { if is_little_endian { u16::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -494,7 +491,7 @@ impl ArrayBuffer { .into() } } - TypedArrayName::Int32Array => { + TypedArrayKind::Int32 => { if is_little_endian { i32::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -503,7 +500,7 @@ impl ArrayBuffer { .into() } } - TypedArrayName::Uint32Array => { + TypedArrayKind::Uint32 => { if is_little_endian { u32::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -512,7 +509,7 @@ impl ArrayBuffer { .into() } } - TypedArrayName::BigInt64Array => { + TypedArrayKind::BigInt64 => { if is_little_endian { i64::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -521,7 +518,7 @@ impl ArrayBuffer { .into() } } - TypedArrayName::BigUint64Array => { + TypedArrayKind::BigUint64 => { if is_little_endian { u64::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -530,7 +527,7 @@ impl ArrayBuffer { .into() } } - TypedArrayName::Float32Array => { + TypedArrayKind::Float32 => { if is_little_endian { f32::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -539,7 +536,7 @@ impl ArrayBuffer { .into() } } - TypedArrayName::Float64Array => { + TypedArrayKind::Float64 => { if is_little_endian { f64::from_le_bytes(bytes.try_into().expect("slice with incorrect length")) .into() @@ -562,7 +559,7 @@ impl ArrayBuffer { pub(crate) fn get_value_from_buffer( &self, byte_index: usize, - t: TypedArrayName, + t: TypedArrayKind, _is_typed_array: bool, _order: SharedMemoryOrder, is_little_endian: Option, @@ -600,43 +597,41 @@ impl ArrayBuffer { /// /// [spec]: https://tc39.es/ecma262/#sec-numerictorawbytes fn numeric_to_raw_bytes( - t: TypedArrayName, + t: TypedArrayKind, value: &JsValue, is_little_endian: bool, context: &mut Context, ) -> JsResult> { Ok(match t { - TypedArrayName::Int8Array if is_little_endian => { + TypedArrayKind::Int8 if is_little_endian => { value.to_int8(context)?.to_le_bytes().to_vec() } - TypedArrayName::Int8Array => value.to_int8(context)?.to_be_bytes().to_vec(), - TypedArrayName::Uint8Array if is_little_endian => { + TypedArrayKind::Int8 => value.to_int8(context)?.to_be_bytes().to_vec(), + TypedArrayKind::Uint8 if is_little_endian => { value.to_uint8(context)?.to_le_bytes().to_vec() } - TypedArrayName::Uint8Array => value.to_uint8(context)?.to_be_bytes().to_vec(), - TypedArrayName::Uint8ClampedArray if is_little_endian => { + TypedArrayKind::Uint8 => value.to_uint8(context)?.to_be_bytes().to_vec(), + TypedArrayKind::Uint8Clamped if is_little_endian => { value.to_uint8_clamp(context)?.to_le_bytes().to_vec() } - TypedArrayName::Uint8ClampedArray => { - value.to_uint8_clamp(context)?.to_be_bytes().to_vec() - } - TypedArrayName::Int16Array if is_little_endian => { + TypedArrayKind::Uint8Clamped => value.to_uint8_clamp(context)?.to_be_bytes().to_vec(), + TypedArrayKind::Int16 if is_little_endian => { value.to_int16(context)?.to_le_bytes().to_vec() } - TypedArrayName::Int16Array => value.to_int16(context)?.to_be_bytes().to_vec(), - TypedArrayName::Uint16Array if is_little_endian => { + TypedArrayKind::Int16 => value.to_int16(context)?.to_be_bytes().to_vec(), + TypedArrayKind::Uint16 if is_little_endian => { value.to_uint16(context)?.to_le_bytes().to_vec() } - TypedArrayName::Uint16Array => value.to_uint16(context)?.to_be_bytes().to_vec(), - TypedArrayName::Int32Array if is_little_endian => { + TypedArrayKind::Uint16 => value.to_uint16(context)?.to_be_bytes().to_vec(), + TypedArrayKind::Int32 if is_little_endian => { value.to_i32(context)?.to_le_bytes().to_vec() } - TypedArrayName::Int32Array => value.to_i32(context)?.to_be_bytes().to_vec(), - TypedArrayName::Uint32Array if is_little_endian => { + TypedArrayKind::Int32 => value.to_i32(context)?.to_be_bytes().to_vec(), + TypedArrayKind::Uint32 if is_little_endian => { value.to_u32(context)?.to_le_bytes().to_vec() } - TypedArrayName::Uint32Array => value.to_u32(context)?.to_be_bytes().to_vec(), - TypedArrayName::BigInt64Array if is_little_endian => { + TypedArrayKind::Uint32 => value.to_u32(context)?.to_be_bytes().to_vec(), + TypedArrayKind::BigInt64 if is_little_endian => { let big_int = value.to_big_int64(context)?; big_int .to_i64() @@ -650,7 +645,7 @@ impl ArrayBuffer { .to_le_bytes() .to_vec() } - TypedArrayName::BigInt64Array => { + TypedArrayKind::BigInt64 => { let big_int = value.to_big_int64(context)?; big_int .to_i64() @@ -664,23 +659,23 @@ impl ArrayBuffer { .to_be_bytes() .to_vec() } - TypedArrayName::BigUint64Array if is_little_endian => value + TypedArrayKind::BigUint64 if is_little_endian => value .to_big_uint64(context)? .to_u64() .unwrap_or(u64::MAX) .to_le_bytes() .to_vec(), - TypedArrayName::BigUint64Array => value + TypedArrayKind::BigUint64 => value .to_big_uint64(context)? .to_u64() .unwrap_or(u64::MAX) .to_be_bytes() .to_vec(), - TypedArrayName::Float32Array => match value.to_number(context)? { + TypedArrayKind::Float32 => match value.to_number(context)? { f if is_little_endian => (f as f32).to_le_bytes().to_vec(), f => (f as f32).to_be_bytes().to_vec(), }, - TypedArrayName::Float64Array => match value.to_number(context)? { + TypedArrayKind::Float64 => match value.to_number(context)? { f if is_little_endian => f.to_le_bytes().to_vec(), f => f.to_be_bytes().to_vec(), }, @@ -696,7 +691,7 @@ impl ArrayBuffer { pub(crate) fn set_value_in_buffer( &mut self, byte_index: usize, - t: TypedArrayName, + t: TypedArrayKind, value: &JsValue, _order: SharedMemoryOrder, is_little_endian: Option, diff --git a/boa_engine/src/builtins/dataview/mod.rs b/boa_engine/src/builtins/dataview/mod.rs index 4b8c256c8e3..6e587feb287 100644 --- a/boa_engine/src/builtins/dataview/mod.rs +++ b/boa_engine/src/builtins/dataview/mod.rs @@ -1,5 +1,5 @@ use crate::{ - builtins::{array_buffer::SharedMemoryOrder, typed_array::TypedArrayName, BuiltIn, JsArgs}, + builtins::{array_buffer::SharedMemoryOrder, typed_array::TypedArrayKind, BuiltIn, JsArgs}, context::StandardObjects, object::{ internal_methods::get_prototype_from_constructor, ConstructorBuilder, FunctionBuilder, @@ -300,7 +300,7 @@ impl DataView { view: &JsValue, request_index: &JsValue, is_little_endian: &JsValue, - t: TypedArrayName, + t: TypedArrayKind, context: &mut Context, ) -> JsResult { // 1. Perform ? RequireInternalSlot(view, [[DataView]]). @@ -378,7 +378,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::BigInt64Array, + TypedArrayKind::BigInt64, context, ) } @@ -407,7 +407,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::BigUint64Array, + TypedArrayKind::BigUint64, context, ) } @@ -436,7 +436,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Float32Array, + TypedArrayKind::Float32, context, ) } @@ -465,7 +465,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Float64Array, + TypedArrayKind::Float64, context, ) } @@ -494,7 +494,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Int8Array, + TypedArrayKind::Int8, context, ) } @@ -523,7 +523,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Int16Array, + TypedArrayKind::Int16, context, ) } @@ -552,7 +552,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Int32Array, + TypedArrayKind::Int32, context, ) } @@ -581,7 +581,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, context, ) } @@ -610,7 +610,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Uint16Array, + TypedArrayKind::Uint16, context, ) } @@ -639,7 +639,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Uint32Array, + TypedArrayKind::Uint32, context, ) } @@ -658,7 +658,7 @@ impl DataView { view: &JsValue, request_index: &JsValue, is_little_endian: &JsValue, - t: TypedArrayName, + t: TypedArrayKind, value: &JsValue, context: &mut Context, ) -> JsResult { @@ -747,7 +747,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::BigInt64Array, + TypedArrayKind::BigInt64, value, context, ) @@ -778,7 +778,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::BigUint64Array, + TypedArrayKind::BigUint64, value, context, ) @@ -809,7 +809,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Float32Array, + TypedArrayKind::Float32, value, context, ) @@ -840,7 +840,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Float64Array, + TypedArrayKind::Float64, value, context, ) @@ -871,7 +871,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Int8Array, + TypedArrayKind::Int8, value, context, ) @@ -902,7 +902,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Int16Array, + TypedArrayKind::Int16, value, context, ) @@ -933,7 +933,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Int32Array, + TypedArrayKind::Int32, value, context, ) @@ -964,7 +964,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, value, context, ) @@ -995,7 +995,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Uint16Array, + TypedArrayKind::Uint16, value, context, ) @@ -1026,7 +1026,7 @@ impl DataView { this, byte_offset, is_little_endian, - TypedArrayName::Uint32Array, + TypedArrayKind::Uint32, value, context, ) diff --git a/boa_engine/src/builtins/typed_array/integer_indexed_object.rs b/boa_engine/src/builtins/typed_array/integer_indexed_object.rs index f9297eb0cff..f36982126f4 100644 --- a/boa_engine/src/builtins/typed_array/integer_indexed_object.rs +++ b/boa_engine/src/builtins/typed_array/integer_indexed_object.rs @@ -9,7 +9,7 @@ //! [spec]: https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects use crate::{ - builtins::typed_array::TypedArrayName, + builtins::typed_array::TypedArrayKind, object::{JsObject, ObjectData}, Context, }; @@ -31,7 +31,7 @@ unsafe impl Trace for ContentType { #[derive(Debug, Clone, Trace, Finalize)] pub struct IntegerIndexed { viewed_array_buffer: Option, - typed_array_name: TypedArrayName, + typed_array_name: TypedArrayKind, byte_offset: usize, byte_length: usize, array_length: usize, @@ -40,7 +40,7 @@ pub struct IntegerIndexed { impl IntegerIndexed { pub(crate) fn new( viewed_array_buffer: Option, - typed_array_name: TypedArrayName, + typed_array_name: TypedArrayKind, byte_offset: usize, byte_length: usize, array_length: usize, @@ -115,7 +115,7 @@ impl IntegerIndexed { } /// Get the integer indexed object's typed array name. - pub(crate) fn typed_array_name(&self) -> TypedArrayName { + pub(crate) fn typed_array_name(&self) -> TypedArrayKind { self.typed_array_name } diff --git a/boa_engine/src/builtins/typed_array/mod.rs b/boa_engine/src/builtins/typed_array/mod.rs index 8fab604ffbc..e6d783f9d05 100644 --- a/boa_engine/src/builtins/typed_array/mod.rs +++ b/boa_engine/src/builtins/typed_array/mod.rs @@ -37,7 +37,7 @@ use std::cmp::Ordering; pub mod integer_indexed_object; macro_rules! typed_array { - ($ty:ident, $name:literal, $global_object_name:ident) => { + ($ty:ident, $variant:ident, $name:literal, $global_object_name:ident) => { #[doc = concat!("JavaScript `", $name, "` built-in implementation.")] #[derive(Debug, Clone, Copy)] pub struct $ty; @@ -75,12 +75,12 @@ macro_rules! typed_array { ) .property( "BYTES_PER_ELEMENT", - TypedArrayName::$ty.element_size(), + TypedArrayKind::$variant.element_size(), Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT, ) .static_property( "BYTES_PER_ELEMENT", - TypedArrayName::$ty.element_size(), + TypedArrayKind::$variant.element_size(), Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT, ) .custom_prototype(typed_array_constructor) @@ -113,7 +113,7 @@ macro_rules! typed_array { } // 2. Let constructorName be the String value of the Constructor Name value specified in Table 72 for this TypedArray constructor. - let constructor_name = TypedArrayName::$ty; + let constructor_name = TypedArrayKind::$variant; // 3. Let proto be "%TypedArray.prototype%". let proto = StandardObjects::$global_object_name; @@ -797,7 +797,7 @@ impl TypedArray { // i. Let value be GetValueFromBuffer(buffer, fromByteIndex, Uint8, true, Unordered). let value = buffer.get_value_from_buffer( from_byte_index as usize, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, true, SharedMemoryOrder::Unordered, None, @@ -806,7 +806,7 @@ impl TypedArray { // ii. Perform SetValueInBuffer(buffer, toByteIndex, Uint8, value, true, Unordered). buffer.set_value_in_buffer( to_byte_index as usize, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, &value, SharedMemoryOrder::Unordered, None, @@ -2054,7 +2054,7 @@ impl TypedArray { // i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, Uint8, true, Unordered). let value = src_buffer.get_value_from_buffer( src_byte_index, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, true, SharedMemoryOrder::Unordered, None, @@ -2067,7 +2067,7 @@ impl TypedArray { .expect("Must be an array buffer") .set_value_in_buffer( target_byte_index, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, &value, SharedMemoryOrder::Unordered, None, @@ -2367,7 +2367,7 @@ impl TypedArray { // 1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, Uint8, true, Unordered). let value = src_buffer.get_value_from_buffer( src_byte_index, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, true, SharedMemoryOrder::Unordered, None, @@ -2376,7 +2376,7 @@ impl TypedArray { // 2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, Uint8, value, true, Unordered). target_buffer.set_value_in_buffer( target_byte_index, - TypedArrayName::Uint8Array, + TypedArrayKind::Uint8, &value, SharedMemoryOrder::Unordered, None, @@ -2809,23 +2809,23 @@ impl TypedArray { /// [spec]: https://tc39.es/ecma262/#typedarray-species-create fn species_create( exemplar: &JsObject, - typed_array_name: TypedArrayName, + typed_array_name: TypedArrayKind, args: &[JsValue], context: &mut Context, ) -> JsResult { // 1. Let defaultConstructor be the intrinsic object listed in column one of Table 73 for exemplar.[[TypedArrayName]]. let default_constructor = match typed_array_name { - TypedArrayName::Int8Array => StandardObjects::typed_int8_array_object, - TypedArrayName::Uint8Array => StandardObjects::typed_uint8_array_object, - TypedArrayName::Uint8ClampedArray => StandardObjects::typed_uint8clamped_array_object, - TypedArrayName::Int16Array => StandardObjects::typed_int16_array_object, - TypedArrayName::Uint16Array => StandardObjects::typed_uint16_array_object, - TypedArrayName::Int32Array => StandardObjects::typed_int32_array_object, - TypedArrayName::Uint32Array => StandardObjects::typed_uint32_array_object, - TypedArrayName::BigInt64Array => StandardObjects::typed_bigint64_array_object, - TypedArrayName::BigUint64Array => StandardObjects::typed_biguint64_array_object, - TypedArrayName::Float32Array => StandardObjects::typed_float32_array_object, - TypedArrayName::Float64Array => StandardObjects::typed_float64_array_object, + TypedArrayKind::Int8 => StandardObjects::typed_int8_array_object, + TypedArrayKind::Uint8 => StandardObjects::typed_uint8_array_object, + TypedArrayKind::Uint8Clamped => StandardObjects::typed_uint8clamped_array_object, + TypedArrayKind::Int16 => StandardObjects::typed_int16_array_object, + TypedArrayKind::Uint16 => StandardObjects::typed_uint16_array_object, + TypedArrayKind::Int32 => StandardObjects::typed_int32_array_object, + TypedArrayKind::Uint32 => StandardObjects::typed_uint32_array_object, + TypedArrayKind::BigInt64 => StandardObjects::typed_bigint64_array_object, + TypedArrayKind::BigUint64 => StandardObjects::typed_biguint64_array_object, + TypedArrayKind::Float32 => StandardObjects::typed_float32_array_object, + TypedArrayKind::Float64 => StandardObjects::typed_float64_array_object, }; // 2. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). @@ -2975,7 +2975,7 @@ impl TypedArray { /// /// [spec]: https://tc39.es/ecma262/#sec-allocatetypedarray fn allocate

( - constructor_name: TypedArrayName, + constructor_name: TypedArrayKind, new_target: &JsValue, default_proto: P, length: Option, @@ -3287,36 +3287,36 @@ impl TypedArray { /// Names of all the typed arrays. #[derive(Debug, Clone, Copy, Finalize, PartialEq)] -pub(crate) enum TypedArrayName { - Int8Array, - Uint8Array, - Uint8ClampedArray, - Int16Array, - Uint16Array, - Int32Array, - Uint32Array, - BigInt64Array, - BigUint64Array, - Float32Array, - Float64Array, +pub(crate) enum TypedArrayKind { + Int8, + Uint8, + Uint8Clamped, + Int16, + Uint16, + Int32, + Uint32, + BigInt64, + BigUint64, + Float32, + Float64, } -unsafe impl Trace for TypedArrayName { +unsafe impl Trace for TypedArrayKind { // Safe because `TypedArrayName` is `Copy` unsafe_empty_trace!(); } -impl TypedArrayName { +impl TypedArrayKind { /// Gets the element size of the given typed array name, as per the [spec]. /// /// [spec]: https://tc39.es/ecma262/#table-the-typedarray-constructors #[inline] pub(crate) const fn element_size(self) -> usize { match self { - Self::Int8Array | Self::Uint8Array | Self::Uint8ClampedArray => 1, - Self::Int16Array | Self::Uint16Array => 2, - Self::Int32Array | Self::Uint32Array | Self::Float32Array => 4, - Self::BigInt64Array | Self::BigUint64Array | Self::Float64Array => 8, + Self::Int8 | Self::Uint8 | Self::Uint8Clamped => 1, + Self::Int16 | Self::Uint16 => 2, + Self::Int32 | Self::Uint32 | Self::Float32 => 4, + Self::BigInt64 | Self::BigUint64 | Self::Float64 => 8, } } @@ -3324,7 +3324,7 @@ impl TypedArrayName { #[inline] pub(crate) const fn content_type(self) -> ContentType { match self { - Self::BigInt64Array | Self::BigUint64Array => ContentType::BigInt, + Self::BigInt64 | Self::BigUint64 => ContentType::BigInt, _ => ContentType::Number, } } @@ -3333,44 +3333,68 @@ impl TypedArrayName { #[inline] pub(crate) const fn name(&self) -> &str { match self { - TypedArrayName::Int8Array => "Int8Array", - TypedArrayName::Uint8Array => "Uint8Array", - TypedArrayName::Uint8ClampedArray => "Uint8ClampedArray", - TypedArrayName::Int16Array => "Int16Array", - TypedArrayName::Uint16Array => "Uint16Array", - TypedArrayName::Int32Array => "Int32Array", - TypedArrayName::Uint32Array => "Uint32Array", - TypedArrayName::BigInt64Array => "BigInt64Array", - TypedArrayName::BigUint64Array => "BigUint64Array", - TypedArrayName::Float32Array => "Float32Array", - TypedArrayName::Float64Array => "Float64Array", + 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", } } pub(crate) fn is_big_int_element_type(self) -> bool { - matches!( - self, - TypedArrayName::BigUint64Array | TypedArrayName::BigInt64Array - ) + matches!(self, TypedArrayKind::BigUint64 | TypedArrayKind::BigInt64) } } -typed_array!(Int8Array, "Int8Array", typed_int8_array_object); -typed_array!(Uint8Array, "Uint8Array", typed_uint8_array_object); +typed_array!(Int8Array, Int8, "Int8Array", typed_int8_array_object); +typed_array!(Uint8Array, Uint8, "Uint8Array", typed_uint8_array_object); typed_array!( Uint8ClampedArray, + Uint8Clamped, "Uint8ClampedArray", typed_uint8clamped_array_object ); -typed_array!(Int16Array, "Int16Array", typed_int16_array_object); -typed_array!(Uint16Array, "Uint16Array", typed_uint16_array_object); -typed_array!(Int32Array, "Int32Array", typed_int32_array_object); -typed_array!(Uint32Array, "Uint32Array", typed_uint32_array_object); -typed_array!(BigInt64Array, "BigInt64Array", typed_bigint64_array_object); +typed_array!(Int16Array, Int16, "Int16Array", typed_int16_array_object); +typed_array!( + Uint16Array, + Uint16, + "Uint16Array", + typed_uint16_array_object +); +typed_array!(Int32Array, Int32, "Int32Array", typed_int32_array_object); +typed_array!( + Uint32Array, + Uint32, + "Uint32Array", + typed_uint32_array_object +); +typed_array!( + BigInt64Array, + BigInt64, + "BigInt64Array", + typed_bigint64_array_object +); typed_array!( BigUint64Array, + BigUint64, "BigUint64Array", typed_biguint64_array_object ); -typed_array!(Float32Array, "Float32Array", typed_float32_array_object); -typed_array!(Float64Array, "Float64Array", typed_float64_array_object); +typed_array!( + Float32Array, + Float32, + "Float32Array", + typed_float32_array_object +); +typed_array!( + Float64Array, + Float64, + "Float64Array", + typed_float64_array_object +); diff --git a/boa_engine/src/bytecompiler.rs b/boa_engine/src/bytecompiler.rs index 57e0d7f6599..2aca2a1c292 100644 --- a/boa_engine/src/bytecompiler.rs +++ b/boa_engine/src/bytecompiler.rs @@ -456,7 +456,7 @@ impl<'b> ByteCompiler<'b> { } #[inline] - fn compile_access<'a>(&mut self, node: &'a Node) -> Access<'a> { + fn compile_access(node: &'_ Node) -> Access<'_> { match node { Node::Identifier(name) => Access::Variable { name: name.sym() }, Node::GetConstField(node) => Access::ByName { node }, @@ -571,7 +571,7 @@ impl<'b> ByteCompiler<'b> { self.compile_expr(unary.target(), true)?; self.emit(Opcode::Inc, &[]); - let access = self.compile_access(unary.target()); + let access = Self::compile_access(unary.target()); self.access_set(access, None, true)?; None } @@ -579,7 +579,7 @@ impl<'b> ByteCompiler<'b> { self.compile_expr(unary.target(), true)?; self.emit(Opcode::Dec, &[]); - let access = self.compile_access(unary.target()); + let access = Self::compile_access(unary.target()); self.access_set(access, None, true)?; None } @@ -587,7 +587,7 @@ impl<'b> ByteCompiler<'b> { self.compile_expr(unary.target(), true)?; self.emit(Opcode::Dup, &[]); self.emit(Opcode::Inc, &[]); - let access = self.compile_access(unary.target()); + let access = Self::compile_access(unary.target()); self.access_set(access, None, false)?; None @@ -596,7 +596,7 @@ impl<'b> ByteCompiler<'b> { self.compile_expr(unary.target(), true)?; self.emit(Opcode::Dup, &[]); self.emit(Opcode::Dec, &[]); - let access = self.compile_access(unary.target()); + let access = Self::compile_access(unary.target()); self.access_set(access, None, false)?; None @@ -744,7 +744,7 @@ impl<'b> ByteCompiler<'b> { AssignOp::BoolAnd => { let exit = self.jump_with_custom_opcode(Opcode::LogicalAnd); self.compile_expr(binary.rhs(), true)?; - let access = self.compile_access(binary.lhs()); + let access = Self::compile_access(binary.lhs()); self.access_set(access, None, use_expr)?; self.patch_jump(exit); None @@ -752,7 +752,7 @@ impl<'b> ByteCompiler<'b> { AssignOp::BoolOr => { let exit = self.jump_with_custom_opcode(Opcode::LogicalOr); self.compile_expr(binary.rhs(), true)?; - let access = self.compile_access(binary.lhs()); + let access = Self::compile_access(binary.lhs()); self.access_set(access, None, use_expr)?; self.patch_jump(exit); None @@ -760,7 +760,7 @@ impl<'b> ByteCompiler<'b> { AssignOp::Coalesce => { let exit = self.jump_with_custom_opcode(Opcode::Coalesce); self.compile_expr(binary.rhs(), true)?; - let access = self.compile_access(binary.lhs()); + let access = Self::compile_access(binary.lhs()); self.access_set(access, None, use_expr)?; self.patch_jump(exit); None @@ -770,7 +770,7 @@ impl<'b> ByteCompiler<'b> { if let Some(opcode) = opcode { self.compile_expr(binary.rhs(), true)?; self.emit(opcode, &[]); - let access = self.compile_access(binary.lhs()); + let access = Self::compile_access(binary.lhs()); self.access_set(access, None, use_expr)?; } } @@ -891,7 +891,7 @@ impl<'b> ByteCompiler<'b> { if let Node::Object(_) = assign.lhs() { self.emit_opcode(Opcode::PushUndefined); } else { - let access = self.compile_access(assign.lhs()); + let access = Self::compile_access(assign.lhs()); self.access_set(access, Some(assign.rhs()), use_expr)?; } } diff --git a/boa_engine/src/object/jsobject.rs b/boa_engine/src/object/jsobject.rs index c4f66e62b88..8a6a995bbe8 100644 --- a/boa_engine/src/object/jsobject.rs +++ b/boa_engine/src/object/jsobject.rs @@ -511,7 +511,7 @@ impl JsObject { // 15. If desc.[[Get]] is present or desc.[[Set]] is present, then ... // a. If desc.[[Value]] is present or desc.[[Writable]] is present, throw a TypeError exception. - if get.as_ref().or_else(|| set.as_ref()).is_some() && desc.inner().is_data_descriptor() { + if get.as_ref().or(set.as_ref()).is_some() && desc.inner().is_data_descriptor() { return context.throw_type_error( "Invalid property descriptor.\ Cannot both specify accessors and a value or writable attribute", diff --git a/boa_engine/src/object/mod.rs b/boa_engine/src/object/mod.rs index 7a100101ea5..ff3ef040cbc 100644 --- a/boa_engine/src/object/mod.rs +++ b/boa_engine/src/object/mod.rs @@ -1304,6 +1304,7 @@ impl<'context> FunctionBuilder<'context> { /// /// The default is `""` (empty string). #[inline] + #[must_use] pub fn name(mut self, name: N) -> Self where N: AsRef, @@ -1318,6 +1319,7 @@ impl<'context> FunctionBuilder<'context> { /// /// The default is `0`. #[inline] + #[must_use] pub fn length(mut self, length: usize) -> Self { self.length = length; self @@ -1327,6 +1329,7 @@ impl<'context> FunctionBuilder<'context> { /// /// The default is `false`. #[inline] + #[must_use] pub fn constructor(mut self, yes: bool) -> Self { match self.function { Function::Native { diff --git a/boa_engine/src/property/mod.rs b/boa_engine/src/property/mod.rs index 079f985d786..bad7e732688 100644 --- a/boa_engine/src/property/mod.rs +++ b/boa_engine/src/property/mod.rs @@ -216,6 +216,7 @@ impl PropertyDescriptor { } #[inline] + #[must_use] pub fn into_accessor_defaulted(mut self) -> Self { self.kind = DescriptorKind::Accessor { get: self.get().cloned(), @@ -226,6 +227,7 @@ impl PropertyDescriptor { .build() } + #[must_use] pub fn into_data_defaulted(mut self) -> Self { self.kind = DescriptorKind::Data { value: self.value().cloned(), @@ -237,6 +239,7 @@ impl PropertyDescriptor { } #[inline] + #[must_use] pub fn complete_property_descriptor(self) -> Self { PropertyDescriptorBuilder { inner: self } .complete_with_defaults() @@ -297,6 +300,7 @@ impl PropertyDescriptorBuilder { Self::default() } + #[must_use] pub fn value>(mut self, value: V) -> Self { match self.inner.kind { DescriptorKind::Data { @@ -313,6 +317,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn writable(mut self, writable: bool) -> Self { match self.inner.kind { DescriptorKind::Data { @@ -330,6 +335,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn get>(mut self, get: V) -> Self { match self.inner.kind { DescriptorKind::Accessor { get: ref mut g, .. } => *g = Some(get.into()), @@ -344,6 +350,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn set>(mut self, set: V) -> Self { match self.inner.kind { DescriptorKind::Accessor { set: ref mut s, .. } => *s = Some(set.into()), @@ -358,6 +365,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn maybe_enumerable(mut self, enumerable: Option) -> Self { if let Some(enumerable) = enumerable { self = self.enumerable(enumerable); @@ -365,6 +373,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn maybe_configurable(mut self, configurable: Option) -> Self { if let Some(configurable) = configurable { self = self.configurable(configurable); @@ -372,6 +381,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn maybe_value>(mut self, value: Option) -> Self { if let Some(value) = value { self = self.value(value); @@ -379,6 +389,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn maybe_writable(mut self, writable: Option) -> Self { if let Some(writable) = writable { self = self.writable(writable); @@ -386,6 +397,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn maybe_get>(mut self, get: Option) -> Self { if let Some(get) = get { self = self.get(get); @@ -393,6 +405,7 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn maybe_set>(mut self, set: Option) -> Self { if let Some(set) = set { self = self.set(set); @@ -400,15 +413,19 @@ impl PropertyDescriptorBuilder { self } + #[must_use] pub fn enumerable(mut self, enumerable: bool) -> Self { self.inner.enumerable = Some(enumerable); self } + + #[must_use] pub fn configurable(mut self, configurable: bool) -> Self { self.inner.configurable = Some(configurable); self } + #[must_use] pub fn complete_with_defaults(mut self) -> Self { match self.inner.kind { DescriptorKind::Generic => { diff --git a/boa_engine/src/value/display.rs b/boa_engine/src/value/display.rs index 28299882554..97f2754bbc9 100644 --- a/boa_engine/src/value/display.rs +++ b/boa_engine/src/value/display.rs @@ -14,6 +14,7 @@ impl ValueDisplay<'_> { /// /// By default this is `false`. #[inline] + #[must_use] pub fn internals(mut self, yes: bool) -> Self { self.internals = yes; self diff --git a/boa_engine/src/value/equality.rs b/boa_engine/src/value/equality.rs index 1039d61d90d..d5812fa6091 100644 --- a/boa_engine/src/value/equality.rs +++ b/boa_engine/src/value/equality.rs @@ -76,10 +76,10 @@ impl JsValue { }, // 8. If Type(x) is Boolean, return the result of the comparison ! ToNumber(x) == y. - (Self::Boolean(x), _) => return other.equals(&Self::new(*x as i32), context), + (Self::Boolean(x), _) => return other.equals(&Self::new(i32::from(*x)), context), // 9. If Type(y) is Boolean, return the result of the comparison x == ! ToNumber(y). - (_, Self::Boolean(y)) => return self.equals(&Self::new(*y as i32), context), + (_, Self::Boolean(y)) => return self.equals(&Self::new(i32::from(*y)), context), // 10. If Type(x) is either String, Number, BigInt, or Symbol and Type(y) is Object, return the result // of the comparison x == ? ToPrimitive(y).