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?
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.