Browse Source

clippy fmt

nan-boxing
jedel1043 2 years ago
parent
commit
9217432669
  1. 9
      boa_engine/src/builtins/array/mod.rs
  2. 6
      boa_engine/src/builtins/async_generator/mod.rs
  3. 26
      boa_engine/src/builtins/promise/mod.rs
  4. 20
      boa_engine/src/builtins/promise/promise_job.rs
  5. 3
      boa_engine/src/builtins/reflect/mod.rs
  6. 5
      boa_engine/src/object/jsset.rs
  7. 1
      boa_engine/src/symbol.rs
  8. 10
      boa_engine/src/value/mod.rs
  9. 11
      boa_engine/src/vm/code_block.rs

9
boa_engine/src/builtins/array/mod.rs

@ -423,8 +423,7 @@ impl Array {
// b. Else, // b. Else,
// i. Let A be ? ArrayCreate(0en). // i. Let A be ? ArrayCreate(0en).
let a = match this.as_constructor() { let a = match this.as_constructor() {
Some(constructor) => constructor Some(constructor) => constructor.construct(&[], None, context)?,
.construct(&[], None, context)?,
_ => Self::array_create(0, None, context)?, _ => Self::array_create(0, None, context)?,
}; };
@ -497,8 +496,7 @@ impl Array {
// 10. Else, // 10. Else,
// a. Let A be ? ArrayCreate(len). // a. Let A be ? ArrayCreate(len).
let a = match this.as_constructor() { let a = match this.as_constructor() {
Some(constructor) => constructor Some(constructor) => constructor.construct(&[len.into()], None, context)?,
.construct(&[len.into()], None, context)?,
_ => Self::array_create(len, None, context)?, _ => Self::array_create(len, None, context)?,
}; };
@ -574,8 +572,7 @@ impl Array {
// 5. Else, // 5. Else,
// a. Let A be ? ArrayCreate(len). // a. Let A be ? ArrayCreate(len).
let a = match this.as_constructor() { let a = match this.as_constructor() {
Some(constructor) => constructor Some(constructor) => constructor.construct(&[len.into()], None, context)?,
.construct(&[len.into()], None, context)?,
_ => Self::array_create(len as u64, None, context)?, _ => Self::array_create(len as u64, None, context)?,
}; };

6
boa_engine/src/builtins/async_generator/mod.rs

@ -374,11 +374,7 @@ impl AsyncGenerator {
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « exception »). // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « exception »).
promise_capability promise_capability
.reject() .reject()
.call( .call(&JsValue::undefined(), &[args.get_or_undefined(0)], context)
&JsValue::undefined(),
&[args.get_or_undefined(0)],
context,
)
.expect("cannot fail per spec"); .expect("cannot fail per spec");
// b. Return promiseCapability.[[Promise]]. // b. Return promiseCapability.[[Promise]].

26
boa_engine/src/builtins/promise/mod.rs

@ -1710,11 +1710,7 @@ impl Promise {
// 1. Let promise be the this value. // 1. Let promise be the this value.
let promise = this; let promise = this;
// 2. Return ? Invoke(promise, "then", « undefined, onRejected »). // 2. Return ? Invoke(promise, "then", « undefined, onRejected »).
promise.invoke( promise.invoke("then", &[JsValue::undefined(), on_rejected], context)
"then",
&[JsValue::undefined(), on_rejected],
context,
)
} }
/// `Promise.prototype.finally ( onFinally )` /// `Promise.prototype.finally ( onFinally )`
@ -1778,9 +1774,7 @@ impl Promise {
// 1. Return value. // 1. Return value.
Ok(captures.value.clone()) Ok(captures.value.clone())
}, },
ReturnValueCaptures { ReturnValueCaptures { value },
value,
},
); );
// iv. Let valueThunk be CreateBuiltinFunction(returnValue, 0, "", « »). // iv. Let valueThunk be CreateBuiltinFunction(returnValue, 0, "", « »).
@ -1823,9 +1817,7 @@ impl Promise {
// 1. Return ThrowCompletion(reason). // 1. Return ThrowCompletion(reason).
Err(captures.reason.clone()) Err(captures.reason.clone())
}, },
ThrowReasonCaptures { ThrowReasonCaptures { reason },
reason,
},
); );
// iv. Let thrower be CreateBuiltinFunction(throwReason, 0, "", « »). // iv. Let thrower be CreateBuiltinFunction(throwReason, 0, "", « »).
@ -1834,10 +1826,7 @@ impl Promise {
// v. Return ? Invoke(promise, "then", « thrower »). // v. Return ? Invoke(promise, "then", « thrower »).
promise.invoke("then", &[thrower.into()], context) promise.invoke("then", &[thrower.into()], context)
}, },
FinallyCaptures { FinallyCaptures { on_finally, c },
on_finally,
c,
},
); );
// d. Let catchFinally be CreateBuiltinFunction(catchFinallyClosure, 1, "", « »). // d. Let catchFinally be CreateBuiltinFunction(catchFinallyClosure, 1, "", « »).
@ -1887,7 +1876,12 @@ impl Promise {
promise_obj promise_obj
.as_promise_mut() .as_promise_mut()
.expect("IsPromise(promise) is false") .expect("IsPromise(promise) is false")
.perform_promise_then(&on_fulfilled, &on_rejected, Some(result_capability), context) .perform_promise_then(
&on_fulfilled,
&on_rejected,
Some(result_capability),
context,
)
.pipe(Ok) .pipe(Ok)
} }

