[webkit-dev] JS: Getter/Setter callbacks at Property level
Brian Barnes
ggadwa at charter.net
Mon Jul 20 10:21:37 PDT 2009
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
>> webkit-dev at lists.webkit.org
>> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>
>
More information about the webkit-dev
mailing list