Browse Source

Fix `use_self` lints (#2946)

pull/2940/head
raskad 2 years ago committed by GitHub
parent
commit
4a368a2431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      boa_engine/src/builtins/function/mod.rs
  2. 8
      boa_engine/src/builtins/intl/segmenter/mod.rs
  3. 6
      boa_engine/src/builtins/intl/segmenter/options.rs
  4. 2
      boa_engine/src/builtins/intl/segmenter/segments.rs
  5. 22
      boa_engine/src/builtins/mod.rs
  6. 14
      boa_engine/src/builtins/promise/mod.rs
  7. 4
      boa_engine/src/environments/runtime/declarative/function.rs
  8. 58
      boa_engine/src/environments/runtime/declarative/mod.rs
  9. 2
      boa_engine/src/error.rs
  10. 2
      boa_engine/src/lib.rs
  11. 8
      boa_engine/src/module/mod.rs
  12. 59
      boa_engine/src/module/source.rs
  13. 54
      boa_engine/src/object/builtins/jspromise.rs
  14. 4
      boa_engine/src/object/shape/mod.rs
  15. 12
      boa_engine/src/object/shape/shared_shape/mod.rs
  16. 2
      boa_engine/src/object/shape/slot.rs
  17. 2
      boa_engine/src/string/mod.rs
  18. 6
      boa_engine/src/tagged.rs
  19. 2
      boa_engine/src/vm/completion_record.rs
  20. 3
      boa_gc/src/pointers/gc.rs

10
boa_engine/src/builtins/function/mod.rs

@ -228,7 +228,7 @@ pub(crate) enum FunctionKind {
impl fmt::Debug for FunctionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FunctionKind::Native {
Self::Native {
function,
constructor,
} => f
@ -236,16 +236,16 @@ impl fmt::Debug for FunctionKind {
.field("function", &function)
.field("constructor", &constructor)
.finish(),
FunctionKind::Ordinary { .. } => f
Self::Ordinary { .. } => f
.debug_struct("FunctionKind::Ordinary")
.finish_non_exhaustive(),
FunctionKind::Async { .. } => f
Self::Async { .. } => f
.debug_struct("FunctionKind::Async")
.finish_non_exhaustive(),
FunctionKind::Generator { .. } => f
Self::Generator { .. } => f
.debug_struct("FunctionKind::Generator")
.finish_non_exhaustive(),
FunctionKind::AsyncGenerator { .. } => f
Self::AsyncGenerator { .. } => f
.debug_struct("FunctionKind::AsyncGenerator")
.finish_non_exhaustive(),
}

8
boa_engine/src/builtins/intl/segmenter/mod.rs

@ -57,9 +57,9 @@ impl NativeSegmenter {
/// of the segments.
pub(crate) fn segment<'l, 's>(&'l self, input: &'s [u16]) -> NativeSegmentIterator<'l, 's> {
match self {
NativeSegmenter::Grapheme(g) => NativeSegmentIterator::Grapheme(g.segment_utf16(input)),
NativeSegmenter::Word(w) => NativeSegmentIterator::Word(w.segment_utf16(input)),
NativeSegmenter::Sentence(s) => NativeSegmentIterator::Sentence(s.segment_utf16(input)),
Self::Grapheme(g) => NativeSegmentIterator::Grapheme(g.segment_utf16(input)),
Self::Word(w) => NativeSegmentIterator::Word(w.segment_utf16(input)),
Self::Sentence(s) => NativeSegmentIterator::Sentence(s.segment_utf16(input)),
}
}
}
@ -152,7 +152,7 @@ impl BuiltInConstructor for Segmenter {
.try_new_segmenter(granularity)
.map_err(|err| JsNativeError::typ().with_message(err.to_string()))?;
let segmenter = Segmenter {
let segmenter = Self {
locale,
native: kind,
};

6
boa_engine/src/builtins/intl/segmenter/options.rs

@ -13,9 +13,9 @@ pub(crate) enum Granularity {
impl Display for Granularity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Granularity::Grapheme => "grapheme",
Granularity::Word => "word",
Granularity::Sentence => "sentence",
Self::Grapheme => "grapheme",
Self::Word => "word",
Self::Sentence => "sentence",
}
.fmt(f)
}

2
boa_engine/src/builtins/intl/segmenter/segments.rs

@ -54,7 +54,7 @@ impl Segments {
// 5. Return segments.
JsObject::from_proto_and_data(
context.intrinsics().objects().segments_prototype(),
ObjectData::segments(Segments { segmenter, string }),
ObjectData::segments(Self { segmenter, string }),
)
}

22
boa_engine/src/builtins/mod.rs

@ -388,19 +388,19 @@ impl BuiltInObjectInitializer {
P: Into<PropertyDescriptor>,
{
match self {
BuiltInObjectInitializer::Shared(obj) => obj.borrow_mut().insert(key, property),
BuiltInObjectInitializer::Unique { object, .. } => object.insert(key, property),
Self::Shared(obj) => obj.borrow_mut().insert(key, property),
Self::Unique { object, .. } => object.insert(key, property),
};
}
/// Sets the prototype of the builtin
fn set_prototype(&mut self, prototype: JsObject) {
match self {
BuiltInObjectInitializer::Shared(obj) => {
Self::Shared(obj) => {
let mut obj = obj.borrow_mut();
obj.set_prototype(prototype);
}
BuiltInObjectInitializer::Unique { object, .. } => {
Self::Unique { object, .. } => {
object.set_prototype(prototype);
}
}
@ -414,14 +414,14 @@ impl BuiltInObjectInitializer {
/// builtin's vtable.
fn set_data(&mut self, new_data: ObjectData) {
match self {
BuiltInObjectInitializer::Shared(obj) => {
Self::Shared(obj) => {
assert!(
std::ptr::eq(obj.vtable(), new_data.internal_methods),
"intrinsic object's vtable didn't match with new data"
);
*obj.borrow_mut().kind_mut() = new_data.kind;
}
BuiltInObjectInitializer::Unique { ref mut data, .. } => *data = new_data,
Self::Unique { ref mut data, .. } => *data = new_data,
}
}
@ -429,19 +429,19 @@ impl BuiltInObjectInitializer {
fn as_shared(&mut self) -> JsObject {
match std::mem::replace(
self,
BuiltInObjectInitializer::Unique {
Self::Unique {
object: Object::default(),
data: ObjectData::ordinary(),
},
) {
BuiltInObjectInitializer::Shared(obj) => {
*self = BuiltInObjectInitializer::Shared(obj.clone());
Self::Shared(obj) => {
*self = Self::Shared(obj.clone());
obj
}
BuiltInObjectInitializer::Unique { mut object, data } => {
Self::Unique { mut object, data } => {
*object.kind_mut() = data.kind;
let obj = JsObject::from_object_and_vtable(object, data.internal_methods);
*self = BuiltInObjectInitializer::Shared(obj.clone());
*self = Self::Shared(obj.clone());
obj
}
}

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

@ -42,8 +42,8 @@ pub enum PromiseState {
unsafe impl Trace for PromiseState {
custom_trace!(this, {
match this {
PromiseState::Fulfilled(v) | PromiseState::Rejected(v) => mark(v),
PromiseState::Pending => {}
Self::Fulfilled(v) | Self::Rejected(v) => mark(v),
Self::Pending => {}
}
});
}
@ -53,7 +53,7 @@ impl PromiseState {
/// the state is not `Fulfilled`.
pub const fn as_fulfilled(&self) -> Option<&JsValue> {
match self {
PromiseState::Fulfilled(v) => Some(v),
Self::Fulfilled(v) => Some(v),
_ => None,
}
}
@ -62,7 +62,7 @@ impl PromiseState {
/// the state is not `Rejected`.
pub const fn as_rejected(&self) -> Option<&JsValue> {
match self {
PromiseState::Rejected(v) => Some(v),
Self::Rejected(v) => Some(v),
_ => None,
}
}
@ -432,7 +432,7 @@ impl BuiltInConstructor for Promise {
impl Promise {
/// Creates a new, pending `Promise`.
pub(crate) fn new() -> Self {
Promise {
Self {
state: PromiseState::Pending,
fulfill_reactions: Vec::default(),
reject_reactions: Vec::default(),
@ -1440,7 +1440,7 @@ impl Promise {
JsNativeError::typ().with_message("Promise.reject() called on a non-object")
})?;
Promise::promise_reject(c, &JsError::from_opaque(r), context).map(JsValue::from)
Self::promise_reject(c, &JsError::from_opaque(r), context).map(JsValue::from)
}
/// Utility function to create a rejected promise.
@ -1764,7 +1764,7 @@ impl Promise {
.and_then(JsFunction::from_object);
// continues in `Promise::inner_then`
Promise::inner_then(promise, on_fulfilled, on_rejected, context).map(JsValue::from)
Self::inner_then(promise, on_fulfilled, on_rejected, context).map(JsValue::from)
}
/// Schedules callback functions for the eventual completion of `promise` — either fulfillment

4
boa_engine/src/environments/runtime/declarative/function.rs

@ -163,8 +163,8 @@ pub(crate) enum ThisBindingStatus {
unsafe impl Trace for ThisBindingStatus {
custom_trace!(this, {
match this {
ThisBindingStatus::Initialized(obj) => mark(obj),
ThisBindingStatus::Lexical | ThisBindingStatus::Uninitialized => {}
Self::Initialized(obj) => mark(obj),
Self::Lexical | Self::Uninitialized => {}
}
});
}

58
boa_engine/src/environments/runtime/declarative/mod.rs

@ -42,7 +42,7 @@ pub(crate) struct DeclarativeEnvironment {
impl DeclarativeEnvironment {
/// Creates a new global `DeclarativeEnvironment`.
pub(crate) fn global(global_this: JsObject) -> Self {
DeclarativeEnvironment {
Self {
kind: DeclarativeEnvironmentKind::Global(GlobalEnvironment::new(global_this)),
compile: Gc::new(GcRefCell::new(CompileTimeEnvironment::new_global())),
}
@ -175,10 +175,10 @@ impl DeclarativeEnvironmentKind {
#[track_caller]
pub(crate) fn get(&self, index: usize) -> Option<JsValue> {
match self {
DeclarativeEnvironmentKind::Lexical(inner) => inner.get(index),
DeclarativeEnvironmentKind::Global(inner) => inner.get(index),
DeclarativeEnvironmentKind::Function(inner) => inner.get(index),
DeclarativeEnvironmentKind::Module(inner) => inner.get(index),
Self::Lexical(inner) => inner.get(index),
Self::Global(inner) => inner.get(index),
Self::Function(inner) => inner.get(index),
Self::Module(inner) => inner.get(index),
}
}
@ -190,10 +190,10 @@ impl DeclarativeEnvironmentKind {
#[track_caller]
pub(crate) fn set(&self, index: usize, value: JsValue) {
match self {
DeclarativeEnvironmentKind::Lexical(inner) => inner.set(index, value),
DeclarativeEnvironmentKind::Global(inner) => inner.set(index, value),
DeclarativeEnvironmentKind::Function(inner) => inner.set(index, value),
DeclarativeEnvironmentKind::Module(inner) => inner.set(index, value),
Self::Lexical(inner) => inner.set(index, value),
Self::Global(inner) => inner.set(index, value),
Self::Function(inner) => inner.set(index, value),
Self::Module(inner) => inner.set(index, value),
}
}
@ -207,10 +207,10 @@ impl DeclarativeEnvironmentKind {
/// [spec]: https://tc39.es/ecma262/#sec-function-environment-records-getthisbinding
pub(crate) fn get_this_binding(&self) -> JsResult<Option<JsValue>> {
match self {
DeclarativeEnvironmentKind::Lexical(_) => Ok(None),
DeclarativeEnvironmentKind::Global(g) => Ok(Some(g.get_this_binding().into())),
DeclarativeEnvironmentKind::Function(f) => f.get_this_binding(),
DeclarativeEnvironmentKind::Module(_) => Ok(Some(JsValue::undefined())),
Self::Lexical(_) => Ok(None),
Self::Global(g) => Ok(Some(g.get_this_binding().into())),
Self::Function(f) => f.get_this_binding(),
Self::Module(_) => Ok(Some(JsValue::undefined())),
}
}
@ -224,39 +224,39 @@ impl DeclarativeEnvironmentKind {
/// [spec]: https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding
pub(crate) fn has_this_binding(&self) -> bool {
match self {
DeclarativeEnvironmentKind::Lexical(_) => false,
DeclarativeEnvironmentKind::Function(f) => f.has_this_binding(),
DeclarativeEnvironmentKind::Global(_) | DeclarativeEnvironmentKind::Module(_) => true,
Self::Lexical(_) => false,
Self::Function(f) => f.has_this_binding(),
Self::Global(_) | Self::Module(_) => true,
}
}
/// Returns `true` if this environment is poisoned.
pub(crate) fn poisoned(&self) -> bool {
match self {
DeclarativeEnvironmentKind::Lexical(lex) => lex.poisonable_environment().poisoned(),
DeclarativeEnvironmentKind::Global(g) => g.poisonable_environment().poisoned(),
DeclarativeEnvironmentKind::Function(f) => f.poisonable_environment().poisoned(),
DeclarativeEnvironmentKind::Module(_) => false,
Self::Lexical(lex) => lex.poisonable_environment().poisoned(),
Self::Global(g) => g.poisonable_environment().poisoned(),
Self::Function(f) => f.poisonable_environment().poisoned(),
Self::Module(_) => false,
}
}
/// Returns `true` if this environment is inside a `with` environment.
pub(crate) fn with(&self) -> bool {
match self {
DeclarativeEnvironmentKind::Lexical(lex) => lex.poisonable_environment().with(),
DeclarativeEnvironmentKind::Global(g) => g.poisonable_environment().with(),
DeclarativeEnvironmentKind::Function(f) => f.poisonable_environment().with(),
DeclarativeEnvironmentKind::Module(_) => false,
Self::Lexical(lex) => lex.poisonable_environment().with(),
Self::Global(g) => g.poisonable_environment().with(),
Self::Function(f) => f.poisonable_environment().with(),
Self::Module(_) => false,
}
}
/// Poisons this environment for future binding searches.
pub(crate) fn poison(&self) {
match self {
DeclarativeEnvironmentKind::Lexical(lex) => lex.poisonable_environment().poison(),
DeclarativeEnvironmentKind::Global(g) => g.poisonable_environment().poison(),
DeclarativeEnvironmentKind::Function(f) => f.poisonable_environment().poison(),
DeclarativeEnvironmentKind::Module(_) => {
Self::Lexical(lex) => lex.poisonable_environment().poison(),
Self::Global(g) => g.poisonable_environment().poison(),
Self::Function(f) => f.poisonable_environment().poison(),
Self::Module(_) => {
unreachable!("modules are always run in strict mode")
}
}
@ -275,7 +275,7 @@ pub(crate) struct PoisonableEnvironment {
impl PoisonableEnvironment {
/// Creates a new `PoisonableEnvironment`.
pub(crate) fn new(bindings_count: usize, poisoned: bool, with: bool) -> Self {
PoisonableEnvironment {
Self {
bindings: GcRefCell::new(vec![None; bindings_count]),
poisoned: Cell::new(poisoned),
with: Cell::new(with),

2
boa_engine/src/error.rs

@ -362,7 +362,7 @@ impl JsError {
///
/// This is a no-op if the error is not native or if the `realm` field of the error is already
/// set.
pub(crate) fn inject_realm(mut self, realm: Realm) -> JsError {
pub(crate) fn inject_realm(mut self, realm: Realm) -> Self {
match &mut self.inner {
Repr::Native(err) if err.realm.is_none() => {
err.realm = Some(realm);

2
boa_engine/src/lib.rs

@ -113,8 +113,6 @@
clippy::missing_errors_doc,
clippy::let_unit_value,
clippy::option_if_let_else,
// Currently lints in places where `Self` would have a type parameter.
clippy::use_self,
// It may be worth to look if we can fix the issues highlighted by these lints.
clippy::cast_possible_truncation,

8
boa_engine/src/module/mod.rs

@ -291,7 +291,7 @@ impl Module {
src: Source<'_, R>,
realm: Option<Realm>,
context: &mut Context<'_>,
) -> JsResult<Module> {
) -> JsResult<Self> {
let _timer = Profiler::global().start_event("Module parsing", "Main");
let mut parser = Parser::new(src);
parser.set_identifier(context.next_parser_identifier());
@ -299,7 +299,7 @@ impl Module {
let src = SourceTextModule::new(module);
let module = Module {
let module = Self {
inner: Gc::new(Inner {
realm: realm.unwrap_or_else(|| context.realm().clone()),
environment: GcRefCell::default(),
@ -448,7 +448,7 @@ impl Module {
pub(crate) fn resolve_export(
&self,
export_name: Sym,
resolve_set: &mut FxHashSet<(Module, Sym)>,
resolve_set: &mut FxHashSet<(Self, Sym)>,
) -> Result<ResolvedBinding, ResolveExportError> {
match self.kind() {
ModuleKind::SourceText(src) => src.resolve_export(export_name, resolve_set),
@ -714,7 +714,7 @@ impl ModuleNamespace {
// 7. Set M.[[Exports]] to sortedExports.
// 8. Create own properties of M corresponding to the definitions in 28.3.
let namespace = context.intrinsics().templates().namespace().create(
ObjectData::module_namespace(ModuleNamespace { module, exports }),
ObjectData::module_namespace(Self { module, exports }),
vec![js_string!("Module").into()],
);

59
boa_engine/src/module/source.rs

@ -95,18 +95,18 @@ enum Status {
unsafe impl Trace for Status {
custom_trace!(this, {
match this {
Status::Unlinked | Status::Linking { info: _ } => {}
Status::PreLinked { context, info: _ } | Status::Linked { context, info: _ } => {
Self::Unlinked | Self::Linking { info: _ } => {}
Self::PreLinked { context, info: _ } | Self::Linked { context, info: _ } => {
mark(context);
}
Status::Evaluating {
Self::Evaluating {
top_level_capability,
cycle_root,
context,
info: _,
async_eval_index: _,
}
| Status::EvaluatingAsync {
| Self::EvaluatingAsync {
top_level_capability,
cycle_root,
context,
@ -117,7 +117,7 @@ unsafe impl Trace for Status {
mark(cycle_root);
mark(context);
}
Status::Evaluated {
Self::Evaluated {
top_level_capability,
cycle_root,
error,
@ -135,11 +135,11 @@ impl Status {
/// module is not in a state executing the dfs algorithm.
const fn dfs_info(&self) -> Option<&DfsInfo> {
match self {
Status::Unlinked | Status::EvaluatingAsync { .. } | Status::Evaluated { .. } => None,
Status::Linking { info }
| Status::PreLinked { info, .. }
| Status::Linked { info, .. }
| Status::Evaluating { info, .. } => Some(info),
Self::Unlinked | Self::EvaluatingAsync { .. } | Self::Evaluated { .. } => None,
Self::Linking { info }
| Self::PreLinked { info, .. }
| Self::Linked { info, .. }
| Self::Evaluating { info, .. } => Some(info),
}
}
@ -147,11 +147,11 @@ impl Status {
/// or `None` if the module is not in a state executing the dfs algorithm.
fn dfs_info_mut(&mut self) -> Option<&mut DfsInfo> {
match self {
Status::Unlinked | Status::EvaluatingAsync { .. } | Status::Evaluated { .. } => None,
Status::Linking { info }
| Status::PreLinked { info, .. }
| Status::Linked { info, .. }
| Status::Evaluating { info, .. } => Some(info),
Self::Unlinked | Self::EvaluatingAsync { .. } | Self::Evaluated { .. } => None,
Self::Linking { info }
| Self::PreLinked { info, .. }
| Self::Linked { info, .. }
| Self::Evaluating { info, .. } => Some(info),
}
}
@ -159,19 +159,19 @@ impl Status {
/// level capability.
const fn top_level_capability(&self) -> Option<&PromiseCapability> {
match &self {
Status::Unlinked
| Status::Linking { .. }
| Status::PreLinked { .. }
| Status::Linked { .. } => None,
Status::Evaluating {
Self::Unlinked
| Self::Linking { .. }
| Self::PreLinked { .. }
| Self::Linked { .. } => None,
Self::Evaluating {
top_level_capability,
..
}
| Status::EvaluatingAsync {
| Self::EvaluatingAsync {
top_level_capability,
..
}
| Status::Evaluated {
| Self::Evaluated {
top_level_capability,
..
} => top_level_capability.as_ref(),
@ -181,7 +181,7 @@ impl Status {
/// If this module is in the evaluated state, gets its `error` field.
const fn evaluation_error(&self) -> Option<&JsError> {
match &self {
Status::Evaluated { error, .. } => error.as_ref(),
Self::Evaluated { error, .. } => error.as_ref(),
_ => None,
}
}
@ -189,9 +189,9 @@ impl Status {
/// If this module is in the evaluating state, gets its cycle root.
const fn cycle_root(&self) -> Option<&SourceTextModule> {
match &self {
Status::Evaluating { cycle_root, .. }
| Status::EvaluatingAsync { cycle_root, .. }
| Status::Evaluated { cycle_root, .. } => Some(cycle_root),
Self::Evaluating { cycle_root, .. }
| Self::EvaluatingAsync { cycle_root, .. }
| Self::Evaluated { cycle_root, .. } => Some(cycle_root),
_ => None,
}
}
@ -200,7 +200,7 @@ impl Status {
/// between states.
fn transition<F>(&mut self, f: F)
where
F: FnOnce(Status) -> Status,
F: FnOnce(Self) -> Self,
{
*self = f(std::mem::take(self));
}
@ -509,10 +509,7 @@ impl SourceTextModule {
/// Concrete method [`GetExportedNames ( [ exportStarSet ] )`][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-getexportednames
pub(super) fn get_exported_names(
&self,
export_star_set: &mut Vec<SourceTextModule>,
) -> FxHashSet<Sym> {
pub(super) fn get_exported_names(&self, export_star_set: &mut Vec<Self>) -> FxHashSet<Sym> {
// 1. Assert: module.[[Status]] is not new.
// 2. If exportStarSet is not present, set exportStarSet to a new empty List.

54
boa_engine/src/object/builtins/jspromise.rs

@ -150,7 +150,7 @@ impl JsPromise {
/// ```
///
/// [`Promise()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
pub fn new<F>(executor: F, context: &mut Context<'_>) -> JsResult<JsPromise>
pub fn new<F>(executor: F, context: &mut Context<'_>) -> JsResult<Self>
where
F: FnOnce(&ResolvingFunctions, &mut Context<'_>) -> JsResult<JsValue>,
{
@ -168,7 +168,7 @@ impl JsPromise {
.call(&JsValue::undefined(), &[e], context)?;
}
Ok(JsPromise { inner: promise })
Ok(Self { inner: promise })
}
/// Creates a new pending promise and returns it and its associated `ResolvingFunctions`.
@ -201,15 +201,15 @@ impl JsPromise {
/// # }
/// ```
#[inline]
pub fn new_pending(context: &mut Context<'_>) -> (JsPromise, ResolvingFunctions) {
pub fn new_pending(context: &mut Context<'_>) -> (Self, ResolvingFunctions) {
let promise = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
context.intrinsics().constructors().promise().prototype(),
ObjectData::promise(Promise::new()),
);
let resolvers = Promise::create_resolving_functions(&promise, context);
let promise = JsPromise::from_object(promise)
.expect("this shouldn't fail with a newly created promise");
let promise =
Self::from_object(promise).expect("this shouldn't fail with a newly created promise");
(promise, resolvers)
}
@ -281,13 +281,13 @@ impl JsPromise {
///
/// [`Promise.resolve()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve
/// [thenables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables
pub fn resolve<V: Into<JsValue>>(value: V, context: &mut Context<'_>) -> JsResult<JsPromise> {
pub fn resolve<V: Into<JsValue>>(value: V, context: &mut Context<'_>) -> JsResult<Self> {
Promise::promise_resolve(
&context.intrinsics().constructors().promise().constructor(),
value.into(),
context,
)
.and_then(JsPromise::from_object)
.and_then(Self::from_object)
}
/// Creates a `JsPromise` that is rejected with the reason `error`.
@ -319,13 +319,13 @@ impl JsPromise {
///
/// [`Promise.reject`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject
/// [thenable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables
pub fn reject<E: Into<JsError>>(error: E, context: &mut Context<'_>) -> JsResult<JsPromise> {
pub fn reject<E: Into<JsError>>(error: E, context: &mut Context<'_>) -> JsResult<Self> {
Promise::promise_reject(
&context.intrinsics().constructors().promise().constructor(),
&error.into(),
context,
)
.and_then(JsPromise::from_object)
.and_then(Self::from_object)
}
/// Gets the current state of the promise.
@ -438,9 +438,9 @@ impl JsPromise {
on_fulfilled: Option<JsFunction>,
on_rejected: Option<JsFunction>,
context: &mut Context<'_>,
) -> JsResult<JsPromise> {
) -> JsResult<Self> {
let result_promise = Promise::inner_then(self, on_fulfilled, on_rejected, context)?;
JsPromise::from_object(result_promise)
Self::from_object(result_promise)
}
/// Schedules a callback to run when the promise is rejected.
@ -498,7 +498,7 @@ impl JsPromise {
/// [`Promise.prototype.catch`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
/// [then]: JsPromise::then
#[inline]
pub fn catch(&self, on_rejected: JsFunction, context: &mut Context<'_>) -> JsResult<JsPromise> {
pub fn catch(&self, on_rejected: JsFunction, context: &mut Context<'_>) -> JsResult<Self> {
self.then(None, Some(on_rejected), context)
}
@ -566,11 +566,7 @@ impl JsPromise {
/// [`Promise.prototype.finally()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
/// [then]: JsPromise::then
#[inline]
pub fn finally(
&self,
on_finally: JsFunction,
context: &mut Context<'_>,
) -> JsResult<JsPromise> {
pub fn finally(&self, on_finally: JsFunction, context: &mut Context<'_>) -> JsResult<Self> {
let c = self.species_constructor(StandardConstructors::promise, context)?;
let (then, catch) = Promise::then_catch_finally_closures(c, on_finally, context);
self.then(Some(then), Some(catch), context)
@ -627,9 +623,9 @@ impl JsPromise {
/// ```
///
/// [`Promise.all`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
pub fn all<I>(promises: I, context: &mut Context<'_>) -> JsResult<JsPromise>
pub fn all<I>(promises: I, context: &mut Context<'_>) -> JsResult<Self>
where
I: IntoIterator<Item = JsPromise>,
I: IntoIterator<Item = Self>,
{
let promises = JsArray::from_iter(promises.into_iter().map(JsValue::from), context);
@ -645,7 +641,7 @@ impl JsPromise {
.as_object()
.expect("Promise.all always returns an object on success");
JsPromise::from_object(value.clone())
Self::from_object(value.clone())
}
/// Waits for a list of promises to settle, fulfilling with an array of the outcomes of every
@ -696,9 +692,9 @@ impl JsPromise {
/// ```
///
/// [`Promise.allSettled`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled
pub fn all_settled<I>(promises: I, context: &mut Context<'_>) -> JsResult<JsPromise>
pub fn all_settled<I>(promises: I, context: &mut Context<'_>) -> JsResult<Self>
where
I: IntoIterator<Item = JsPromise>,
I: IntoIterator<Item = Self>,
{
let promises = JsArray::from_iter(promises.into_iter().map(JsValue::from), context);
@ -714,7 +710,7 @@ impl JsPromise {
.as_object()
.expect("Promise.allSettled always returns an object on success");
JsPromise::from_object(value.clone())
Self::from_object(value.clone())
}
/// Returns the first promise that fulfills from a list of promises.
@ -758,9 +754,9 @@ impl JsPromise {
/// ```
///
/// [`Promise.any`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any
pub fn any<I>(promises: I, context: &mut Context<'_>) -> JsResult<JsPromise>
pub fn any<I>(promises: I, context: &mut Context<'_>) -> JsResult<Self>
where
I: IntoIterator<Item = JsPromise>,
I: IntoIterator<Item = Self>,
{
let promises = JsArray::from_iter(promises.into_iter().map(JsValue::from), context);
@ -776,7 +772,7 @@ impl JsPromise {
.as_object()
.expect("Promise.any always returns an object on success");
JsPromise::from_object(value.clone())
Self::from_object(value.clone())
}
/// Returns the first promise that settles from a list of promises.
@ -821,9 +817,9 @@ impl JsPromise {
/// ```
///
/// [`Promise.race`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race
pub fn race<I>(promises: I, context: &mut Context<'_>) -> JsResult<JsPromise>
pub fn race<I>(promises: I, context: &mut Context<'_>) -> JsResult<Self>
where
I: IntoIterator<Item = JsPromise>,
I: IntoIterator<Item = Self>,
{
let promises = JsArray::from_iter(promises.into_iter().map(JsValue::from), context);
@ -839,7 +835,7 @@ impl JsPromise {
.as_object()
.expect("Promise.race always returns an object on success");
JsPromise::from_object(value.clone())
Self::from_object(value.clone())
}
}

4
boa_engine/src/object/shape/mod.rs

@ -64,7 +64,7 @@ pub struct Shape {
impl Default for Shape {
fn default() -> Self {
Shape::unique(UniqueShape::default())
Self::unique(UniqueShape::default())
}
}
@ -131,7 +131,7 @@ impl Shape {
pub(crate) fn change_attributes_transition(
&self,
key: TransitionKey,
) -> ChangeTransition<Shape> {
) -> ChangeTransition<Self> {
match &self.inner {
Inner::Shared(shape) => {
let change_transition = shape.change_attributes_transition(key);

12
boa_engine/src/object/shape/shared_shape/mod.rs

@ -54,15 +54,15 @@ impl Default for ShapeFlags {
impl ShapeFlags {
// NOTE: Remove type bits and set the new ones.
fn insert_property_transition_from(previous: ShapeFlags) -> Self {
fn insert_property_transition_from(previous: Self) -> Self {
previous.difference(Self::TRANSITION_TYPE)
| Self::from_bits_retain(INSERT_PROPERTY_TRANSITION_TYPE)
}
fn configure_property_transition_from(previous: ShapeFlags) -> Self {
fn configure_property_transition_from(previous: Self) -> Self {
previous.difference(Self::TRANSITION_TYPE)
| Self::from_bits_retain(CONFIGURE_PROPERTY_TRANSITION_TYPE)
}
fn prototype_transition_from(previous: ShapeFlags) -> Self {
fn prototype_transition_from(previous: Self) -> Self {
previous.difference(Self::TRANSITION_TYPE)
| Self::from_bits_retain(PROTOTYPE_TRANSITION_TYPE)
}
@ -133,7 +133,7 @@ impl SharedShape {
self.inner.transition_count
}
/// Getter for the previous field.
pub fn previous(&self) -> Option<&SharedShape> {
pub fn previous(&self) -> Option<&Self> {
self.inner.previous.as_ref()
}
/// Get the prototype of the shape.
@ -245,7 +245,7 @@ impl SharedShape {
pub(crate) fn change_attributes_transition(
&self,
key: TransitionKey,
) -> ChangeTransition<SharedShape> {
) -> ChangeTransition<Self> {
let slot = self.property_table().get_expect(&key.property_key);
// Check if we have already created such a transition, if so use it!
@ -355,7 +355,7 @@ impl SharedShape {
&self,
key: &PropertyKey,
) -> (
SharedShape,
Self,
Option<JsPrototype>,
IndexMap<PropertyKey, SlotAttributes>,
) {

2
boa_engine/src/object/shape/slot.rs

@ -58,7 +58,7 @@ impl Slot {
///
/// This is needed because slots do not have the same width.
pub(crate) fn from_previous(
previous_slot: Option<Slot>,
previous_slot: Option<Self>,
new_attributes: SlotAttributes,
) -> Self {
// If there was no previous slot then return 0 as the index.

2
boa_engine/src/string/mod.rs

@ -295,7 +295,7 @@ impl JsString {
impl<I: Iterator> WideStringDecoderIterator<I> {
fn new(iterator: I) -> Self {
WideStringDecoderIterator {
Self {
codepoints: iterator.peekable(),
}
}

6
boa_engine/src/tagged.rs

@ -46,7 +46,7 @@ impl<T> Tagged<T> {
///
/// - `T` must have an alignment of at least 2.
/// - `tag` must fit inside `usize::BITS - 1` bits
pub(crate) const fn from_tag(tag: usize) -> Tagged<T> {
pub(crate) const fn from_tag(tag: usize) -> Self {
debug_assert!(std::mem::align_of::<T>() >= 2);
let addr = (tag << 1) | 1;
// SAFETY: `addr` is never zero, since we always set its LSB to 1
@ -62,7 +62,7 @@ impl<T> Tagged<T> {
/// # Safety
///
/// - `T` must be non null.
pub(crate) const unsafe fn from_ptr(ptr: *mut T) -> Tagged<T> {
pub(crate) const unsafe fn from_ptr(ptr: *mut T) -> Self {
debug_assert!(std::mem::align_of::<T>() >= 2);
// SAFETY: the caller must ensure the invariants hold.
unsafe { Self(NonNull::new_unchecked(ptr)) }
@ -73,7 +73,7 @@ impl<T> Tagged<T> {
/// # Requirements
///
/// - `T` must have an alignment of at least 2.
pub(crate) const fn from_non_null(ptr: NonNull<T>) -> Tagged<T> {
pub(crate) const fn from_non_null(ptr: NonNull<T>) -> Self {
debug_assert!(std::mem::align_of::<T>() >= 2);
Self(ptr)
}

2
boa_engine/src/vm/completion_record.rs

@ -16,7 +16,7 @@ pub(crate) enum CompletionRecord {
// ---- `CompletionRecord` methods ----
impl CompletionRecord {
pub(crate) const fn is_throw_completion(&self) -> bool {
matches!(self, CompletionRecord::Throw(_))
matches!(self, Self::Throw(_))
}
/// This function will consume the current `CompletionRecord` and return a `JsResult<JsValue>`

3
boa_gc/src/pointers/gc.rs

@ -46,8 +46,7 @@ impl<T: Trace> Gc<T> {
/// Consumes the `Gc`, returning a wrapped raw pointer.
///
/// To avoid a memory leak, the pointer must be converted back to a `Gc` using [`Gc::from_raw`].
#[allow(clippy::use_self)]
pub fn into_raw(this: Gc<T>) -> NonNull<GcBox<T>> {
pub fn into_raw(this: Self) -> NonNull<GcBox<T>> {
let ptr = this.inner_ptr();
std::mem::forget(this);
ptr

Loading…
Cancel
Save