[webkit-help] Find out if a given JSValueRef is of a certain built-in class (Array, Date, Error, …)
marco at duckcode.com
Mon Feb 4 08:20:56 PST 2013
I found the solution thanks to "andersca" in the IRC chatroom (#webkit on irc.freenode.net):
The context's global object has the constructors as properties (e.g. this.Array). These can then be used in a call to JSValueIsInstanceOfConstructor().
> I'm looking for a way to find out if a given JSValueRef is, for example, an Array or a Date.
> Is there some other way to find the class of a given object?
> I tried the following approach, but that just doesn't seem right to me:
> • Call JSGlobalContextCreate()
> • Store a pointer to the prototype JSValueRef:
> arrayPrototype = JSObjectGetPrototype(JSObjectMakeArray())
> • To check if an arbitrary JSObjectRef is an Array:
> arrayPrototype == JSObjectGetPrototype(object)
> A little more detail about what I'm really trying to do:
> For this to work, I must know that kind of JSObjectRef I'm getting. I simply know that the JSType is kJSTypeObject, but there doesn't seem to be a way to simply get the class of an object.
> Thanks in advance,
More information about the webkit-help