[webkit-dev] when can I treat a JSValueRef as a JSObjectRef?
Since JSValueRef and JSObjectRef are typedef's to the same OpaqueJSValue structure (pointer), it appears you could almost use them in the same contexts. And if fact, it appears you can use a JSObjectRef wherever a JSValueRef is defined in the API. And you can sometimes use a JSValueRef wherever a JSObjectRef is defined. It would be nice to see this documented a little better. My current guess is that if JSValueGetType() returns kJSTypeObject for a JSValueRef, you can safely treat it as a JSObjectRef. If it doesn't, then you can't. Guess is based on looking at the code, seeing the pointer dereferenced in the JSObjectRef cases, but knowing that those pointers are actually sometimes tagged pointers for literal values, in which case the dereference won't work. -- Patrick Mueller ___ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
Re: [webkit-dev] when can I treat a JSValueRef as a JSObjectRef?
On May 4, 2009, at 10:17 AM, Patrick Mueller wrote: Since JSValueRef and JSObjectRef are typedef's to the same OpaqueJSValue structure (pointer) It’s easy to get the wrong idea about this by looking at the implementation. These two typedefs use the same structure, but they use const in an unusual way to make the compiler check the relationship between the types. Because of how the types are defined all JSObjectRef values work as JSValueRef values without any type cast. There are many JSValueRef values that are not JSObjectRef values, so converting from one to the other requires a type cast. If you want to use a JSValueRef as a JSObjectRef, you need to call JSValueIsObject and if it’s true, then you can cast the JSValueRef to a JSObjectRef. Or you can use JSValueGetType, but that could be less efficient so you should use it only if you care which specific type it is if it’s not a JSObjectRef. It would be nice to see this documented a little better. What documentation were you reading? Since WebKit is an open source project, if you have improvements to, say, the comments in the header, you can submit them as a patch. Most of the mechanics are covered at http://webkit.org/coding/contributing.html , although some of the steps don’t apply for changes that are entirely in comments. If this was some Apple documentation you were reading, not generated directly from the header file, then you could instead file a bug at http://bugreport.apple.com suggesting improvements. My current guess is that if JSValueGetType() returns kJSTypeObject for a JSValueRef, you can safely treat it as a JSObjectRef. If it doesn't, then you can't. Yes, that’s right. -- Darin ___ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
Re: [webkit-dev] when can I treat a JSValueRef as a JSObjectRef?
Darin Adler wrote: What documentation were you reading? Since WebKit is an open source project, if you have improvements to, say, the comments in the header, you can submit them as a patch. Most of the mechanics are covered at http://webkit.org/coding/contributing.html, although some of the steps don’t apply for changes that are entirely in comments. If this was some Apple documentation you were reading, not generated directly from the header file, then you could instead file a bug at http://bugreport.apple.com suggesting improvements. Thanks for the quick reply. The docs I was reading were in fact the Apple docs, which AFAIK are the only docs for JavaScriptCore. When working at the API level, I try to stick to docs instead of code, but sometimes I cheat :-) Actually, I learned a lot by printing out pointer values, without even looking at the impl. Maybe it would make sense for webkit.org to host something similar to the apple docs, located here, http://developer.apple.com/documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/ so that mortals could contribute back to that level of documentation. At the minimum, I suspect the turn around time in getting changes to such doc would be quicker than going through official Apple support. I'll file a report at the apple site in the meantime though. -- Patrick Mueller ___ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
Re: [webkit-dev] when can I treat a JSValueRef as a JSObjectRef?
On May 4, 2009, at 10:53 AM, Patrick Mueller wrote: The docs I was reading were in fact the Apple docs I believe the document you cited is automatically generated from the comments in the JavaScriptCore headers. So if we improve the documentation comments in the headers in the WebKit open source project, eventually the Apple reference document will get those same fixes. -- Darin ___ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev