gpt4 book ai didi

javascript - 拦截javascript中的所有函数调用

转载 作者:行者123 更新时间:2023-12-03 12:21:49 28 4
gpt4 key购买 nike

我想做的是拦截 javascript 中的所有函数调用,无论它们是由 new Function 还是 function 创建的。

换句话说,可能为将要创建的所有函数做一个代理。在函数初始代码之前执行一些代码。

所以我的问题是:

  1. 有办法做到这一点吗?

  2. 有没有办法改变 Function.prototype ?它是内置的可配置:false。可以改吗。

  3. 我正在尝试在 electron 中执行此操作,因此我可以更改 V8 的标志,启用实验

  4. 这可以通过启用 --allow_natives_syntax 标志的 native 函数来完成吗?

  5. 有没有办法改变内部 [[Call]] ?

我知道我不应该这样做的所有原因。我只对可以完成的方式感兴趣。

最佳答案

  1. Is there a way to do this?

没有。

  1. is there a way to change Function.prototype ? It is build-in with configurable:false. Can that be changed?

没有。

  1. Can this done with a native function enabled with --allow_natives_syntax flag ?

没有。

  1. Is there a way to change internal [[Call]] ?

没有。

如果您只对跟踪函数调用感兴趣,可以使用 V8 现有的 --trace 标志。无法在 JavaScript 中复制该功能(否则该标志将不存在)。

关于javascript - 拦截javascript中的所有函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61406070/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com