Typeof and Expression* in V8

你。 提交于 2020-01-06 02:12:31

问题


I am experimenting with the V8 engine.

In V8 (full-codegen-x64.cc) exists this function for comparing types:

void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
                                             Expression* sub_expr,
                                             Handle<String> check)

So, if for example:

   typeof Obj == "object"

Then sub_expr is an Expression object with "typeof Obj" and check is an "object".

How can I get a JSObject from an Expression object, if possible? - not possible (You can't. An Expression is a piece of syntax Andreas Rossberg)

In void FullCodeGenerator::EmitLiteralCompareTypeof we can check if :

Obj is function   __ CmpObjectType(rax, JS_FUNCTION_TYPE, rdx);
Obj is proxy function  __ CmpInstanceType(rdx, JS_FUNCTION_PROXY_TYPE);
Obj is proxy __ CmpObjectType(rax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, rdx);
and etc...

Just for example if we will use this code:

__ CmpObjectType(rax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, rdx);
__ j(equal, if_true);
then
typeof Proxy_Obj == 'string'  ---> true

How V8 knows about this? Is it mean - V8 run code?


回答1:


You can't. An Expression is a piece of syntax, a JSObject is a runtime object. They have absolutely nothing to do with each other.



来源:https://stackoverflow.com/questions/29102874/typeof-and-expression-in-v8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!