How to use% signs in identifiers

Looking at the v8 tree, in the src directory, there were some js files providing some basic JS objects such as Math, Array, etc. Looking through these files, I saw identifiers, including the percent sign (%) in their names, i.e. %Foo . At first, I naively thought that it was another allowed character in JS identifiers, but when I tried it in the shell, he screamed at me, saying that he was violating the rules of syntax. But if this is a syntax error, how does d8 work? Here is an example from the source code:

src / apinatives.js lines 44 to 47, git clone from github / v8 / v8

 function Instantiate(data, name) { if (!%IsTemplate(data)) return data; var tag = %GetTemplateField(data, kApiTagOffset); switch (tag) { 

src / apinatives.js lines 41 to 43, git clone from github / v8 / v8

 function SetConstructor() { if (%_IsConstructCall()) { %SetInitialize(this); 

Why these identifiers do not give syntax errors. All js files, including math.js and string.js and all the rest ?: Wq

+6
source share
1 answer

This is not technically valid JavaScript. These are V8 runtime function calls . From this page:

Most JavaScript libraries are implemented in JavaScript code themselves, using a minimal set of C ++ runtime functions called from JavaScript. Some of them are called using names beginning with%, and using the "-allow-natives-syntax" flag. Others are only called by the code generated by the code generators and are not visible in JS, even using the% syntax.

If you look at parser.cc , you can see the code related to allow_natives_syntax , which determines whether the parser will accept this extension in JavaScript, which V8 uses to interact with its runtime. These files should be analyzed with the option enabled.

I would suggest that V8 does not allow you to make these calls by default, since it is against the JavaScript standard and because it will probably allow you to do something in the runtime environment that you cannot make.

+15
source

All Articles