hasOwnProperty & ECMAScript instanceof check not working on a custome ScriptObject

A. Sundararajan sundararajan.athijegannathan at oracle.com
Thu Jan 2 04:24:11 PST 2014


Hi,

* You may want to align your email text before posting it.

* As replied to one of your earlier emails, jdk.nashorn.internal.* are 
internal classes. These could be removed/changed without notice. Your 
interface to nashorn is just javax.script and jdk.nashorn.api.scripting 
packages. If you *really* want to play with internals, you are 
essentially on your own. We try to document as much as needed for 
nashorn developers. But, if you depend on internals in *your* code, 
nashorn team may not be able to support the same.

-Sundar

On Thursday 02 January 2014 05:31 PM, buddhi mihara wrote:
> 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