Skip to content

Commit

Permalink
Get property while writing inline cache
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Apr 9, 2023
1 parent 4ebb6a2 commit 4abf50f
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions boa_engine/src/vm/opcode/get/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,25 @@ impl Operation for GetPropertyByName {

// Check if it can be cached.
let shape = object_borrowed.properties().shape.clone();
drop(object_borrowed);
let slot = if let Some(mut slot) = shape.lookup(&key) {
let (slot, mut result) = if let Some(mut slot) = shape.lookup(&key) {
slot.attributes |= SlotAttributes::DIRECT;
slot
} else if let Some(mut slot) = shape
.prototype()
.and_then(|prototype| prototype.borrow().properties().shape.lookup(&key))
{
let result = object_borrowed.properties().storage[slot.index as usize].clone();

(slot, result)
} else if let Some(prototype) = shape.prototype() {
let prototype_borrowed = prototype.borrow();
let Some(mut slot) = prototype_borrowed.properties().shape.lookup(&key) else {
drop(object_borrowed);
drop(prototype_borrowed);
let result = object.__get__(&key, value, context)?;
context.vm.push(result);
return Ok(CompletionType::Normal);
};
let result = prototype_borrowed.properties().storage[slot.index as usize].clone();
slot.attributes.set(SlotAttributes::DIRECT, false);
slot
(slot, result)
} else {
drop(object_borrowed);
let result = object.__get__(&key, value, context)?;
context.vm.push(result);
return Ok(CompletionType::Normal);
Expand All @@ -93,7 +101,11 @@ impl Operation for GetPropertyByName {

*ic.shape.borrow_mut() = Some(shape);

let result = object.__get__(&key, value, context)?;
drop(object_borrowed);
if slot.attributes.has_get() {
result = result.call(&value, &[], context)?;
}

context.vm.push(result);
Ok(CompletionType::Normal)
}
Expand Down

0 comments on commit 4abf50f

Please sign in to comment.