20
boa_engine/src/builtins/promise/promise_job.rs

@ -54,9 +54,11 @@ impl PromiseJob {
} }
}, },
// e. Else, let handlerResult be Completion(HostCallJobCallback(handler, undefined, « argument »)). // e. Else, let handlerResult be Completion(HostCallJobCallback(handler, undefined, « argument »)).
Some(handler) => { Some(handler) => handler.call_job_callback(
handler.call_job_callback(&JsValue::undefined(), &[argument.clone()], context) &JsValue::undefined(),
} &[argument.clone()],
context,
),
}; };
match promise_capability { match promise_capability {
@ -83,13 +85,21 @@ impl PromiseJob {
// h. If handlerResult is an abrupt completion, then // h. If handlerResult is an abrupt completion, then
Err(value) => { Err(value) => {
// i. Return ? Call(promiseCapability.[[Reject]], undefined, « handlerResult.[[Value]] »). // i. Return ? Call(promiseCapability.[[Reject]], undefined, « handlerResult.[[Value]] »).
context.call(&reject.clone().into(), &JsValue::undefined(), &[value]) context.call(
&reject.clone().into(),
&JsValue::undefined(),
&[value],
)
} }
// i. Else, // i. Else,
Ok(value) => { Ok(value) => {
// i. Return ? Call(promiseCapability.[[Resolve]], undefined, « handlerResult.[[Value]] »). // i. Return ? Call(promiseCapability.[[Resolve]], undefined, « handlerResult.[[Value]] »).
context.call(&resolve.clone().into(), &JsValue::undefined(), &[value]) context.call(
&resolve.clone().into(),
&JsValue::undefined(),
&[value],
)
} }
} }
} }

3
boa_engine/src/builtins/reflect/mod.rs

