What about JSObject? Object.prototype.hasOwnProperty.call(obj, prop)
Sundararajan Athijegannathan
sundararajan.athijegannathan at oracle.com
Wed Nov 23 05:06:17 UTC 2016
JSObject is a way to implement script friendly Java objects. But
JSObjects can not be substituted in all places where a real ScriptObject
is expected. In particular, JSObjects don't have any notion of prototype
and so JSObjects are not on par with ECMAScript script objects.
But, you can bind your POJO to an empty script object and pass it to
ECMAScript APIs.
See also:
https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions#Nashornextensions-Object.bindProperties
HTH,
-Sundar
On 11/19/2016 2:28 AM, Art Fiedler wrote:
> In UglifyJS2 they use Object.prototype.hasOwnProperty.call(obj, prop) to
> determine if the object has that property defined, others like LessCss use
> obj.hasOwnProperty(prop) so I was previously able to avoid implementing
> JSObject and just add a hasOwnProperty method onto my POJO... but in
> UglifyJS2 they use a for(i in obj) and the prototype call so I figured I
> had to implement JSObject now I did and ended up finding...
>
> jdk.nashorn.internal.objects.NativeObject.hasOwnProperty(self, v) only
> accepts a ScriptObject or a wrapped Boolean, Number, Object[], double[],
> int[], or ArrayData... My guess is this should also support
> JSObject.hasMember()
>
> Searching through NativeObject.java I actually don't find a single
> reference of JSObject it maybe possible there are a few other area's
> needing JSObject support.
>
> -Art
More information about the nashorn-dev
mailing list