Hi Brian.

I see what you mean now.

In JavaScriptCore, there's no API for defining C getters and setters individually. There's an API for associating a set of C getters and setters with a class, and there's an API for defining a generic fallback getter and setter for a class.

I looked briefly, and it seems like it would be relatively easy to add an API for adding C getters and setters to a class individually. So, that seems like a reasonable feature request.

I'm not sure how important it is to you to be able to add C getters and setters to objects, as opposed to classes, individually. I think that would be a trickier API to get right. The main challenge is that getters and setters of that dynamic nature tend to slow down the object system. So, we would either want to engineer a way to avoid the performance cost in most cases, or we would want to design a way to steer API users away from that particular API in the general case. If you have a good example of how this feature would be generally useful to API clients, it's still a reasonable request, though.

Geoff

On Jul 20, 2009, at 10:21 AM, Brian Barnes wrote:

In SpiderMonkey, you can create an object, and that object has a callback to a getter or a setter in C. You get the name, look it up, return or set a value. Nitro has that same functionality.

On SpiderMonkey, though, when creating a property, you can also do this:

JS_DefineProperty(context,object,name,value,getter,setter,flags);

Where "getter" and "setter" are direct calls for the property, for only that property. There's no lookup logic in my code.

So, in pseudo code, at object level, we'd have a single getter:

void getMyObjectValues(.... name ...)
{
 if (name == 'red') return(red)
 if (name == 'green') return(green)
 if (name == 'blue') return(blue)
}

And property level, we'd have 3 getters:

void getMyObjectRed(...)
{
return(red);
}

void getMyObjectGreen(...)
{
return(green);
}

void getMyObjectBlue(...)
{
return(blue);
}

[>] Brian

Geoffrey Garen wrote:
Hi Brian.

I don't understand the distinction you're drawing between "the property level" and "the object level". Can you explain what those mean and give an example of each?

Thanks,
Geoff

On Jul 20, 2009, at 9:14 AM, Brian Barnes wrote:

I was getting ready to try the first move from SpiderMonkey to Nitro, and ran into a large problem. Right now, all my getters and setters are at the property level. In the documentation I have, Nitro only seems to put them at the object level. This would force a huge refactoring of my code (which I'm willing to do if I have to, I would just like to avoid it as I have hundred or so objects.)

Is my documentation old, did I miss something, or am I stuck? If I'm stuck, is there any call to have this put into Nitro at some time in the future?

[>] Brian


_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev




_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to