为什么 v8 源代码的 JS 文件中的某些函数调用前面带有 %? [英] Why are some of the function invocations preceded by a % in JS files for v8 source?

查看:28
本文介绍了为什么 v8 源代码的 JS 文件中的某些函数调用前面带有 %?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多代码中看到了 %.您能向我解释一下它的用途或作用吗?

I saw % in many codes. Can you explain to me its purpose or what it does?

我知道数学中的操作数 13 % 10 = 3 但我看到的是 return %foo.

I know the operand in math 13 % 10 = 3 but what I saw is like return %foo.

在查看 v8 源文件时遇到这个问题

为什么有些函数调用前面有一个 % 符号?

Why are some of the function invocations preceded by a % sign?

%CheckIsBootstrapping();
//---
// Only used by async-await.js
function RejectPromise(promise, reason, debugEvent) {
  %PromiseReject(promise, reason, debugEvent);
}
//---
var callbacks = %create_resolving_functions(promise, debugEvent);

推荐答案

根据您在评论中提供的链接,% 字符似乎用于某些 V8 JavaScript 引擎 源代码,用于指示将在解析 JavaScript 源代码时执行的 C++ 运行时方法.

Based on the link you provided in the comments, the % character appears to be used in some of the V8 JavaScript engine source code to indicate a method of the C++ runtime that will be executed while parsing the JavaScript source.

例如,string.js:

return %StringBuilderConcat(parts, len + 1, "");

当解析器遇到时,将执行StringBuilderConcat 方法.您可以在 runtime.h(注意,我没有使用 C++ 的经验,所以据我所知,这与 string.js 中引用的 StringBuilderConcat 方法无关,但我认为这是同一件事):

When encountered by the parser, the StringBuilderConcat method will be executed. You can find a list of the runtime methods available to the V8 JavaScript files in runtime.h (note, I have no experience with C++, so for all I know this has nothing to do with the StringBuilderConcat method referenced in string.js, but I think it's the same thing):

#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
  /* Property access */ \
  F(GetProperty, 2, 1) \
  F(KeyedGetProperty, 2, 1) \
  /* ... */
  F(StringBuilderConcat, 3, 1) \
  /* ... */

如前所述,return %foo 会在 JavaScript 中抛出 SyntaxError.

As has already been stated, return %foo would throw a SyntaxError in JavaScript.

这篇关于为什么 v8 源代码的 JS 文件中的某些函数调用前面带有 %?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