As the size of my blog Chrome Development Tool tips used in my daily work turns to be larger I create a separate post to record down this small tip.
Are you curious about the “native code” here? At least I am

Today I find that the Profiles tab in Chrome development tool can help us to unveil the mysteries to some degree.
In Chrome development, just select this checkbox:

And then execute the simple JavaScript code below:

var arr = [];
for (var i=0; i<1000; i++){arr.push(i)
}
console.profile("Array toString");for( var i = 0; i < 1000; i++){var a = arr.toString();
}
console.profileEnd("Array toString");

Once done, you can see a profile record with the name specified in JavaScript code above, “Array toString”. Hover the mouse to the first row, “anonymous function”, we find the hint “array.js”.

Switch display style from Chart to Tree:

From here the callstack of native implementation of toString is displayed:

The next step is to look into in array.js.
Launch url: https://cs.chromium.org/
Click this hyperlink:

now you can find the array.js file via path: src/v8/src/js/array.js

The callstack analyzed through the source code exactly matches the one we get in Chrome development tool Profile tab:
ArrayToString will delegate to Join if current caller is an Array:

Join will call DoJoin:

DoJoin will first call UseSparseVariant to evaluate the possibility to perform Join via SparseVariant. If not possible, call ConvertToString as fall back. ( The line number of source code may vary with the one you see in Chrome Development Tool profile tab due to the different version of Chrome being used. )

If you could not tolerate the poor performance of this online source code repository, you could download the whole source code of V8 to your local laptop by cloning this github repository:

https://chromium.googlesource.com/v8/v8.git/

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

使用Chrome开发者工具研究JavaScript函数的原生实现原理相关推荐

  1. 使用Chrome开发者工具研究JavaScript里函数的原生实现

    As the size of my blog Chrome Development Tool tips used in my daily work turns to be larger I creat ...

  2. 使用 Chrome 开发者工具进行 JavaScript 问题定位与调试

    引言 Google Chrome 是由 Goole 公司开发的一款网页浏览器,自 2008 年 9 月第一个测试版本发布以来,其市场占有率逐步上升,至 2014 年 5 月,Chrome 已超越 Fi ...

  3. 使用 Chrome 开发者工具研究一个基于 Angular 开发的网站源代码

    Chrome 开发者工具是前端开发工程师工具箱里使用频率最高的工具之一. 本文通过一个具体的例子,给大家分享笔者工作中,是如何通过 Chrome 开发者工具,分析一个网站的实现明细. 下图是 SAP ...

  4. 使用chrome开发者工具调试JavaScript代码的三种常用方法

    对 JS 程序的调试,除了在 JS 程序中使用 alert().console.log() 方法跟踪和调试代码外,开发人员也会经常使用一些调试工具.最常用的 JS 调试工具就是一些主流的浏览器的调试工 ...

  5. Chrome开发者工具之JavaScript内存分析

    为什么80%的码农都做不了架构师?>>>    内存泄漏是指计算机可用内存的逐渐减少.当程序持续无法释放其使用的临时内存时就会发生.JavaScript的web应用也会经常遇到在原生 ...

  6. 在 Chrome 开发者工具中调试 node.js

    命令行工具 devtool ,它可以在 Chrome 的开发者工具中运行 Node.js 程序. 下面的记录显示了在一个 HTTP 服务器中设置断点的情况. 该工具基于 Electron 将 Node ...

  7. 如何使用 Chrome 开发者工具 Performance tab 分析 JavaScript 的执行瓶颈

    将下面这段代码插入 SAP Spartacus payment types Component 的 next 方法: console.time('Jerry');const N = 100000;le ...

  8. Jerry和您聊聊Chrome开发者工具

    Chrome开发者工具是Jerry日常工作使用的三大调试器之一.虽然工具名称前面带了个"开发者", 但是它对非开发人员仍然有用.不信? 用Chrome打开我们常用的网站,按F12, ...

  9. Chrome 开发者工具的Timeline和Profiles提高Web应用程序的性能[转]

    我们都希望创建高性能的Web应用程序.由于我们的应用程序变得越来越复杂,我们可能想要支持丰富的画面以及理想的60帧/秒,这能保证我们的应用程序响应灵敏且生动流畅. 知道如何衡量和提高性能,是一个有用的 ...

最新文章

  1. AttributeError: module ‘sys‘ has no attribute ‘maxint‘
  2. androidx和android的区别,【译】使用AndroidX代替Android支持库
  3. 【Tree】迷宫生成算法
  4. 学习笔记之Iframe
  5. python dict 属性_python的dir()和__dict__属性的区别
  6. BZOJ 1257: [CQOI2007]余数之和sum【神奇的做法,思维题】
  7. 一步步在Docker里运行Web应用
  8. python docx包_[Python02] Python-docx包的使用,快速处理 Word 文件!
  9. 十八、AR数据库的关联查询relations之单条数据查询
  10. 关于四川2019ACM省赛热身赛B题的一个证明
  11. RS232 9针串口定义
  12. tim指定保存云服务器_腾讯 TIM 迎来重大版本更新 新增独立的云文件功能
  13. 计算机408考试题库百度云,2017年计算机408考研真题.pdf
  14. Merged region A1 must contain 2 or more cells
  15. [附源码]Python计算机毕业设计电脑配件仓储后台管理系统
  16. JavaScript写一个虚拟软键盘,可拼音输入
  17. 网易云评论 爬虫 java_网易云音乐资源爬取(登录+评论)
  18. linux编辑pdf文件内容,PDF修改文字的步骤
  19. 强关联中Tight-Binding哈密顿量的生成
  20. 新书出版发布会发言稿_我从发布会议发言人调查中学到的东西

热门文章

  1. 插件~NuGet与packages管理项目的包包
  2. [LeetCode]93.Restore IP Addresses
  3. ibernate ID生成策略 小知识
  4. 第2本书:CCIE Practical Studies, Volume II-第5天
  5. 微信小程序项目实战知识点总结(swiper组件自适应高度,自定义弹出层,悬浮按钮,虚拟键盘)...
  6. linux安装php7.2.7
  7. x86 linux 裁剪过程中能正常跑起来的必要配置项
  8. CentOS 7破解root密码
  9. bootstrap panel 和table的使用
  10. VS中修改站点运行方式(集成 Or 经典)