2013-10-24 22 views
0

我正在學習v8源代碼。 我花了3個星期,但我無法找到8v如何調用DOM的功能。v8如何調用DOM的函數?

Example for, 
<script> 
    document.writeln("Hello V8"); 
</script> 

我想知道調用序列的過程,writeln()函數的DOM。 你能解釋一下嗎?或者給我一些提示。

回答

0

你可以檢查V8HTMLDocumentCustom.cpp文件,其中.writeln功能發現:

void V8HTMLDocument::writelnMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args){ 
     HTMLDocument* htmlDocument = V8HTMLDocument::toNative(args.Holder()); 
     htmlDocument->writeln(writeHelperGetString(args), activeDOMWindow()->document()); 
} 

正如你可以看到有幾個頭在內,其中一些包括帶你到其他的頭,你找到的文件像V8DOMConfiguration.h

V8DOMConfiguration.h有一些意見:

class V8DOMConfiguration { 
    public: 
    // The following Batch structs and methods are used for setting multiple 
    // properties on an ObjectTemplate, used from the generated bindings 
    // initialization (ConfigureXXXTemplate). This greatly reduces the binary 
    // size by moving from code driven setup to data table driven setup. 

我從中得到的結果是,Chrome V8爲對象創建了「包裝世界」,爲它們中的每一個重新創建了DOM,然而它只是將數據傳遞到創建的活動窗口。

我不太熟悉V8,但這是一個起點。也許有更深層次的知識的人可以更好地解釋它。

更新

由於運行時沒有瀏覽器有沒有可用的DOM @Esailija指出V8發動機。由於DOM是Webkit/Blink的一部分,鏈接引用指向它們。一旦瀏覽器呈現DOM,V8對象就會與DOM樹元素匹配。這裏有一個相關的問題:V8 Access to DOM

+0

爲了避免混淆:您引用了Webkit/Blink源代碼,而不是V8。 OP正在閱讀V8源代碼,它根本沒有任何DOM東西。 – Esailija