Compatibility with the typeof, instanceof keywords
Is there any expected support for the mentioned keywords in the future? Currently it's not such a big deal when working with typeof as it can be easily polyfilled with inlining. While speaking of instanceof, I haven't seemed to find any intrinsics in the API (see below), which would allow me to pass the wanted types. I know it's not doable with just simple __asm__ as it's quite limited for this case
9 Replies
(Replacing a previous answer, since I did not fully understood the problem at first).
Can you elaborate on what are the limitations you see with using
__asm__
? That would help in understanding the exact scope of your requirements. Extending C++ in terms of new keyword is not something that we would consider, but the compiler could be made powerful enough to express what you want as a normal template method.Sure, I wasn't exactly talking about extending it with a new keyword as it would likely break the compatibility with C++ but more of an adding a support at a compiler intrinsics level, which would allow the types to be passed as actual values via the template, the asm, as I said before is quite limited in regards to passing those
@Chen Do you see any reasonable way to provide support for something along those lines? I'd rather avoid something completely ad-hoc
Possible suggestion:
->instanceOf<T>()
This seems possible, either by adding a special static variable to all client types that stores the corresponding javascript type, or with an templated intrinsic that returns the javascript type for a client type. It should then be relatively simple to implement functions like
typeof
and instanceof
in c++.I'm not sure if having it as a part of an object would be a good idea, mixing JS object's methods with Cheerp's ones feels a bit questionable
Personally I feel like leaving for it a dedicated templated intrinsic would be pretty acceptable, like for example
client::instanceof<T>()
/cheerp::instanceof<T>()
?After some more discussion we have decided that we want to implement this, though it will likely be implemented as a member of the object to stay consistent with
->cast()
. There is some other work I need to finish first before I can start on this, but if you're interested I can let you know when it's done.Okay, got it, yes that's fine, good to know, it would be nice to have it as it comes in pretty handy when dealing with weakly typed parameters. Besides that I'll probably wait till the next stable release anyway.
@Awesome Marking the question as resolved, work on the requested feature has been allocated and will start soon
instanceof
and _typeof
are now available in nightly.