termi / es6-transpiler

Tomorrow's JavaScript syntax today
Other
216 stars 18 forks source link

Rhino support #41

Open ai opened 10 years ago

ai commented 10 years ago

When I try to run compiled JS in Rhino, I get error:

InternalError: Changing attributes not supported for Function prototype property

It was generated because of:

var DP$0 = Object.defineProperty;
DP$0(MyClass, "prototype", {"configurable": false, "enumerable": false, "writable": false});

Problem is that Rhino deby to replace prototype. But this code is unnecessary in Rhino, because MyClass.prototype is already not writable.

Rhino support is very important to me, because it allow to run JS code on Java (and languages like JRuby). It is a big market and fix is very small.

ai commented 10 years ago

@termi Traceur has same issue: https://github.com/google/traceur-compiler/issues/1200

ai commented 10 years ago

@termi we can wrap DP$0 into try catch or detect Rhino.

ai commented 10 years ago

@termi how I can help with this fix?

termi commented 10 years ago

Sorry for the long absence. I don't think it should be part of the transpiler, since it's an environment bug and you can wrap it by your self:

var $Object_defineProperty = Object.defineProperty;
Object.defineProperty = function(obj, prop, desc) {
    if ( prop === 'prototype' ) {
        delete desc['writable'];
        arguments[2] = desc;
    }
    return $Object_defineProperty.apply(this, arguments);
}

But I will do an option for this in one of the future versions. Don't close this issue.