From 60afbb4bf5dd9c9b8a3f32e60f2be9bcbe2ff6f2 Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Sat, 27 Apr 2019 21:53:08 +0300 Subject: [PATCH] Don't pop exeption for context --- vm/src/frame.rs | 4 ++-- vm/src/vm.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 00d843d2a..69b1d510a 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -739,8 +739,8 @@ impl Frame { }; let context = match argc { 0 => vm.get_none(), // We have already got the exception, - _ => match vm.pop_exception() { - Some(exc) => exc, + _ => match vm.last_exception() { + Some(exc) => exc.clone(), None => vm.get_none(), }, }; diff --git a/vm/src/vm.rs b/vm/src/vm.rs index a677d7341..9308c0caa 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -931,6 +931,17 @@ impl VirtualMachine { pub fn pop_exception(&self) -> Option { self.exceptions.borrow_mut().pop() } + + pub fn last_exception(&self) -> Option> { + let exceptions = self.exceptions.borrow(); + if exceptions.is_empty() { + None + } else { + Some(Ref::map(self.exceptions.borrow(), |exceptions| { + exceptions.last().unwrap() + })) + } + } } impl Default for VirtualMachine {