簡體   English   中英

v8如何調用DOM的函數?

[英]How does v8 call DOM's function?

我正在研究 v8 源代碼。 我已經花了 3 周,但我找不到 8v 是如何調用 DOM 的函數的。

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

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

您可以檢查找到.writeln函數的V8HTMLDocumentCustom.cpp文件:

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 使用對象創建“Wrapper Worlds”,為每個對象重新創建 DOM,然后它只是將數據傳遞給創建的活動窗口。

我不太精通 V8,但這是一個起點。 也許對它有更深入了解的人可以更好地解釋它。

更新

正如@Esailija 指出的,V8 引擎在沒有瀏覽器的情況下運行時沒有可用的 DOM。 由於 DOM 是 Webkit/Blink 的一部分,鏈接引用指向它們。 一旦瀏覽器渲染了 DOM,V8 對象就會與 DOM 樹元素匹配。 這里有一個相關的問題: V8 Access to DOM

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM