简体   繁体   English

拦截 javascript 中的所有 function 调用

[英]Intercept all function calls in javascript

What i will like to do is intercept all function calls in javascript, either if they are created by new Function , or function . What i will like to do is intercept all function calls in javascript, either if they are created by new Function , or function .

In other words to maybe do a Proxy for all functions that will be created.换句话说,可能为将要创建的所有功能做一个代理。 To execute some code before the function initial code.在 function 初始代码之前执行一些代码。

So my questions are:所以我的问题是:

  1. is there a way to do this?有没有办法做到这一点?

  2. is there a way to change Function.prototype?有没有办法改变 Function.prototype? It is build-in with configurable:false.它是内置的,可配置:false。 Can that be changed.那能不能改。

  3. I am trying to do this in electron, so i can change flags for V8, enable Experiments我正在尝试在 electron 中执行此操作,因此我可以更改 V8 的标志,启用实验

  4. Can this done with a native function enabled with --allow_natives_syntax flag?这可以通过启用--allow_natives_syntax标志的本机 function 来完成吗?

  5. Is there a way to change internal [[Call]]?有没有办法改变内部 [[Call]]?

I know about all the reasons why i should not do this.我知道为什么我不应该这样做的所有原因。 I am only interested in a way that can be done.我只对可以完成的方式感兴趣。

  1. Is there a way to do this?有没有办法做到这一点?

No.不。

  1. is there a way to change Function.prototype?有没有办法改变 Function.prototype? It is build-in with configurable:false.它是内置的,可配置:false。 Can that be changed?那可以改变吗?

No.不。

  1. Can this done with a native function enabled with --allow_natives_syntax flag?这可以通过启用 --allow_natives_syntax 标志的本机 function 来完成吗?

No.不。

  1. Is there a way to change internal [[Call]]?有没有办法改变内部 [[Call]]?

No.不。

If you're just interested in tracing function calls, you can use V8's existing --trace flag.如果您只是对跟踪 function 调用感兴趣,可以使用 V8 现有的--trace标志。 It's not possible to replicate that functionality in JavaScript (otherwise that flag wouldn't exist).无法在 JavaScript 中复制该功能(否则该标志将不存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM