V8/Ignition:仅打印 JavaScript 文件的顶级代码的字节码

V8/Ignition: Print bytecode of just the top-level code of a JavaScript file

我知道 D8 和 Node.js 都有选项 --print-bytecode 可以在执行期间打印字节码,还有 --print-bytecode-filter 可以限制我要打印的函数。但是有什么办法可以限制只打印脚本的顶层代码而不是脚本中的特定函数吗?

让我帮你自助:

(1) 使用source.chromium.org搜索FLAG_print_bytecode_filter.

(2) 查看处理标志的代码,特别是这个片段:

  if (shared->is_toplevel()) {
    base::Vector<const char> filter =
        base::CStrVector(FLAG_print_bytecode_filter);
    return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*');
  }

(3) 这就是你的答案:--print-bytecode-filter="" 将字节码打印限制在顶层代码。