[webkit-dev] Some JSC API Suggestions

Brian Barnes ggadwa at charter.net
Fri Aug 14 07:24:20 PDT 2009

A couple of "convenience" API suggestions.  Again, I'm in the middle of 
a big switch over from Mozilla's SpiderMonkey to JSC, so I see a couple 
IMHO (and I've been wrong before!) API additions that might make it 
easier for new users.

.... JSValueMakeObject(.....)

I know you can cast to the JSObjectRef from JSValueRef (if it is indeed 
a value), but it's not immediately obvious from the API (I figured it 
out from the examples.)  And it gives an equivalent to JSValueToObject, 
like all other types have.  What to do if the value isn't an object is 
probably one reason it doesn't exist, but maybe that could be doc'd to 
return a JS null or exception could actually be part of the call.

... JSValueMakeArray(.....size_t argumentCount,JSValueRef *arguments.....)

Another one that can obviously be done in code but would be nice as a 
convenience.  Right now it takes a good 5-10 lines to build an array 
(complete with values, etc.)

... JSValueMakeException( .... const char *str ....)

Just a way to make exception creating easy, and it could attach 
sourceURL, line, etc, there (this would also give you a cheap way to 
find out where you are in execution if you wanted to build some kind of 
specialized debugger, make an exception, get the line -- the same trick 
you do in Java.)  It makes throwing exceptions a bit easier.  Also, 
SpiderMonkey had one nice thing that could be used, which is sprintf 
like variable count exception functions, for instance:

*exception=JSValueMakeException(ctx,"There is no %s by the name of 

That would make it very easy to build and throw exceptions (in only one 
line most of the time) for most any exception.

Again, thanks for all the great work and listening to my suggestions, 
which might be dumb :)  I also have a couple places where I think the 
documentation generated from the header files could be updated, but I'll 
just bug you guys with one thing at a time.

[>] Brian

More information about the webkit-dev mailing list