Skip to content

Commit

Permalink
Add DeletePropertyByName vm opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Oct 9, 2021
1 parent a5b7873 commit 8bc8aa6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions boa/src/bytecompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ impl ByteCompiler {
UnaryOp::DecrementPost => todo!(),
UnaryOp::Delete => match unary.target() {
Node::GetConstField(ref get_const_field) => {
self.emit_push_literal(Literal::String(get_const_field.field().into()));
let index = self.get_or_insert_name(get_const_field.field());
self.compile_expr(get_const_field.obj(), true);
self.emit(Opcode::DeletePropertyByValue, &[]);
self.emit(Opcode::DeletePropertyByName, &[index]);
None
}
Node::GetField(ref get_field) => {
Expand Down
1 change: 1 addition & 0 deletions boa/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl CodeBlock {
| Opcode::Neg
| Opcode::GetPropertyByValue
| Opcode::SetPropertyByValue
| Opcode::DeletePropertyByName
| Opcode::DeletePropertyByValue
| Opcode::ToBoolean
| Opcode::Throw
Expand Down
9 changes: 9 additions & 0 deletions boa/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,15 @@ impl Context {
let key = key.to_property_key(self)?;
object.set(key, value, true, self)?;
}
Opcode::DeletePropertyByName => {
let index = self.vm.read::<u32>();
let key = self.vm.frame().code.variables[index as usize].clone();
let object = self.vm.pop();
let result = object
.to_object(self)?
.__delete__(&key.into(), self)?;
self.vm.push(result);
}
Opcode::DeletePropertyByValue => {
let object = self.vm.pop();
let key = self.vm.pop();
Expand Down
10 changes: 10 additions & 0 deletions boa/src/vm/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,15 @@ pub enum Opcode {
/// Stack: value, key, object **=>**
SetPropertyByValue,

/// Deletes a property by name of an object.
///
/// Like `delete object.key.`
///
/// Operands: name_index: `u32`
///
/// Stack: object **=>**
DeletePropertyByName,

/// Deletes a property by value of an object.
///
/// Like `delete object[key]`
Expand Down Expand Up @@ -614,6 +623,7 @@ impl Opcode {
Opcode::GetPropertyByValue => "GetPropertyByValue",
Opcode::SetPropertyByName => "SetPropertyByName",
Opcode::SetPropertyByValue => "SetPropertyByValue",
Opcode::DeletePropertyByName => "DeletePropertyByName",
Opcode::DeletePropertyByValue => "DeletePropertyByValue",
Opcode::Jump => "Jump",
Opcode::JumpIfFalse => "JumpIfFalse",
Expand Down

0 comments on commit 8bc8aa6

Please sign in to comment.