void
JavaScriptFilterService::doIdle(void)
{
    ODL_OBJENTER(); //####
    if (isActive())
    {
        ODL_LOG("(isActive())"); //####
        if (_goAhead.check())
        {
            ODL_LOG("(_goAhead.check())"); //####
            if (_scriptThreadFunc.isNullOrUndefined())
            {
                ODL_LOG("(_scriptThreadFunc.isNullOrUndefined())"); //####
                // We have a request from an input handler.
                if (_inHandlers.size() > _mostRecentSlot)
                {
                    ODL_LOG("(getInletCount() > _mostRecentSlot)"); //####
                    JS::HandleValue                handlerFunc = _inletHandlers[_mostRecentSlot];
                    JavaScriptFilterInputHandler * aHandler = _inHandlers.at(_mostRecentSlot);

                    if (aHandler && (! handlerFunc.isNullOrUndefined()))
                    {
                        ODL_LOG("(aHandler && (! handlerFunc.isNullOrUndefined()))"); //####
                        JS::RootedValue     argValue(_context);
                        JS::Value           slotNumberValue;
                        JS::AutoValueVector funcArgs(_context);
                        JS::RootedValue     funcResult(_context);

                        slotNumberValue.setInt32(static_cast<int32_t>(_mostRecentSlot));
                        createValueFromBottle(_context, aHandler->getReceivedData(), &argValue);
                        funcArgs.append(slotNumberValue);
                        funcArgs.append(argValue);
                        JS_BeginRequest(_context);
                        if (JS_CallFunctionValue(_context, _global, handlerFunc, funcArgs,
                                                 &funcResult))
                        {
                            // We don't care about the function result, as it's supposed to just
                            // write to the outlet stream(s).
                        }
                        else
                        {
                            ODL_LOG("! (JS_CallFunctionValue(_context, _global, " //####
                                    "handlerFunc, funcArgs, &funcResult))"); //####
                            JS::RootedValue exc(_context);

                            if (JS_GetPendingException(_context, &exc))
                            {
                                JS_ClearPendingException(_context);
                                std::stringstream buff;
                                YarpString        message("Exception occurred while executing "
                                                          "handler function for inlet ");

                                buff << _mostRecentSlot;
                                message += buff.str();
                                message += ".";
                                MpM_FAIL_(message.c_str());
                            }
                        }
                        JS_EndRequest(_context);
                    }
                }
                _staller.post();
            }
            else
            {
                ODL_LOG("! (_scriptThreadFunc.isNullOrUndefined())"); //####
                try
                {
                    JS::AutoValueVector funcArgs(_context);
                    JS::RootedValue     funcResult(_context);

                    JS_BeginRequest(_context);
                    if (JS_CallFunctionValue(_context, _global, _scriptThreadFunc, funcArgs,
                                             &funcResult))
                    {
                        ODL_LOG("(JS_CallFunctionValue(_context, _global, " //####
                                "_scriptThreadFunc, funcArgs, &funcResult))"); //####
                        // We don't care about the function result, as it's supposed to just perform
                        // an iteration of the thread.
                    }
                    else
                    {
                        ODL_LOG("! (JS_CallFunctionValue(_context, _global, " //####
                                "_scriptThreadFunc, funcArgs, &funcResult))"); //####
                        JS::RootedValue exc(_context);

                        if (JS_GetPendingException(_context, &exc))
                        {
                            ODL_LOG("(JS_GetPendingException(_context, &exc))"); //####
                            JS_ClearPendingException(_context);
                            MpM_FAIL_("Exception occurred while executing the scriptThread "
                                      "function.");
                        }
                    }
                    JS_EndRequest(_context);
                }
                catch (...)
                {
                    ODL_LOG("Exception caught"); //####
                    throw;
                }
            }
        }
    }
    ODL_OBJEXIT(); //####
} // JavaScriptFilterService::doIdle