@@ -692,12 +692,14 @@ class JavascriptEngine::Impl
692692 {
693693 shouldStop = false ;
694694
695- engine.setInterruptHandler ([this , maxExecTime, started = Time::getMillisecondCounterHiRes ()]()
695+ timeAtLastStart = Time::getMillisecondCounterHiRes ();
696+
697+ engine.setInterruptHandler ([this , maxExecTime]()
696698 {
697699 if (shouldStop)
698700 return 1 ;
699701
700- const auto elapsed = RelativeTime::milliseconds ((int64) (Time::getMillisecondCounterHiRes () - started ));
702+ const auto elapsed = RelativeTime::milliseconds ((int64) (Time::getMillisecondCounterHiRes () - timeAtLastStart ));
701703 return elapsed > maxExecTime ? 1 : 0 ;
702704 });
703705
@@ -723,8 +725,10 @@ class JavascriptEngine::Impl
723725 return result;
724726 }
725727
726- var callFunction (const Identifier& function, const var::NativeFunctionArgs& args, Result* errorMessage)
728+ var callFunction (const Identifier& function, const var::NativeFunctionArgs& args, Result* errorMessage, RelativeTime maxExecTime )
727729 {
730+ timeAtLastStart = Time::getMillisecondCounterHiRes ();
731+
728732 auto * ctx = engine.getQuickJSContext ();
729733 const auto functionStr = function.toString ();
730734
@@ -771,6 +775,11 @@ class JavascriptEngine::Impl
771775 // ==============================================================================
772776 detail::QuickJSWrapper engine;
773777 std::atomic<bool > shouldStop = false ;
778+
779+ /* * This value stores the last time a execute, eval or callFunction has been started.
780+ This allows to update the interrupt check when using callFunction() after execute() without having to always override the interrupt handler
781+ */
782+ double timeAtLastStart = 0 ;
774783};
775784
776785// ==============================================================================
@@ -801,7 +810,7 @@ var JavascriptEngine::callFunction (const Identifier& function,
801810 const var::NativeFunctionArgs& args,
802811 Result* errorMessage)
803812{
804- return impl->callFunction (function, args, errorMessage);
813+ return impl->callFunction (function, args, errorMessage, maximumExecutionTime );
805814}
806815
807816void JavascriptEngine::stop () noexcept
0 commit comments