標籤: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