DOM and Script

本文深入探讨了浏览器中脚本的加载与执行过程,包括DOM对象与窗口对象的作用及关系,HTML文档解析器的工作原理,以及脚本从文档解析到JavaScript引擎执行的全过程。

script

1.DOM object in js
Windows object, the biggest object.
Screen,Navigaor,Location,History
2.document.frames[0]
document.frames[1]
return the frame of the Document.

(to be continued)


webkit

1.HTMLDocumentPareser's membership

OwnPtr<HTMLTokenizer> m_tokenizer;
OwnPtr<HTMLScriptRunner> m_scriptRunner;
OwnPtr<HTMLTreeBuilder> m_treeBuilder;
OwnPtr<HTMLPreloadScanner> m_preloadScanner;
OwnPtr<HTMLParserScheduler> m_parserScheduler;
2.Script Parese call stack
a.HTMLDocumentParser::runScriptsForPausedTreeBuilder
b.HTMLScriptRunner::execute
c.HTMLScriptRunner::runScript
d.ScriptElement::executeScript
e.ScriptController::executeScript
3.Frame has a ScriptController
Frame will pass itself to the ScriptController.

//current it will be js or V8.


2.construct a ScriptSourceCode
DocumentWriter::end()
DocumentWriter::endIfNotLoadingMainResource()
DocumentWriter::addData
DecodedDataDocumentParser::appendBytes
HTMLDocumentParser::append()
HTMLDocumentParser::pumpTokenizerIfPossible()
HTMLDocumentParser::pumpTokenizer
HTMLDocumentParser::runScriptsForPausedTreeBuilder()
HTMLScriptRunner::execute
HTMLScriptRunner::runScript
ScriptSourceCode::ScriptSourceCode

3.str in a ScriptSourceCode
ScriptSourceCode.(SourceCode m_code).(<SourceProvider> m_provider).(UString m_source).(<StringImpl> m_impl)
every sourcecode has a url

4. js's classes

MSVCBugWorkaround<--JSCell<--JSObject<--JSDOMWindowShell
JSObject<--JSVariableObject<--JSGlobalObject<--JSDOMGlobalObject<--JSDOMWindowBase<--JSDOMWindow






3.execute a script (honey js)

1)From DocumentParser to JS Engine
a.HTMLDocumentParser::runScriptsForPausedTreeBuilder
b.HTMLScriptRunner::execute
c.HTMLScriptRunner::runScript
d.ScriptElement::executeScript
e.ScriptController::executeScript(ScriptControllerBase.cpp)
f.ScriptController::evaluate
g.ScriptController::evaluateInWorld
in this
JSDOMWindowShell* shell = windowShell(world);
ExecState* exec = shell->window()->globalExec(); (ExecState was defined in CallFrame.h)
h.JSMainThreadExecState::evaluate
i.JSC::Completion evaluate (JSMainThreadExecState.h)
j.JSC::evaluate (Completion.cpp)
k.Interpreter::execute

.... to js engine

2)js engine return to DOM

take "document.write("abc")" for example

a. ....js engine ...

b.jsHTMLDocumentPrototypeFunctionWrite (JSHTMLDocument.cpp)

c.JSHTMLDocument::write(JSHTMLDocumentCustom.cpp)

d.documentWrite.write(JSHTMLDocumentCustom.cpp)

e.Document::write

3)external script's request process

jsNodePrototypeFunctionAppendChild(JSC::ExecState * exec=0x065400e8)
JSNode::appendChild(JSC::ExecState * exec=0x065400e8)  
Node::appendChild(WTF::PassRefPtr<WebCore::Node> newChild={...}, int & ec=0, bool shouldLazyAttach=true)
ContainerNode::appendChild(WTF::PassRefPtr<WebCore::Node> newChild={...}, int & ec=0, bool shouldLazyAttach=true)
notifyChildInserted(WebCore::Node * child=0x08b91cd8) 
HTMLScriptElement::insertedIntoDocument()
ScriptElement::insertedIntoDocument()
ScriptElement::prepareScript(const WTF::TextPosition<WTF::OneBasedNumber> & scriptStartPosition={...}, ScriptElement::LegacyTypeSupport supportLegacyTypes=DisallowLegacyTypeInTypeAttribute) 
ScriptElement::requestScript(const WTF::String & sourceUrl={...})

4) external script's notify process

jsNodePrototypeFunctionAppendChild(JSC::ExecState * exec=0x065400e8)
JSNode::appendChild(JSC::ExecState * exec=0x065400e8) 
Node::appendChild(WTF::PassRefPtr<WebCore::Node> newChild={...}, int & ec=0, bool shouldLazyAttach=true) 
ContainerNode::appendChild(WTF::PassRefPtr<WebCore::Node> newChild={...}, int & ec=0, bool shouldLazyAttach=true)
notifyChildInserted(WebCore::Node * child=0x08b91cd8)
HTMLScriptElement::insertedIntoDocument()
ScriptElement::insertedIntoDocument()
ScriptElement::prepareScript(const WTF::TextPosition<WTF::OneBasedNumber> & scriptStartPosition={...}, 
LegacyTypeSupport supportLegacyTypes=DisallowLegacyTypeInTypeAttribute)
CachedResource::addClient(WebCore::CachedResourceClient * client=0x08b91d1c)
CachedScript::didAddClient(WebCore::CachedResourceClient * c=0x08b91d1c)
CachedResource::didAddClient(WebCore::CachedResourceClient * c=0x08b91d1c)
ScriptElement::notifyFinished(WebCore::CachedResource * o=0x069f8ac0)











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值