double HighResolutionClock::GetRelativeSeconds()
{
    std::call_once(s_InitializationFlag, []
    {
        ASSERT_EVAL(::QueryPerformanceFrequency(&s_TicksPerSecond));
    });

    LARGE_INTEGER tickCount;
    ASSERT_EVAL(::QueryPerformanceCounter(&tickCount));

    auto wholeSeconds = tickCount.QuadPart / s_TicksPerSecond.QuadPart;
    auto remainingTicks = tickCount.QuadPart % s_TicksPerSecond.QuadPart;

    return wholeSeconds + (static_cast<double>(remainingTicks) / s_TicksPerSecond.QuadPart);
}
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;
    }
}
Esempio n. 3
0
void V8Platform::EnsureInstalled()
{
    std::call_once(ms_InstallationFlag, []
    {
        v8::V8::InitializePlatform(&ms_Instance);
        ASSERT_EVAL(v8::V8::Initialize());
    });
}
void V8IsolateImpl::DisableDebugging()
{
    _ASSERTE(m_pIsolate == Isolate::GetCurrent());
    _ASSERTE(Locker::IsLocked(m_pIsolate));

    if (m_DebuggingEnabled)
    {
        Debug::DisableAgent();
        Debug::SetDebugMessageDispatchHandler(nullptr);

        if (m_pDebugMessageDispatcher != nullptr)
        {
            ASSERT_EVAL(CALLBACK_MANAGER(DebugMessageDispatcher)::Free(m_pDebugMessageDispatcher));
        }

        m_DebuggingEnabled = false;
        m_DebugMessageDispatchCount = 0;
    }
}
V8IsolateImpl::V8IsolateImpl(const wchar_t* pName, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort) :
    m_pIsolate(Isolate::New()),
    m_DebuggingEnabled(false),
    m_DebugMessageDispatchCount(0),
    m_MaxStackUsage(0),
    m_ExecutionLevel(0),
    m_pStackLimit(nullptr),
    m_IsOutOfMemory(false)
{
    BEGIN_ADDREF_SCOPE

        if (pName != nullptr)
        {
            m_Name = pName;
        }

        BEGIN_ISOLATE_ENTRY_SCOPE

            V8::SetCaptureStackTraceForUncaughtExceptions(true, 64, StackTrace::kDetailed);
            V8::IgnoreOutOfMemoryException();
            if (pConstraints != nullptr)
            {
                ResourceConstraints constraints;
                constraints.set_max_young_space_size(pConstraints->GetMaxYoungSpaceSize());
                constraints.set_max_old_space_size(pConstraints->GetMaxOldSpaceSize());
                constraints.set_max_executable_size(pConstraints->GetMaxExecutableSize());
                ASSERT_EVAL(SetResourceConstraints(m_pIsolate, &constraints));
            }

        END_ISOLATE_ENTRY_SCOPE

        if (enableDebugging)
        {
            BEGIN_ISOLATE_SCOPE

                EnableDebugging(debugPort);

            END_ISOLATE_SCOPE
        }

    END_ADDREF_SCOPE
}