V8引擎之从webcore到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

相关文章:

你感兴趣的文章:

标签云: