Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/engine/src/bytecompiler/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ impl ByteCompiler<'_> {
}
}
Statement::With(with) => self.compile_with(with, use_expr),
Statement::Empty | Statement::Debugger => {}
Statement::Empty => {}
Statement::Debugger => {
self.bytecode.emit_debugger();
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,8 @@ impl CodeBlock {
| Instruction::SuperCallSpread
| Instruction::PopPrivateEnvironment
| Instruction::Generator
| Instruction::AsyncGenerator => String::new(),
| Instruction::AsyncGenerator
| Instruction::Debugger => String::new(),
Instruction::Reserved1
| Instruction::Reserved2
| Instruction::Reserved3
Expand Down Expand Up @@ -917,8 +918,7 @@ impl CodeBlock {
| Instruction::Reserved56
| Instruction::Reserved57
| Instruction::Reserved58
| Instruction::Reserved59
| Instruction::Reserved60 => unreachable!("Reserved opcodes are unreachable"),
| Instruction::Reserved59 => unreachable!("Reserved opcodes are unreachable"),
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions core/engine/src/vm/flowgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,11 @@ impl CodeBlock {
| Instruction::Reserved56
| Instruction::Reserved57
| Instruction::Reserved58
| Instruction::Reserved59
| Instruction::Reserved60 => unreachable!("Reserved opcodes are unreachable"),
| Instruction::Reserved59 => unreachable!("Reserved opcodes are unreachable"),
Instruction::Debugger => {
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::None);
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions core/engine/src/vm/opcode/debugger/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::{Context, vm::opcode::Operation};

/// `Debugger` implements the Opcode Operation for `Opcode::Debugger`
///
/// Operation:
/// - No-op for now. Emitted for `debugger;` statements so they are
/// represented in bytecode and visible during tracing.
#[derive(Debug, Clone, Copy)]
pub(crate) struct Debugger;

impl Debugger {
#[inline(always)]
pub(super) fn operation((): (), _: &mut Context) {}
}

impl Operation for Debugger {
const NAME: &'static str = "Debugger";
const INSTRUCTION: &'static str = "INST - Debugger";
const COST: u8 = 1;
}
17 changes: 15 additions & 2 deletions core/engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod call;
mod concat;
mod control_flow;
mod copy;
mod debugger;
mod define;
mod delete;
mod environment;
Expand Down Expand Up @@ -55,6 +56,8 @@ pub(crate) use control_flow::*;
#[doc(inline)]
pub(crate) use copy::*;
#[doc(inline)]
pub(crate) use debugger::*;
#[doc(inline)]
pub(crate) use define::*;
#[doc(inline)]
pub(crate) use delete::*;
Expand Down Expand Up @@ -2141,6 +2144,18 @@ generate_opcodes! {
/// - Output: dst
CreateUnmappedArgumentsObject { dst: RegisterOperand },

/// The `debugger` statement.
///
/// Currently a no-op. This opcode is emitted for `debugger;` statements
/// so they are represented in the bytecode, enabling future debugger
/// integration to intercept them.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-debugger-statement
Debugger,

/// Reserved [`Opcode`].
Reserved1 => Reserved,
/// Reserved [`Opcode`].
Expand Down Expand Up @@ -2259,6 +2274,4 @@ generate_opcodes! {
Reserved58 => Reserved,
/// Reserved [`Opcode`].
Reserved59 => Reserved,
/// Reserved [`Opcode`].
Reserved60 => Reserved,
}
Loading