This project has moved. For the latest updates, please go here.

Weird getter/setter issue

Jul 25, 2013 at 12:08 AM
So, in Jurassic it seems to have some weird scoping/naming issue that other JS engines do not have. I don't know if this is strictly an ECMA thing or a Jurassic corner case issue.

This code:
var prop = 6;

var a = { get prop() { return prop; } };

print(a.prop);
It will print 6 in most engines w/ a print function implemented. In Jurassic it prints: "function prop() { return prop; }" Now, if I instead renamed that outer variable to something else it will work. So long as that variable is named the same name as the getter (or setter) it doesn't work as intended.
Coordinator
Jul 25, 2013 at 4:48 AM
Wow that's pretty obscure :-) I've committed a fix for this issue (166c33aeda0e).
Jul 25, 2013 at 6:17 AM
Thank you! :D

As an aside: I've been using this for a video game scripting language, using SFML as the base game library. I think it's a really solid example of your work being embedded in a major codebase: there was an older game engine, but I wanted to leverage newer technologies to create a better version of that engine. Since you implement ECMA 5 so well (up to that quirky issue you solved) your engine was a dead-simple drop-in replacement. The only thing left on my wishlist is for you to help make Jurassic compile under Mono. I've read here that something like that won't happen anytime soon though, and a limited Jurassic API wouldn't quite cut it.

Also for those interested, here's how I solved the spidermonkey-like __defineG/Setter__ in Jurassic:
            engine.Execute("Object.defineProperty(Object.prototype, \"__defineGetter__\", { value: function(name, func) {" +
                "Object.defineProperty(this, name, { get: func, configurable: true }); } });");

            engine.Execute("Object.defineProperty(Object.prototype, \"__defineSetter__\", { value: function(name, func) {" +
                "Object.defineProperty(this, name, { set: func, configurable: true }); } });");

It is not technically ECMA 5, but helps with compatibility. In order to make it not enumerable I had to use defineProperty to define the __G/Setter__ methods. ;)