hasOwnProperty & ECMAScript instanceof check not working on a custome ScriptObject

buddhi mihara buddhi.mihara at live.com
Thu Jan 2 04:01:05 PST 2014


hi,i created a object just like native math , following the structure of the jdk.nashorn.internal.objects.prototype object,but i have two question
1.instanceof check does not working on my cutom object but it working on the Math Object2.hasOwnProperty does not working it gives me error - (<shell>:1 TypeError: Cannot call undefined)
here is my code 
package Dilan;
import jdk.nashorn.internal.runtime.PropertyMap;import jdk.nashorn.internal.runtime.AccessorProperty;import jdk.nashorn.internal.runtime.ScriptObject;import jdk.nashorn.internal.runtime.Property;
import java.lang.invoke.MethodHandle;import java.lang.invoke.MethodHandles;import java.util.ArrayList;
import static jdk.nashorn.internal.lookup.Lookup.MH;import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
public class Jaggery2 {
    public static ScriptObject getJagGlobal(){        final ScriptObject pros = new JaggeryPro();        return pros;    }
    //class represent jaggery2 Pro Object    private static final class JaggeryPro extends ScriptObject {
        private static PropertyMap $nasgenmap$;
        JaggeryPro(){            super($nasgenmap$);        }
        static PropertyMap getInitialMap() {            return $nasgenmap$;        }
        private static final MethodHandle GET_CACHE = findOwnMH("getCache", Object.class,Object.class);        private static final MethodHandle GET_BIND  = findOwnMH("getBind", Object.class, Object.class);
        static {
            final ArrayList<Property> properties = new ArrayList<>();            properties.add(AccessorProperty.create("caches", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, GET_CACHE, null));            properties.add(AccessorProperty.create("bind", Property.WRITABLE_ENUMERABLE_CONFIGURABLE,GET_BIND, null));
            $nasgenmap$ = PropertyMap.newMap(properties);        }

        static Object getCache(final Object self) {            return (self instanceof JaggeryPro) ?                    ((JaggeryPro)self).getModule() :                    UNDEFINED;        }
        static Object getBind(final Object self) {            return (self instanceof JaggeryPro) ?                    ((JaggeryPro)self).getBind() :                    UNDEFINED;        }
        private Object getModule(){            return 1;        }
        private Object getBind(){            return new BindImpl();        }
        private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {            return MH.findStatic(MethodHandles.lookup(), JaggeryPro.class, name, MH.type(rtype, types));        }
        @Override        public String getClassName() {            return "JAGGERYPROCESS";        }
    }}
how can i solve those two errors.i have wrap this object using ScripObjecMirror.but than ain't help
thank you
 		 	   		  


More information about the nashorn-dev mailing list