Skip to content

Commit 92b7fa0

Browse files
committed
fix: formatting and lint issues
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
1 parent 81a3f59 commit 92b7fa0

File tree

9 files changed

+46
-59
lines changed

9 files changed

+46
-59
lines changed

core/engine/src/bytecompiler/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,10 +2258,10 @@ impl<'ctx> ByteCompiler<'ctx> {
22582258
} else {
22592259
self.bytecode.emit_store_undefined(value.variable());
22602260
}
2261-
2261+
22622262
// Add resource to disposal stack
22632263
self.bytecode.emit_add_disposable_resource(value.variable());
2264-
2264+
22652265
self.emit_binding(BindingOpcode::InitLexical, ident, &value);
22662266
self.register_allocator.dealloc(value);
22672267
}
@@ -2273,10 +2273,10 @@ impl<'ctx> ByteCompiler<'ctx> {
22732273
} else {
22742274
self.bytecode.emit_store_undefined(value.variable());
22752275
}
2276-
2276+
22772277
// Add resource to disposal stack
22782278
self.bytecode.emit_add_disposable_resource(value.variable());
2279-
2279+
22802280
self.compile_declaration_pattern(
22812281
pattern,
22822282
BindingOpcode::InitLexical,

core/engine/src/bytecompiler/statement/block.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ impl ByteCompiler<'_> {
1010
pub(crate) fn compile_block(&mut self, block: &Block, use_expr: bool) {
1111
let scope = self.push_declarative_scope(block.scope());
1212
self.block_declaration_instantiation(block);
13-
13+
1414
// Check if this block has any using declarations
15-
let has_using = lexically_scoped_declarations(block)
16-
.iter()
17-
.any(|decl| matches!(
15+
let has_using = lexically_scoped_declarations(block).iter().any(|decl| {
16+
matches!(
1817
decl,
1918
LexicallyScopedDeclaration::LexicalDeclaration(
2019
LexicalDeclaration::Using(_) | LexicalDeclaration::AwaitUsing(_)
2120
)
22-
));
23-
21+
)
22+
});
23+
2424
// Push disposal scope if this block has using declarations
2525
if has_using {
2626
self.bytecode.emit_push_disposal_scope();
2727
}
28-
28+
2929
self.compile_statement_list(block.statement_list(), use_expr, true);
30-
30+
3131
// Dispose resources if this block has using declarations
3232
if has_using {
3333
self.bytecode.emit_dispose_resources();
3434
}
35-
35+
3636
self.pop_declarative_scope(scope);
3737
}
3838
}

core/engine/src/vm/code_block.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,10 @@ impl CodeBlock {
892892
| Instruction::SuperCallSpread
893893
| Instruction::PopPrivateEnvironment
894894
| Instruction::Generator
895-
| Instruction::AsyncGenerator => String::new(),
896-
Instruction::AddDisposableResource { value } => {
897-
format!("value: {value}")
898-
}
899-
Instruction::DisposeResources => String::new(),
900-
Instruction::PushDisposalScope => String::new(),
895+
| Instruction::AsyncGenerator
896+
| Instruction::AddDisposableResource { .. }
897+
| Instruction::DisposeResources
898+
| Instruction::PushDisposalScope => String::new(),
901899
Instruction::Reserved4
902900
| Instruction::Reserved5
903901
| Instruction::Reserved6

core/engine/src/vm/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ pub struct Vm {
101101
/// Stack of disposable resources for explicit resource management.
102102
///
103103
/// Resources are added via `using` declarations and disposed in reverse order (LIFO)
104-
/// when the scope exits. Each entry contains (value, dispose_method, scope_depth).
104+
/// when the scope exits. Each entry contains (`value`, `dispose_method`, `scope_depth`).
105105
pub(crate) disposal_stack: Vec<(JsValue, JsValue)>,
106-
106+
107107
/// Tracks the disposal stack depth for each scope level.
108108
/// When a scope exits, we dispose resources back to this depth.
109109
pub(crate) disposal_scope_depths: Vec<usize>,
@@ -620,17 +620,17 @@ impl Vm {
620620
pub(crate) fn pop_disposable_resource(&mut self) -> Option<(JsValue, JsValue)> {
621621
self.disposal_stack.pop()
622622
}
623-
623+
624624
/// Mark the current disposal stack depth for a new scope.
625625
pub(crate) fn push_disposal_scope(&mut self) {
626626
self.disposal_scope_depths.push(self.disposal_stack.len());
627627
}
628-
628+
629629
/// Get the disposal stack depth for the current scope.
630630
pub(crate) fn current_disposal_scope_depth(&self) -> usize {
631631
self.disposal_scope_depths.last().copied().unwrap_or(0)
632632
}
633-
633+
634634
/// Pop the disposal scope depth marker.
635635
pub(crate) fn pop_disposal_scope(&mut self) {
636636
self.disposal_scope_depths.pop();

core/engine/src/vm/opcode/disposal/add_disposable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
vm::opcode::{Operation, RegisterOperand},
32
Context, JsResult,
3+
vm::opcode::{Operation, RegisterOperand},
44
};
55

66
/// `AddDisposableResource` implements the AddDisposableResource operation.
@@ -32,7 +32,9 @@ impl AddDisposableResource {
3232
};
3333

3434
// Add to disposal stack
35-
context.vm.push_disposable_resource(value, dispose_method.into());
35+
context
36+
.vm
37+
.push_disposable_resource(value, dispose_method.into());
3638

3739
Ok(())
3840
}

core/engine/src/vm/opcode/disposal/dispose_resources.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
vm::opcode::Operation,
3-
Context, JsError, JsNativeError, JsResult,
4-
};
1+
use crate::{Context, JsError, JsNativeError, JsResult, vm::opcode::Operation};
52

63
/// `DisposeResources` implements the DisposeResources operation.
74
///
@@ -14,7 +11,7 @@ pub(crate) struct DisposeResources;
1411
impl DisposeResources {
1512
pub(crate) fn operation((): (), context: &mut Context) -> JsResult<()> {
1613
let mut suppressed_error: Option<JsError> = None;
17-
14+
1815
// Get the scope depth to know how many resources to dispose
1916
let scope_depth = context.vm.current_disposal_scope_depth();
2017

@@ -30,13 +27,13 @@ impl DisposeResources {
3027
None => err,
3128
Some(previous) => {
3229
// Create a SuppressedError
33-
create_suppressed_error(err, previous, context)
30+
create_suppressed_error(err, &previous, context)
3431
}
3532
});
3633
}
3734
}
3835
}
39-
36+
4037
// Pop the disposal scope depth marker
4138
context.vm.pop_disposal_scope();
4239

