void V8IsolateImpl::EnableDebugging(int debugPort)
{
    _ASSERTE(m_pIsolate == Isolate::GetCurrent());
    _ASSERTE(Locker::IsLocked(m_pIsolate));

    if (!m_DebuggingEnabled)
    {
        if (debugPort < 1)
        {
            debugPort = 9222;
        }

        auto wrThis = CreateWeakRef();
        m_pDebugMessageDispatcher = CALLBACK_MANAGER(DebugMessageDispatcher)::Alloc([wrThis]
        {
            Concurrency::create_task([wrThis]
            {
                auto spIsolate = wrThis.GetTarget();
                if (!spIsolate.IsEmpty())
                {
                    auto pIsolateImpl = static_cast<V8IsolateImpl*>(spIsolate.GetRawPtr());
                    pIsolateImpl->DispatchDebugMessages();
                }
            });
        });

        _ASSERTE(m_pDebugMessageDispatcher);
        Debug::SetDebugMessageDispatchHandler(m_pDebugMessageDispatcher);
        ASSERT_EVAL(Debug::EnableAgent(*String::Utf8Value(CreateString(m_Name.c_str())), debugPort));

        m_DebuggingEnabled = true;
        m_DebugPort = debugPort;
    }
}
Exemplo n.º 2
0
void V8IsolateImpl::EnableDebugging(int debugPort)
{
    _ASSERTE(IsCurrent() && IsLocked());
    if (!m_DebuggingEnabled)
    {
        StdString version(v8::String::NewFromUtf8(m_pIsolate, v8::V8::GetVersion()));
        if (debugPort < 1)
        {
            debugPort = 9222;
        }

        auto wrIsolate = CreateWeakRef();
        m_pvDebugAgent = HostObjectHelpers::CreateDebugAgent(m_Name, version, debugPort, [wrIsolate] (HostObjectHelpers::DebugDirective directive, const StdString* pCommand)
        {
            auto spIsolate = wrIsolate.GetTarget();
            if (!spIsolate.IsEmpty())
            {
                auto pIsolateImpl = static_cast<V8IsolateImpl*>(spIsolate.GetRawPtr());
                if ((directive == HostObjectHelpers::DebugDirective::SendDebugCommand) && pCommand)
                {
                    pIsolateImpl->SendDebugCommand(*pCommand);
                }
                else if (directive == HostObjectHelpers::DebugDirective::DispatchDebugMessages)
                {
                    pIsolateImpl->DispatchDebugMessages();
                }
            }
        });

        v8::Debug::SetMessageHandler(OnDebugMessageShared);

        m_DebuggingEnabled = true;
        m_DebugPort = debugPort;
    }
}