boa: Calling a function that mutates itself causes borrow panic
This is caused when we call a function we borrow the function object and we do not release the hold until function ends. see GcObject::call / GcObject::construct
To Reproduce Steps to reproduce the issue, or JavaScript code that causes this failure.
function x() {
x.y = 3;
}
x();
Expected behavior
Not panic and x to have a property y with value 3
Actual behavior Panics:
thread 'main' panicked at 'Object already borrowed: BorrowMutError', boa/src/builtins/object/gcobject.rs:41:9
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 18 (8 by maintainers)
Ok now it works 🥳. I thought with NLL it would get dropped before the function returns
That is only one half of the problem the next is to release the borrow a nicer way of doing this is to create a enum
and return it in the if expression https://github.com/dvtkrlbs/boa/blob/0fc8052f4ee8bc79ee3df265b855f66b421f641e/boa/src/builtins/object/gcobject.rs#L68 then
matchon it outside of the borrow.Got it thank you for the help. I probably should look at it tomorrow.
we need to implement
Dereftrait on theRcStatementlist:The
std::rc::RcimplementsDeref, but our wrapper type (RcStatementlist) does not. CheckRcString/RcSymbol/RcBigIntfor more information/examples since its very similar.i can try to fix this issue