V8引擎之從webcore到V8

來源:互聯網
上載者:User

標籤:v8

這裡不想講什麼是V8,請自行百度。自己搞webkit,故以後的V8學習研究都是基於webkit與V8的結合(目前沒有研究blink,僅僅是把webkit官方的JavaScriptCore引擎換作了V8),不是純粹的V8。

這裡僅介紹從webcore的入口處


先從webcore的js入口說起,在html詞法解析的時候,有一個這個函數:

bool HTMLDocumentParser::canTakeNextToken(SynchronousMode mode, PumpSession& session)

這個會判斷當前是否繼續解析,而其中:

   // If we‘re paused waiting for a script, we try to execute scripts before continuing.
        bool shouldContinueParsing = runScriptsForPausedTreeBuilder();

這裡正是解析的入口,繼續下去直到dom模組的一個void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)這個函數

void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
{
    ASSERT(m_alreadyStarted);


    if (sourceCode.isEmpty())
        return;


    if (!m_isExternalScript && !m_element->document()->contentSecurityPolicy()->allowInlineScript())
        return;


    RefPtr<Document> document = m_element->document();
    ASSERT(document);
    if (Frame* frame = document->frame()) {
        {
            IgnoreDestructiveWriteCountIncrementer ignoreDesctructiveWriteCountIncrementer(m_isExternalScript ? document.get() : 0);
            // Create a script from the script element node, using the script
            // block‘s source and the script block‘s type.
            // Note: This is where the script is compiled and actually executed.
            frame->script()->evaluate(sourceCode);
        }


        Document::updateStyleForAllDocuments();
    }
}

看見了吧,注釋已經寫的很清楚,從這裡開始離開webcore準備進入js引擎了

  frame->script()->evaluate(sourceCode);這裡調用binding模組的指令碼控制器scriptcontroler,開始進入binding模組,這binding模組JSC和V8其實有很大的相似之處。下篇再專門分析下v8的binding模組

V8引擎之從webcore到V8

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.