@ -104,8 +104,7 @@ impl Reflect {
context: &mut Context, context: &mut Context,
) -> JsResult<JsValue> { ) -> JsResult<JsValue> {
// 1. If IsConstructor(target) is false, throw a TypeError exception. // 1. If IsConstructor(target) is false, throw a TypeError exception.
let target = args let target = args.get_or_undefined(0);
.get_or_undefined(0);
let target = target let target = target
.as_constructor() .as_constructor()
.ok_or_else(|| context.construct_type_error("target must be a constructor"))?; .ok_or_else(|| context.construct_type_error("target must be a constructor"))?;

5
boa_engine/src/object/jsset.rs

@ -5,7 +5,8 @@ use boa_gc::{Finalize, Trace};
use crate::{ use crate::{
builtins::Set, builtins::Set,
object::{JsFunction, JsObject, JsObjectType, JsSetIterator}, object::{JsFunction, JsObject, JsObjectType, JsSetIterator},
Context, JsResult, JsValue, value::JsVariant, value::JsVariant,
Context, JsResult, JsValue,
}; };
// This is an wrapper for `JsSet` // This is an wrapper for `JsSet`
@ -89,7 +90,7 @@ impl JsSet {
where where
T: Into<JsValue>, T: Into<JsValue>,
{ {
match Set::has(&self.inner.clone().into(), &[value.into()], context)?.variant() { match Set::has(&self.inner.clone().into(), &[value.into()], context)?.variant() {
JsVariant::Boolean(bool) => Ok(bool), JsVariant::Boolean(bool) => Ok(bool),
_ => Err(JsValue::undefined()), _ => Err(JsValue::undefined()),
} }

1
boa_engine/src/symbol.rs

@ -270,7 +270,6 @@ unsafe impl Trace for JsSymbol {
unsafe_empty_trace!(); unsafe_empty_trace!();
} }
impl JsSymbol { impl JsSymbol {
/// Create a new symbol. /// Create a new symbol.
#[inline] #[inline]

10
boa_engine/src/value/mod.rs

@ -454,12 +454,12 @@ impl JsValue {
JsVariant::Object(_) => { JsVariant::Object(_) => {
let primitive = self.to_primitive(context, PreferredType::String)?; let primitive = self.to_primitive(context, PreferredType::String)?;
match primitive.variant() { match primitive.variant() {
JsVariant::String(string) => string.clone().into(), JsVariant::String(string) => string.clone().into(),
JsVariant::Symbol(symbol) => symbol.clone().into(), JsVariant::Symbol(symbol) => symbol.clone().into(),
JsVariant::Integer32(integer) => integer.into(), JsVariant::Integer32(integer) => integer.into(),
_ => primitive.to_string(context)?.into(), _ => primitive.to_string(context)?.into(),
}
} }
},
_ => self.to_string(context)?.into(), _ => self.to_string(context)?.into(),
}) })
} }

11
boa_engine/src/vm/code_block.rs

@ -18,9 +18,10 @@ use crate::{
}, },
property::PropertyDescriptor, property::PropertyDescriptor,
syntax::ast::node::FormalParameterList, syntax::ast::node::FormalParameterList,
value::JsVariant,
vm::call_frame::GeneratorResumeKind, vm::call_frame::GeneratorResumeKind,
vm::{call_frame::FinallyReturn, CallFrame, Opcode}, vm::{call_frame::FinallyReturn, CallFrame, Opcode},
Context, JsResult, JsValue, value::JsVariant, Context, JsResult, JsValue,
}; };
use boa_gc::{Cell, Finalize, Gc, Trace}; use boa_gc::{Cell, Finalize, Gc, Trace};
use boa_interner::{Interner, Sym, ToInternedString}; use boa_interner::{Interner, Sym, ToInternedString};
@ -1241,7 +1242,9 @@ impl JsObject {
match function(this_target, args, context)?.variant() { match function(this_target, args, context)?.variant() {
JsVariant::Object(o) => Ok(o.clone()), JsVariant::Object(o) => Ok(o.clone()),
val => { val => {
if constructor.expect("hmm").is_base() || matches!(val, JsVariant::Undefined) { if constructor.expect("hmm").is_base()
|| matches!(val, JsVariant::Undefined)
{
create_this(context) create_this(context)
} else { } else {
context.throw_type_error( context.throw_type_error(
@ -1265,7 +1268,9 @@ impl JsObject {
match (function)(this_target, args, captures, context)?.variant() { match (function)(this_target, args, captures, context)?.variant() {
JsVariant::Object(o) => Ok(o.clone()), JsVariant::Object(o) => Ok(o.clone()),
val => { val => {
if constructor.expect("hmma").is_base() || matches!(val, JsVariant::Undefined) { if constructor.expect("hmma").is_base()
|| matches!(val, JsVariant::Undefined)
{
create_this(context) create_this(context)
} else { } else {
context.throw_type_error( context.throw_type_error(

Loading…
Cancel
Save