objects with "get" properties

Maciej Stachowiak mjs at apple.com
Mon Jun 16 21:29:28 CEST 2003


On Friday, June 13, 2003, at 09:55  AM, George Staikos wrote:

>
>    I stumbled across objects with "get" properties in some mozilla JS, 
> and we
> don't currently parse it (gives a parse error).  Does the Apple 
> ScriptCore
> handle it yet?

No, JavaScriptCore does not handle it.

>  Here's an example:
>
> var someObject = {
>       _someMember : "foo",
>       get someProperty() {
>                return this._someMember + this._someMember;
>       }
> };
>
> someObject.someProperty == "foofoo"
>
>    Is this part of the spec, or a Mozilla-ism?

It's a Mozilla-ism and not part of any current spec. It's part of their 
proposal for the next version of ECMAScript, but it's unclear if that 
will ever go through, and if it will continue to include this change 
when it does.

>    It was easy to add the parser support for this, but I'm not exactly 
> sure
> what the best approach is to implement this.  Properties seem to 
> explicitly
> have Values as the value (go figure ;)) which doesn't work too well 
> for this
> case.  Should there be a class FunctionValue : public Value  that gets
> executed in the object context whenever its value is requested?  Is 
> there a
> better approach?

If you decide to implement this, I think a better approach would be to 
have a separate table of getter properties, and a similar table of 
setter properties. Then the ObjectImp::get method could check the 
getter properties table separately from the regular property map. These 
tables could be consulted before the property map when getting and 
setting.

Is there a site that needs this feature to work properly?

Regards,
Maciej



More information about the Khtml-devel mailing list