@@ -56,19 +53,16 @@ impl Operation for DisposeResources {
5653
}
5754

5855
/// Helper function to create a SuppressedError
59-
fn create_suppressed_error(_error: JsError, suppressed: JsError, _context: &mut Context) -> JsError {
56+
fn create_suppressed_error(
57+
_error: JsError,
58+
suppressed: &JsError,
59+
_context: &mut Context,
60+
) -> JsError {
6061
// For now, we'll create a simple error that contains both errors
6162
// TODO: Implement proper SuppressedError builtin in Phase 2
62-
let message = format!(
63-
"An error was suppressed during disposal: {}",
64-
suppressed
65-
);
66-
67-
let err = JsNativeError::error()
68-
.with_message(message)
69-
.into();
70-
63+
let message = format!("An error was suppressed during disposal: {suppressed}");
64+
7165
// Attach the original error as a property
7266
// This is a temporary solution until SuppressedError is implemented
73-
err
67+
JsNativeError::error().with_message(message).into()
7468
}

core/engine/src/vm/opcode/disposal/push_scope.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
vm::opcode::Operation,
3-
Context, JsResult,
4-
};
1+
use crate::{Context, vm::opcode::Operation};
52

63
/// `PushDisposalScope` marks the current disposal stack depth for a new scope.
74
///
@@ -12,9 +9,8 @@ use crate::{
129
pub(crate) struct PushDisposalScope;
1310

1411
impl PushDisposalScope {
15-
pub(crate) fn operation((): (), context: &mut Context) -> JsResult<()> {
12+
pub(crate) fn operation((): (), context: &mut Context) {
1613
context.vm.push_disposal_scope();
17-
Ok(())
1814
}
1915
}
2016

core/engine/src/vm/opcode/global.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
vm::opcode::{Operation, RegisterOperand, IndexOperand},
32
Context, JsResult,
3+
vm::opcode::{IndexOperand, Operation, RegisterOperand},
44
};
55

66
/// `HasRestrictedGlobalProperty` implements the Opcode Operation for `Opcode::HasRestrictedGlobalProperty`
@@ -101,16 +101,13 @@ impl CreateGlobalFunctionBinding {
101101
let name = code_block.constant_string(name_index.into());
102102
let value = context.vm.get_register(src.into()).clone();
103103
let configurable = u32::from(configurable) != 0;
104-
104+
105105
// Convert JsValue to JsObject
106106
let function = value
107107
.as_object()
108-
.ok_or_else(|| {
109-
crate::JsNativeError::typ()
110-
.with_message("value is not an object")
111-
})?
108+
.ok_or_else(|| crate::JsNativeError::typ().with_message("value is not an object"))?
112109
.clone();
113-
110+
114111
context.create_global_function_binding(name, function, configurable)?;
115112
Ok(())
116113
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ generate_opcodes! {
22022202
///
22032203
/// - Registers:
22042204
/// - Input: value
2205-
AddDisposableResource { value: RegisterOperand },
2205+
AddDisposableResource { #[allow(dead_code)] value: RegisterOperand },
22062206

22072207
/// Dispose all resources in the current disposal stack.
22082208
///
@@ -2211,7 +2211,7 @@ generate_opcodes! {
22112211
///
22122212
/// - Stack: **=>**
22132213
DisposeResources,
2214-
2214+
22152215
/// Push a new disposal scope.
22162216
///
22172217
/// This marks the current disposal stack depth for a new scope.

0 commit comments

Comments
 (0)