v8访问DOM [英] v8 access to DOM

查看:281
本文介绍了v8访问DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改v8引擎,以便能够拦截对DOM元素的每次访问。
如您所知,v8不会创建DOM树。浏览器创建DOM树。




  • 我的问题1:在v8源代码中,如何/何地将DOM内存结构传递到v8 。

  • 如何以最小的努力进行拦截?


解决方案

使用V8注册DOM元素的代码不在V8源代码中,而是在Chromium源代码的另一部分中:third_party / WebKit / Source /



其中可能有一些有趣的内容:




  • core / dom:此目录包含基本DOM类,再加上用于生成V8接口的IDL定义

  • core / html:相同,但对于HTML特定类

  • bindings / scripts:我相信这是将IDL转换为与V8接口的C源代码的脚本所在的地方(我没有对此部分进行详细研究)

  • bindings / core / v8:这是代码实际上是调用V8执行脚本等的内容。



编辑(2020-05-27): Chromium的最新版本。从铬83开始(我认为至少可以回到75左右),


  • third_party / blink / renderer / core / dom /

  • third_party / blink / renderer / core / html /

  • third_party / blink / renderer / bindings / scripts /

  • third_party / blink / renderer / bindings / core / v8 /


I want to change the v8 engine in order to be able to intercept every access to DOM elements. As you know, v8 does not create the DOM tree. The browser creates the DOM tree.

  • My question 1: how/where in the v8 source code, the DOM memory structure is delivered to v8.
  • How can I do my interception with minimum effort?

解决方案

The code that registers the DOM elements with V8 is not within the V8 source code, it's in another part of the Chromium source: third_party/WebKit/Source/

There are a few pieces in there which are probably of interest to you:

  • core/dom: This directory contains the implementations of the base DOM classes, plus IDL definitions of them which are used to generate the interfaces to V8
  • core/html: Same, but for HTML-specific classes
  • bindings/scripts: I believe this is where the scripts live which convert the IDL into C source which interfaces with V8 (I haven't looked into this part in much detail)
  • bindings/core/v8: This is where the code is which actually calls into V8 to execute scripts, etc

Edit (2020-05-27): This stuff has moved around in recent versions of Chromium. As of chromium 83 (and I think at least back to around chromium 75), it's now under:

  • third_party/blink/renderer/core/dom/
  • third_party/blink/renderer/core/html/
  • third_party/blink/renderer/bindings/scripts/
  • third_party/blink/renderer/bindings/core/v8/

这篇关于v8访问DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