Skip to content

Commit

Permalink
Refactor: Allow clippy::unnecessary_wraps at builtins module
Browse files Browse the repository at this point in the history
Discussed in #1126 with @HalidOdat
  • Loading branch information
RageKnify committed Feb 16, 2021
1 parent 3caf209 commit 13cc560
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 20 deletions.
4 changes: 0 additions & 4 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.isarray
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn is_array(_: &Value, args: &[Value], _: &mut Context) -> Result<Value> {
match args.get(0).and_then(|x| x.as_object()) {
Some(object) => Ok(Value::from(object.borrow().is_array())),
Expand Down Expand Up @@ -1241,7 +1240,6 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn values(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
Ok(ArrayIterator::create_array_iterator(
context,
Expand All @@ -1260,7 +1258,6 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn keys(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
Ok(ArrayIterator::create_array_iterator(
context,
Expand All @@ -1279,7 +1276,6 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn entries(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
Ok(ArrayIterator::create_array_iterator(
context,
Expand Down
3 changes: 0 additions & 3 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/clear
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn clear(_: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
context.console_mut().groups.clear();
Ok(Value::undefined())
Expand Down Expand Up @@ -536,7 +535,6 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#groupend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/groupEnd
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn group_end(_: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
context.console_mut().groups.pop();

Expand All @@ -553,7 +551,6 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#dir
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/dir
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn dir(_: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
let undefined = Value::undefined();
logger(
Expand Down
1 change: 0 additions & 1 deletion boa/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,6 @@ impl Date {
///
/// [spec]: https://tc39.es/ecma262/#sec-date.now
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn now(_: &Value, _: &[Value], _: &mut Context) -> Result<Value> {
Ok(Value::from(Utc::now().timestamp_millis() as f64))
}
Expand Down
1 change: 0 additions & 1 deletion boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ impl BuiltInFunctionObject {
Ok(this)
}

#[allow(clippy::unnecessary_wraps)] // built-in function
fn prototype(_: &Value, _: &[Value], _: &mut Context) -> Result<Value> {
Ok(Value::undefined())
}
Expand Down
4 changes: 0 additions & 4 deletions boa/src/builtins/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ impl Map {
///
/// [spec]: https://www.ecma-international.org/ecma-262/11.0/index.html#sec-map.prototype.entries
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn entries(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
Ok(MapIterator::create_map_iterator(
context,
Expand All @@ -176,7 +175,6 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.keys
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn keys(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
Ok(MapIterator::create_map_iterator(
context,
Expand Down Expand Up @@ -299,7 +297,6 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn clear(this: &Value, _: &[Value], _: &mut Context) -> Result<Value> {
this.set_data(ObjectData::Map(OrderedMap::new()));

Expand Down Expand Up @@ -405,7 +402,6 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.values
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn values(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
Ok(MapIterator::create_map_iterator(
context,
Expand Down
1 change: 0 additions & 1 deletion boa/src/builtins/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.random
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn random(_: &Value, _: &[Value], _: &mut Context) -> Result<Value> {
Ok(rand::random::<f64>().into())
}
Expand Down
4 changes: 0 additions & 4 deletions boa/src/builtins/number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ impl Number {
///
/// [spec]: https://tc39.es/ecma262/#sec-number.isfinite
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn number_is_finite(_: &Value, args: &[Value], _ctx: &mut Context) -> Result<Value> {
Ok(Value::from(if let Some(val) = args.get(0) {
match val {
Expand All @@ -911,7 +910,6 @@ impl Number {
///
/// [spec]: https://tc39.es/ecma262/#sec-number.isinteger
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn number_is_integer(
_: &Value,
args: &[Value],
Expand All @@ -934,7 +932,6 @@ impl Number {
///
/// [spec]: https://tc39.es/ecma262/#sec-isnan-number
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn number_is_nan(_: &Value, args: &[Value], _ctx: &mut Context) -> Result<Value> {
Ok(Value::from(if let Some(val) = args.get(0) {
match val {
Expand All @@ -961,7 +958,6 @@ impl Number {
///
/// [spec]: https://tc39.es/ecma262/#sec-isnan-number
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn is_safe_integer(_: &Value, args: &[Value], _ctx: &mut Context) -> Result<Value> {
Ok(Value::from(match args.get(0) {
Some(Value::Integer(_)) => true,
Expand Down
2 changes: 0 additions & 2 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.padend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn pad_end(this: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
let primitive = this.to_string(context)?;
if args.is_empty() {
Expand Down Expand Up @@ -975,7 +974,6 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.padstart
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
#[allow(clippy::unnecessary_wraps)] // built-in function
pub(crate) fn pad_start(this: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
let primitive = this.to_string(context)?;
if args.is_empty() {
Expand Down
2 changes: 2 additions & 0 deletions boa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ This is an experimental Javascript lexer, parser and compiler written in Rust. C
missing_doc_code_examples
)]

// builtins module has a lot of built-in functions that need unnecessary_wraps
#[allow(clippy::unnecessary_wraps)]
pub mod builtins;
pub mod class;
pub mod environment;
Expand Down

0 comments on commit 13cc560

Please sign in to comment.