如何通过d8深入分析对象

323 字
2 分钟
如何通过d8深入分析对象

为了更深入理解JavaScript中的对象,需要安装d8(V8调试工具)

mac安装指导 windows安装指导

创建文件test.js

obj = { "second":2, 2: "b", 1: "a", "first": 1 };
%DebugPrint(obj);

执行命令 d8 --allow-natives-syntax test.js

d8命令参数解释

—allow-natives-syntax 的含义是允许调用V8内部调试方法。通过%DebugPrint() 这种方式我们可以看到相对于控制台memory内存快照中更深度的信息。

DebugPrint:
0x3c9d0010b481: [JS_OBJECT_TYPE]
- map: 0x3c9d0025a4dd <Map[20](HOLEY_ELEMENTS)> [FastProperties] `隐藏类`
- prototype: 0x3c9d00244a09 <Object map = 0x3c9d002440c5>
- elements: 0x3c9d0010b4b1 <FixedArray[20]> [HOLEY_ELEMENTS]
- properties: 0x3c9d000022a9 <FixedArray[0]>
- All own properties (excluding elements): { `命名属性`
0x3c9d00007591: [String] in ReadOnlySpace: #second: 2 (const data field 0), location: in-object
0x3c9d00005755: [String] in ReadOnlySpace: #first: 1 (const data field 1), location: in-object
}
- elements: 0x3c9d0010b4b1 <FixedArray[20]> { `可索引属性`
0: 0x3c9d000022fd <the_hole>
1: 0x3c9d00004a4d <String[1]: #a>
2: 0x3c9d00004a5d <String[1]: #b>
3-19: 0x3c9d000022fd <the_hole>
}
0x3c9d0025a4dd: [Map] in OldSpace `垃圾回收相关-老生代`
- type: JS_OBJECT_TYPE
- instance size: 20
- inobject properties: 2 `对象内属性数量`
- elements kind: HOLEY_ELEMENTS
- enum length: invalid
- back pointer: 0x3c9d0025a495 <Map[20](HOLEY_ELEMENTS)> `transition tree上指针`
- instance descriptors (own) #2: 0x3c9d0010b509 <DescriptorArray[2]> `描述符数组`
- prototype: 0x3c9d00244a09 <Object map = 0x3c9d002440c5> `原型`
- constructor: 0x3c9d002445cd <JSFunction Object (sfi = 0x3c9d00217d3d)> `构造者`
- dependent code: 0x3c9d000022b9 <Other `heap` object (WEAK_ARRAY_LIST_TYPE)> `存放位置`

可以看到通过d8我们可以看到隐藏类、命名属性、可索引属性、垃圾回收相关内容。

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

如何通过d8深入分析对象
https://an2333.com/posts/frontend/browser/v8/如何通过d8深入分析对象/
作者
Annan
发布于
2025-05-25
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
Annan
写点前端,聊点 AI。
公告
博客已迁移到 Astro + Firefly,旧文章正在陆续搬家中。
分类
标签
站点统计
文章
50
分类
7
标签
28
总字数
84,160
运行时长
0 天
最后活动
0 天前
站点信息
构建平台
GitHub Actions
博客版本
Firefly v6.16.8
文章许可
CC BY-NC-SA 4.0

当前页面没有目录

文章目录

当前页面没有目录