From sundararajan.athijegannathan at oracle.com Wed Nov 2 08:27:31 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Wed, 2 Nov 2016 13:57:31 +0530 Subject: dynalink alternative for jdk8 In-Reply-To: References: Message-ID: If your java_type_object.someMethod method's signature is something like: void someMethod(JSObject obj) { } then from nashorn side, you can pass script objects and your java code would receive it as JSObject. java_type_object.someMethod({k: 1}); should work fine in that case. To operate smoothly on JsonObject/JsonArray on script object is somewhat involved. You may have to use JSAdapter or JSObject wrapper over your Java object for script friendliness... Regards, -Sundar On 10/28/2016 7:35 PM, Paulo Lopes wrote: > Hi everyone, > > I'm working with eclipse vert.x project javascript support and one > thing we would like to achieve was to simplify our bindings code by > having what could be done with dynalink to provide "automatic" > conversion between: > > JSObject <--> io.vertx.core.json.JsonObject > > We do not want to introduce helper functions to the end user like: > > var java_type_object = Java.type(...); > > java_type_object.someMethod(to_native({k: 1})); > > but we would like to have: > > java_type_object.someMethod({k: 1}); > > > Currently we have a code generator that writes a full wrapper for the > vert.x API that will do this translation, but this has several > limitations, we must force a very restricted set of types to be used in > public APIs, there's a build step for each module, introduces potential > bugs if the generated code is not correct. > > After reading the Dynalink API and examples from JDK9 it seems that > this could be done with it since one could write a linker from JSObject > properties to JsonObject and vice-versa but this is not present on > JDK8. > > Even though dynalink was present on JDK8 the service loader is not > present or at least should not be used. > > So my question is, what alternatives/suggestions do you have to achieve > this? > > I'm thinking of something like groovy metaprogramming but that would > also require dynalink, or not? > > For the sake of completeness I must say that JsonObject/JsonArray do > not implement java.util.Map/java.util.List interfaces so one cannot > rely on the fact that nashorn would internally handle those for us. > > Best regards, > Paulo From sundararajan.athijegannathan at oracle.com Wed Nov 2 12:38:27 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Wed, 2 Nov 2016 18:08:27 +0530 Subject: RFR 8169050: underscore_linker.js sample fails after dynalink changes for JDK-8168005 Message-ID: <7860ebcb-73e7-7145-ea50-2bcde1857b21@oracle.com> Please review http://cr.openjdk.java.net/~sundar/8169050/webrev.00/ for https://bugs.openjdk.java.net/browse/JDK-8169050 PS. The failing sample exposed a bug in nashorn's NashornCallSiteDescriptor. I converted that sample as a test. Thanks, -Sundar From james.laskey at oracle.com Wed Nov 2 12:49:19 2016 From: james.laskey at oracle.com (Jim Laskey (Oracle)) Date: Wed, 2 Nov 2016 09:49:19 -0300 Subject: RFR 8169050: underscore_linker.js sample fails after dynalink changes for JDK-8168005 In-Reply-To: <7860ebcb-73e7-7145-ea50-2bcde1857b21@oracle.com> References: <7860ebcb-73e7-7145-ea50-2bcde1857b21@oracle.com> Message-ID: <3C0BE415-CC16-46B7-B21D-9BD4EF9A76D5@oracle.com> +1 > On Nov 2, 2016, at 9:38 AM, Sundararajan Athijegannathan wrote: > > Please review http://cr.openjdk.java.net/~sundar/8169050/webrev.00/ for > https://bugs.openjdk.java.net/browse/JDK-8169050 > > PS. The failing sample exposed a bug in nashorn's > NashornCallSiteDescriptor. I converted that sample as a test. > > Thanks, > > -Sundar > From hannes.wallnoefer at oracle.com Wed Nov 2 13:00:44 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Wed, 2 Nov 2016 14:00:44 +0100 Subject: RFR 8169050: underscore_linker.js sample fails after dynalink changes for JDK-8168005 In-Reply-To: <3C0BE415-CC16-46B7-B21D-9BD4EF9A76D5@oracle.com> References: <7860ebcb-73e7-7145-ea50-2bcde1857b21@oracle.com> <3C0BE415-CC16-46B7-B21D-9BD4EF9A76D5@oracle.com> Message-ID: Good catch, + 1 Hannes > Am 02.11.2016 um 13:49 schrieb Jim Laskey (Oracle) : > > +1 > >> On Nov 2, 2016, at 9:38 AM, Sundararajan Athijegannathan wrote: >> >> Please review http://cr.openjdk.java.net/~sundar/8169050/webrev.00/ for >> https://bugs.openjdk.java.net/browse/JDK-8169050 >> >> PS. The failing sample exposed a bug in nashorn's >> NashornCallSiteDescriptor. I converted that sample as a test. >> >> Thanks, >> >> -Sundar >> > From hannes.wallnoefer at oracle.com Mon Nov 7 10:01:07 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Mon, 7 Nov 2016 11:01:07 +0100 Subject: RFR: 8156619: Unimplemented ES6 features should result in clear Error being thrown Message-ID: Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8156619 Webrev: http://cr.openjdk.java.net/~hannesw/8156619/webrev.00/ Note that this also contains a small fix in Parser which was an oversight in my previous backport of ES6 changes from Graaljs. It made some destructuring cases impossible to detect but does not affect the syntax we currently support, which is why it wasn?t noticed before. Thanks, Hannes From hannes.wallnoefer at oracle.com Mon Nov 7 11:52:58 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Mon, 7 Nov 2016 12:52:58 +0100 Subject: RFR: 8156619: Unimplemented ES6 features should result in clear Error being thrown In-Reply-To: <8123830c-6276-0604-e3da-495116eecf80@oracle.com> References: <8123830c-6276-0604-e3da-495116eecf80@oracle.com> Message-ID: <3A5B394D-BED2-49FB-81E7-8F3B92C04EF6@oracle.com> Thanks Sundar. For the super keyword, we store its usage in the function while super itself is a normal identifier. For generators, the function actually is the entity although you could argue we should point to the * token that makes it a generator. I?d rather not have to change these, I hope you?re fine with that. Hannes > Am 07.11.2016 um 11:30 schrieb Sundararajan Athijegannathan : > > generator and super keyword "not yet implemented" errors (carets in > error message) point to the beginning of the function declaration > (rather than to the exact place of issue). Other than that, +1 > > -Sundar > > > On 11/7/2016 3:31 PM, Hannes Walln?fer wrote: >> Please review: >> >> Bug: https://bugs.openjdk.java.net/browse/JDK-8156619 >> Webrev: http://cr.openjdk.java.net/~hannesw/8156619/webrev.00/ >> >> Note that this also contains a small fix in Parser which was an oversight in my previous backport of ES6 changes from Graaljs. It made some destructuring cases impossible to detect but does not affect the syntax we currently support, which is why it wasn?t noticed before. >> >> Thanks, >> Hannes > From szegedia at gmail.com Mon Nov 7 12:14:00 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Mon, 7 Nov 2016 13:14:00 +0100 Subject: RFR: 8156619: Unimplemented ES6 features should result in clear Error being thrown In-Reply-To: <3A5B394D-BED2-49FB-81E7-8F3B92C04EF6@oracle.com> References: <8123830c-6276-0604-e3da-495116eecf80@oracle.com> <3A5B394D-BED2-49FB-81E7-8F3B92C04EF6@oracle.com> Message-ID: <841C0F1E-2813-455D-8F28-08D09316DB1A@gmail.com> +1 from me. > On 07 Nov 2016, at 12:52, Hannes Walln?fer wrote: > > Thanks Sundar. > > For the super keyword, we store its usage in the function while super itself is a normal identifier. For generators, the function actually is the entity although you could argue we should point to the * token that makes it a generator. I?d rather not have to change these, I hope you?re fine with that. > > Hannes > > > >> Am 07.11.2016 um 11:30 schrieb Sundararajan Athijegannathan : >> >> generator and super keyword "not yet implemented" errors (carets in >> error message) point to the beginning of the function declaration >> (rather than to the exact place of issue). Other than that, +1 >> >> -Sundar >> >> >> On 11/7/2016 3:31 PM, Hannes Walln?fer wrote: >>> Please review: >>> >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156619 >>> Webrev: http://cr.openjdk.java.net/~hannesw/8156619/webrev.00/ >>> >>> Note that this also contains a small fix in Parser which was an oversight in my previous backport of ES6 changes from Graaljs. It made some destructuring cases impossible to detect but does not affect the syntax we currently support, which is why it wasn?t noticed before. >>> >>> Thanks, >>> Hannes >> > From sundararajan.athijegannathan at oracle.com Mon Nov 7 12:15:42 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Mon, 7 Nov 2016 17:45:42 +0530 Subject: RFR: 8156619: Unimplemented ES6 features should result in clear Error being thrown In-Reply-To: <3A5B394D-BED2-49FB-81E7-8F3B92C04EF6@oracle.com> References: <8123830c-6276-0604-e3da-495116eecf80@oracle.com> <3A5B394D-BED2-49FB-81E7-8F3B92C04EF6@oracle.com> Message-ID: While it is okay on generators, reporting super keyword usage with function declaration looks bit odd.. That said, it is not very serious. +1 -Sundar On 11/7/2016 5:22 PM, Hannes Walln?fer wrote: > Thanks Sundar. > > For the super keyword, we store its usage in the function while super itself is a normal identifier. For generators, the function actually is the entity although you could argue we should point to the * token that makes it a generator. I?d rather not have to change these, I hope you?re fine with that. > > Hannes > > > >> Am 07.11.2016 um 11:30 schrieb Sundararajan Athijegannathan : >> >> generator and super keyword "not yet implemented" errors (carets in >> error message) point to the beginning of the function declaration >> (rather than to the exact place of issue). Other than that, +1 >> >> -Sundar >> >> >> On 11/7/2016 3:31 PM, Hannes Walln?fer wrote: >>> Please review: >>> >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156619 >>> Webrev: http://cr.openjdk.java.net/~hannesw/8156619/webrev.00/ >>> >>> Note that this also contains a small fix in Parser which was an oversight in my previous backport of ES6 changes from Graaljs. It made some destructuring cases impossible to detect but does not affect the syntax we currently support, which is why it wasn?t noticed before. >>> >>> Thanks, >>> Hannes From srinivas.dama at oracle.com Mon Nov 7 16:10:01 2016 From: srinivas.dama at oracle.com (Srinivas Dama) Date: Mon, 7 Nov 2016 08:10:01 -0800 (PST) Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode Message-ID: <3eed0422-4b87-4257-a404-8c4b93554c19@default> Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. Regards, Srinivas From sundararajan.athijegannathan at oracle.com Tue Nov 8 03:45:04 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Tue, 8 Nov 2016 09:15:04 +0530 Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: <3eed0422-4b87-4257-a404-8c4b93554c19@default> References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> Message-ID: <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> You need to update Parser API implementation to handle catch parameter being expression - rather than an IdentNode. => you need to * add another getter in CatchNode to expose Expression * Use it in IRTranslator (of Parser API impl.) to translate catch param as expression * You need to check for expression param in codegen pipeline to throw "not yet implemented" error. -Sundar On 11/7/2016 9:40 PM, Srinivas Dama wrote: > Please review: > Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 > Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ > > Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. > > Regards, > Srinivas From szegedia at gmail.com Tue Nov 8 13:01:05 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Tue, 8 Nov 2016 14:01:05 +0100 Subject: Review request for JDK-8168373: don't emit conversions for symbols outside their lexical scope Message-ID: <6B221818-832D-42A6-AEBF-0F15F7C64E6D@gmail.com> Please review JDK-8168373 "don't emit conversions for symbols outside their lexical scope" at for Few remarks on the implementation: - I changed localVariableTypes from using IdentityHashMap to HashMap. The reason for this is that Symbol uses identity semantics for equals/hashCode anyway, and IdentityHashMap.keySet() has a worse implementation of removeAll, which is now used. HashMap has O(min(m, n)) where ?m? and ?n? are sizes of the two collections involved in removeAll, while IdentityHashMap.keySet() is always O(n) to the size of the map. - in the ?-462,13? patch block: we now clone localVariableTypes at most once, instead of once per symbol that needs to be set in it (that was happening in the setType() call). This is an optimization fix. - in the ?-1044,19? patch block there?s no longer a need to manually remove exceptionSymbol from the localVariableTypes when following the CF edge from a catch body to the try statement's end label. It becomes part of the general case handling lexically scoped symbols; leaveBlock on catchBody will take care of it. - the PrintVisitor change now correctly prints ?const? and ?let? nodes. I was using it for debugging and it was confusing that it printed ?var? for ?let?. Thanks, Attila. From szegedia at gmail.com Tue Nov 8 14:10:00 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Tue, 8 Nov 2016 15:10:00 +0100 Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> Message-ID: <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> What Sundar said. Additionally: + if (exception instanceof IdentNode) { + this.exception = ((IdentNode) exception == null) ? null : ((IdentNode) exception).setIsInitializedHere(); First, casting an expression before a null comparison is silly :-). Second, you don?t even need to check for exception == null as "exception instanceof IdentNode? implies that exception != null. So that line should just be: + if (exception instanceof IdentNode) { + this.exception = ((IdentNode) exception).setIsInitializedHere(); Attila. > On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: > > You need to update Parser API implementation to handle catch parameter > being expression - rather than an IdentNode. > > => you need to > > * add another getter in CatchNode to expose Expression > > * Use it in IRTranslator (of Parser API impl.) to translate catch param > as expression > > * You need to check for expression param in codegen pipeline to throw > "not yet implemented" error. > > -Sundar > > On 11/7/2016 9:40 PM, Srinivas Dama wrote: >> Please review: >> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >> >> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >> >> Regards, >> Srinivas > From hannes.wallnoefer at oracle.com Tue Nov 8 17:07:57 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Tue, 8 Nov 2016 18:07:57 +0100 Subject: Review request for JDK-8168373: don't emit conversions for symbols outside their lexical scope In-Reply-To: <6B221818-832D-42A6-AEBF-0F15F7C64E6D@gmail.com> References: <6B221818-832D-42A6-AEBF-0F15F7C64E6D@gmail.com> Message-ID: <38E4CF2B-A8AC-4B34-8141-9863423F78F5@oracle.com> +1 Thank for fixing this, Attila! Hannes > Am 08.11.2016 um 14:01 schrieb Attila Szegedi : > > Please review JDK-8168373 "don't emit conversions for symbols outside their lexical scope" at for > > Few remarks on the implementation: > - I changed localVariableTypes from using IdentityHashMap to HashMap. The reason for this is that Symbol uses identity semantics for equals/hashCode anyway, and IdentityHashMap.keySet() has a worse implementation of removeAll, which is now used. HashMap has O(min(m, n)) where ?m? and ?n? are sizes of the two collections involved in removeAll, while IdentityHashMap.keySet() is always O(n) to the size of the map. > > - in the ?-462,13? patch block: we now clone localVariableTypes at most once, instead of once per symbol that needs to be set in it (that was happening in the setType() call). This is an optimization fix. > > - in the ?-1044,19? patch block there?s no longer a need to manually remove exceptionSymbol from the localVariableTypes when following the CF edge from a catch body to the try statement's end label. It becomes part of the general case handling lexically scoped symbols; leaveBlock on catchBody will take care of it. > > - the PrintVisitor change now correctly prints ?const? and ?let? nodes. I was using it for debugging and it was confusing that it printed ?var? for ?let?. > > Thanks, > Attila. > From srinivas.dama at oracle.com Thu Nov 10 11:46:34 2016 From: srinivas.dama at oracle.com (Srinivas Dama) Date: Thu, 10 Nov 2016 03:46:34 -0800 (PST) Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> Message-ID: Hi, Please review Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.02/ Included all changes suggested with some modifications. Regards, Srinivas -----Original Message----- From: Attila Szegedi [mailto:szegedia at gmail.com] Sent: Tuesday, November 08, 2016 7:40 PM To: Nashorn-dev Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode What Sundar said. Additionally: + if (exception instanceof IdentNode) { + this.exception = ((IdentNode) exception == null) ? null : + ((IdentNode) exception).setIsInitializedHere(); First, casting an expression before a null comparison is silly :-). Second, you don't even need to check for exception == null as "exception instanceof IdentNode" implies that exception != null. So that line should just be: + if (exception instanceof IdentNode) { + this.exception = ((IdentNode) exception).setIsInitializedHere(); Attila. > On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: > > You need to update Parser API implementation to handle catch parameter > being expression - rather than an IdentNode. > > => you need to > > * add another getter in CatchNode to expose Expression > > * Use it in IRTranslator (of Parser API impl.) to translate catch > param as expression > > * You need to check for expression param in codegen pipeline to throw > "not yet implemented" error. > > -Sundar > > On 11/7/2016 9:40 PM, Srinivas Dama wrote: >> Please review: >> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >> >> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >> >> Regards, >> Srinivas > From sundararajan.athijegannathan at oracle.com Thu Nov 10 12:02:22 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Thu, 10 Nov 2016 17:32:22 +0530 Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> Message-ID: You may want to add a parser API test for catch parameter being a pattern rather than an identifier. -Sundar On 11/10/2016 5:16 PM, Srinivas Dama wrote: > Hi, > > Please review > Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 > webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.02/ > > Included all changes suggested with some modifications. > > Regards, > Srinivas > > -----Original Message----- > From: Attila Szegedi [mailto:szegedia at gmail.com] > Sent: Tuesday, November 08, 2016 7:40 PM > To: Nashorn-dev > Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode > > What Sundar said. Additionally: > > + if (exception instanceof IdentNode) { > + this.exception = ((IdentNode) exception == null) ? null : > + ((IdentNode) exception).setIsInitializedHere(); > > First, casting an expression before a null comparison is silly :-). > Second, you don't even need to check for exception == null as "exception instanceof IdentNode" implies that exception != null. So that line should just be: > > + if (exception instanceof IdentNode) { > + this.exception = ((IdentNode) exception).setIsInitializedHere(); > > Attila. > >> On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: >> >> You need to update Parser API implementation to handle catch parameter >> being expression - rather than an IdentNode. >> >> => you need to >> >> * add another getter in CatchNode to expose Expression >> >> * Use it in IRTranslator (of Parser API impl.) to translate catch >> param as expression >> >> * You need to check for expression param in codegen pipeline to throw >> "not yet implemented" error. >> >> -Sundar >> >> On 11/7/2016 9:40 PM, Srinivas Dama wrote: >>> Please review: >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >>> >>> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >>> >>> Regards, >>> Srinivas From szegedia at gmail.com Thu Nov 10 12:07:32 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Thu, 10 Nov 2016 13:07:32 +0100 Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> Message-ID: <3BBF85E3-AE5A-40AA-B7DC-3608ABFE801D@gmail.com> I?m still not happy with this, although we?re getting there :-) - you changed getException() to return Expression, even though Sundar asked you to add a different method. I don?t like the fact that getException() returns Expression, since it can?t be an arbitrary expression; it?s limited to identifier and binding pattern, yet you have unchecked casts on its return value on invocation everywhere now. Maybe keep your ?Expression getException()? change, but add ?IdentNode getExceptionIdentifier() { return (IdentNode)exception; }? and have the callers use that now instead. That way, you encapsulate the cast and don?t force the users of the API to do it everywhere, and it?s easier to track with call hierarchy in the IDEs which callers presume the exception is an identifier. - the JavaDoc for getException() and setException() should be updated to reflect the value can be a binding pattern. Please use the wording ?binding pattern? instead of just ?pattern? in the documentation (including the field declaration) to avoid ambiguity. - Maybe throw an IllegalArgumentException if either the constructor or setException receive something that isn?t either an ident node or a binding pattern. That way, you could enforce an invariant in the class that the types of the expression are only legitimate ones. I?m unsure if it?s easy to recognize the binding pattern or not (e.g. if it just looks like an object/array literal). Attila. > On 10 Nov 2016, at 12:46, Srinivas Dama wrote: > > Hi, > > Please review > Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 > webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.02/ > > Included all changes suggested with some modifications. > > Regards, > Srinivas > > -----Original Message----- > From: Attila Szegedi [mailto:szegedia at gmail.com] > Sent: Tuesday, November 08, 2016 7:40 PM > To: Nashorn-dev > Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode > > What Sundar said. Additionally: > > + if (exception instanceof IdentNode) { > + this.exception = ((IdentNode) exception == null) ? null : > + ((IdentNode) exception).setIsInitializedHere(); > > First, casting an expression before a null comparison is silly :-). > Second, you don't even need to check for exception == null as "exception instanceof IdentNode" implies that exception != null. So that line should just be: > > + if (exception instanceof IdentNode) { > + this.exception = ((IdentNode) exception).setIsInitializedHere(); > > Attila. > >> On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: >> >> You need to update Parser API implementation to handle catch parameter >> being expression - rather than an IdentNode. >> >> => you need to >> >> * add another getter in CatchNode to expose Expression >> >> * Use it in IRTranslator (of Parser API impl.) to translate catch >> param as expression >> >> * You need to check for expression param in codegen pipeline to throw >> "not yet implemented" error. >> >> -Sundar >> >> On 11/7/2016 9:40 PM, Srinivas Dama wrote: >>> Please review: >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >>> >>> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >>> >>> Regards, >>> Srinivas >> > From szegedia at gmail.com Thu Nov 10 12:20:41 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Thu, 10 Nov 2016 13:20:41 +0100 Subject: Review request for JDK-8168373: don't emit conversions for symbols outside their lexical scope In-Reply-To: <38E4CF2B-A8AC-4B34-8141-9863423F78F5@oracle.com> References: <6B221818-832D-42A6-AEBF-0F15F7C64E6D@gmail.com> <38E4CF2B-A8AC-4B34-8141-9863423F78F5@oracle.com> Message-ID: <069A2518-73D3-42A5-BF61-B870FE17442E@gmail.com> 2nd review, anyone? Or can I go ahead with one? Attila. > On 08 Nov 2016, at 18:07, Hannes Walln?fer wrote: > > +1 > > Thank for fixing this, Attila! > > Hannes > >> Am 08.11.2016 um 14:01 schrieb Attila Szegedi : >> >> Please review JDK-8168373 "don't emit conversions for symbols outside their lexical scope" at for >> >> Few remarks on the implementation: >> - I changed localVariableTypes from using IdentityHashMap to HashMap. The reason for this is that Symbol uses identity semantics for equals/hashCode anyway, and IdentityHashMap.keySet() has a worse implementation of removeAll, which is now used. HashMap has O(min(m, n)) where ?m? and ?n? are sizes of the two collections involved in removeAll, while IdentityHashMap.keySet() is always O(n) to the size of the map. >> >> - in the ?-462,13? patch block: we now clone localVariableTypes at most once, instead of once per symbol that needs to be set in it (that was happening in the setType() call). This is an optimization fix. >> >> - in the ?-1044,19? patch block there?s no longer a need to manually remove exceptionSymbol from the localVariableTypes when following the CF edge from a catch body to the try statement's end label. It becomes part of the general case handling lexically scoped symbols; leaveBlock on catchBody will take care of it. >> >> - the PrintVisitor change now correctly prints ?const? and ?let? nodes. I was using it for debugging and it was confusing that it printed ?var? for ?let?. >> >> Thanks, >> Attila. >> > From hannes.wallnoefer at oracle.com Fri Nov 11 11:25:13 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Fri, 11 Nov 2016 12:25:13 +0100 Subject: RFR: 8168049: Fix Performance of Lexer.isJSWhitespace Message-ID: Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8168049 Webrev: http://cr.openjdk.java.net/~hannesw/8168049/webrev/ This improves parse time by 5 - 10% in most scripts I?ve looked at. Thanks, Hannes From sundararajan.athijegannathan at oracle.com Fri Nov 11 11:43:41 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Fri, 11 Nov 2016 17:13:41 +0530 Subject: Review request for JDK-8168373: don't emit conversions for symbols outside their lexical scope In-Reply-To: <069A2518-73D3-42A5-BF61-B870FE17442E@gmail.com> References: <6B221818-832D-42A6-AEBF-0F15F7C64E6D@gmail.com> <38E4CF2B-A8AC-4B34-8141-9863423F78F5@oracle.com> <069A2518-73D3-42A5-BF61-B870FE17442E@gmail.com> Message-ID: +1 On 11/10/2016 5:50 PM, Attila Szegedi wrote: > 2nd review, anyone? Or can I go ahead with one? > > Attila. > >> On 08 Nov 2016, at 18:07, Hannes Walln?fer wrote: >> >> +1 >> >> Thank for fixing this, Attila! >> >> Hannes >> >>> Am 08.11.2016 um 14:01 schrieb Attila Szegedi : >>> >>> Please review JDK-8168373 "don't emit conversions for symbols outside their lexical scope" at for >>> >>> Few remarks on the implementation: >>> - I changed localVariableTypes from using IdentityHashMap to HashMap. The reason for this is that Symbol uses identity semantics for equals/hashCode anyway, and IdentityHashMap.keySet() has a worse implementation of removeAll, which is now used. HashMap has O(min(m, n)) where ?m? and ?n? are sizes of the two collections involved in removeAll, while IdentityHashMap.keySet() is always O(n) to the size of the map. >>> >>> - in the ?-462,13? patch block: we now clone localVariableTypes at most once, instead of once per symbol that needs to be set in it (that was happening in the setType() call). This is an optimization fix. >>> >>> - in the ?-1044,19? patch block there?s no longer a need to manually remove exceptionSymbol from the localVariableTypes when following the CF edge from a catch body to the try statement's end label. It becomes part of the general case handling lexically scoped symbols; leaveBlock on catchBody will take care of it. >>> >>> - the PrintVisitor change now correctly prints ?const? and ?let? nodes. I was using it for debugging and it was confusing that it printed ?var? for ?let?. >>> >>> Thanks, >>> Attila. >>> From sundararajan.athijegannathan at oracle.com Fri Nov 11 11:44:14 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Fri, 11 Nov 2016 17:14:14 +0530 Subject: RFR: 8168049: Fix Performance of Lexer.isJSWhitespace In-Reply-To: References: Message-ID: <3875a044-187a-ebc9-fe0b-d7368f7fd0e8@oracle.com> +1 On 11/11/2016 4:55 PM, Hannes Walln?fer wrote: > Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8168049 > Webrev: http://cr.openjdk.java.net/~hannesw/8168049/webrev/ > > This improves parse time by 5 - 10% in most scripts I?ve looked at. > > Thanks, > Hannes From szegedia at gmail.com Fri Nov 11 13:14:16 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Fri, 11 Nov 2016 14:14:16 +0100 Subject: RFR: 8168049: Fix Performance of Lexer.isJSWhitespace In-Reply-To: <3875a044-187a-ebc9-fe0b-d7368f7fd0e8@oracle.com> References: <3875a044-187a-ebc9-fe0b-d7368f7fd0e8@oracle.com> Message-ID: <5E100535-0EC4-4D1C-90C6-5C152A6380C0@gmail.com> Nice, +1. > On 11 Nov 2016, at 12:44, Sundararajan Athijegannathan wrote: > > +1 > > > On 11/11/2016 4:55 PM, Hannes Walln?fer wrote: >> Please review: >> >> Bug: https://bugs.openjdk.java.net/browse/JDK-8168049 >> Webrev: http://cr.openjdk.java.net/~hannesw/8168049/webrev/ >> >> This improves parse time by 5 - 10% in most scripts I?ve looked at. >> >> Thanks, >> Hannes > From srinivas.dama at oracle.com Fri Nov 11 18:47:12 2016 From: srinivas.dama at oracle.com (Srinivas Dama) Date: Fri, 11 Nov 2016 10:47:12 -0800 (PST) Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: <3BBF85E3-AE5A-40AA-B7DC-3608ABFE801D@gmail.com> References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> <3BBF85E3-AE5A-40AA-B7DC-3608ABFE801D@gmail.com> Message-ID: Hi, Please review webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.03/ Bug : https://bugs.openjdk.java.net/browse/JDK-8156615 @Attila, Thank you for the comments. Regards, Srinivas -----Original Message----- From: Attila Szegedi [mailto:szegedia at gmail.com] Sent: Thursday, November 10, 2016 5:38 PM To: Nashorn-dev Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode I?m still not happy with this, although we?re getting there :-) - you changed getException() to return Expression, even though Sundar asked you to add a different method. I don?t like the fact that getException() returns Expression, since it can?t be an arbitrary expression; it?s limited to identifier and binding pattern, yet you have unchecked casts on its return value on invocation everywhere now. Maybe keep your ?Expression getException()? change, but add ?IdentNode getExceptionIdentifier() { return (IdentNode)exception; }? and have the callers use that now instead. That way, you encapsulate the cast and don?t force the users of the API to do it everywhere, and it?s easier to track with call hierarchy in the IDEs which callers presume the exception is an identifier. - the JavaDoc for getException() and setException() should be updated to reflect the value can be a binding pattern. Please use the wording ?binding pattern? instead of just ?pattern? in the documentation (including the field declaration) to avoid ambiguity. - Maybe throw an IllegalArgumentException if either the constructor or setException receive something that isn?t either an ident node or a binding pattern. That way, you could enforce an invariant in the class that the types of the expression are only legitimate ones. I?m unsure if it?s easy to recognize the binding pattern or not (e.g. if it just looks like an object/array literal). Attila. > On 10 Nov 2016, at 12:46, Srinivas Dama wrote: > > Hi, > > Please review > Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 > webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.02/ > > Included all changes suggested with some modifications. > > Regards, > Srinivas > > -----Original Message----- > From: Attila Szegedi [mailto:szegedia at gmail.com] > Sent: Tuesday, November 08, 2016 7:40 PM > To: Nashorn-dev > Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in > ES6 mode > > What Sundar said. Additionally: > > + if (exception instanceof IdentNode) { > + this.exception = ((IdentNode) exception == null) ? null : > + ((IdentNode) exception).setIsInitializedHere(); > > First, casting an expression before a null comparison is silly :-). > Second, you don't even need to check for exception == null as "exception instanceof IdentNode" implies that exception != null. So that line should just be: > > + if (exception instanceof IdentNode) { > + this.exception = ((IdentNode) exception).setIsInitializedHere(); > > Attila. > >> On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: >> >> You need to update Parser API implementation to handle catch >> parameter being expression - rather than an IdentNode. >> >> => you need to >> >> * add another getter in CatchNode to expose Expression >> >> * Use it in IRTranslator (of Parser API impl.) to translate catch >> param as expression >> >> * You need to check for expression param in codegen pipeline to throw >> "not yet implemented" error. >> >> -Sundar >> >> On 11/7/2016 9:40 PM, Srinivas Dama wrote: >>> Please review: >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >>> >>> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >>> >>> Regards, >>> Srinivas >> > From sundararajan.athijegannathan at oracle.com Mon Nov 14 03:09:31 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Mon, 14 Nov 2016 08:39:31 +0530 Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> <3BBF85E3-AE5A-40AA-B7DC-3608ABFE801D@gmail.com> Message-ID: <9dc730df-18fa-59b9-9444-941aa4bb3bd6@oracle.com> Looks good PS. LiteralNode in catch should be an array literal, right? i.e., false or 3.14 or "hello" won't be accepted as catch param. Perhaps worth adding a check (where catch param expression is checked). But, no biggie. -Sundar On 11/12/2016 12:17 AM, Srinivas Dama wrote: > Hi, > > Please review > webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.03/ > Bug : https://bugs.openjdk.java.net/browse/JDK-8156615 > > @Attila, Thank you for the comments. > > Regards, > Srinivas > > -----Original Message----- > From: Attila Szegedi [mailto:szegedia at gmail.com] > Sent: Thursday, November 10, 2016 5:38 PM > To: Nashorn-dev > Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode > > I?m still not happy with this, although we?re getting there :-) > > - you changed getException() to return Expression, even though Sundar asked you to add a different method. I don?t like the fact that getException() returns Expression, since it can?t be an arbitrary expression; it?s limited to identifier and binding pattern, yet you have unchecked casts on its return value on invocation everywhere now. Maybe keep your ?Expression getException()? change, but add ?IdentNode getExceptionIdentifier() { return (IdentNode)exception; }? and have the callers use that now instead. That way, you encapsulate the cast and don?t force the users of the API to do it everywhere, and it?s easier to track with call hierarchy in the IDEs which callers presume the exception is an identifier. > > - the JavaDoc for getException() and setException() should be updated to reflect the value can be a binding pattern. Please use the wording ?binding pattern? instead of just ?pattern? in the documentation (including the field declaration) to avoid ambiguity. > > - Maybe throw an IllegalArgumentException if either the constructor or setException receive something that isn?t either an ident node or a binding pattern. That way, you could enforce an invariant in the class that the types of the expression are only legitimate ones. I?m unsure if it?s easy to recognize the binding pattern or not (e.g. if it just looks like an object/array literal). > > Attila. > >> On 10 Nov 2016, at 12:46, Srinivas Dama wrote: >> >> Hi, >> >> Please review >> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >> webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.02/ >> >> Included all changes suggested with some modifications. >> >> Regards, >> Srinivas >> >> -----Original Message----- >> From: Attila Szegedi [mailto:szegedia at gmail.com] >> Sent: Tuesday, November 08, 2016 7:40 PM >> To: Nashorn-dev >> Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in >> ES6 mode >> >> What Sundar said. Additionally: >> >> + if (exception instanceof IdentNode) { >> + this.exception = ((IdentNode) exception == null) ? null : >> + ((IdentNode) exception).setIsInitializedHere(); >> >> First, casting an expression before a null comparison is silly :-). >> Second, you don't even need to check for exception == null as "exception instanceof IdentNode" implies that exception != null. So that line should just be: >> >> + if (exception instanceof IdentNode) { >> + this.exception = ((IdentNode) exception).setIsInitializedHere(); >> >> Attila. >> >>> On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: >>> >>> You need to update Parser API implementation to handle catch >>> parameter being expression - rather than an IdentNode. >>> >>> => you need to >>> >>> * add another getter in CatchNode to expose Expression >>> >>> * Use it in IRTranslator (of Parser API impl.) to translate catch >>> param as expression >>> >>> * You need to check for expression param in codegen pipeline to throw >>> "not yet implemented" error. >>> >>> -Sundar >>> >>> On 11/7/2016 9:40 PM, Srinivas Dama wrote: >>>> Please review: >>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>>> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >>>> >>>> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >>>> >>>> Regards, >>>> Srinivas From hannes.wallnoefer at oracle.com Mon Nov 14 10:17:55 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Mon, 14 Nov 2016 11:17:55 +0100 Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: <9dc730df-18fa-59b9-9444-941aa4bb3bd6@oracle.com> References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> <3BBF85E3-AE5A-40AA-B7DC-3608ABFE801D@gmail.com> <9dc730df-18fa-59b9-9444-941aa4bb3bd6@oracle.com> Message-ID: <64C75043-FFAD-40FE-9402-4619109A006C@oracle.com> +1 Hannes > Am 14.11.2016 um 04:09 schrieb Sundararajan Athijegannathan : > > Looks good > > PS. LiteralNode in catch should be an array literal, right? i.e., false > or 3.14 or "hello" won't be accepted as catch param. Perhaps worth > adding a check (where catch param expression is checked). But, no biggie. > > -Sundar > > > On 11/12/2016 12:17 AM, Srinivas Dama wrote: >> Hi, >> >> Please review >> webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.03/ >> Bug : https://bugs.openjdk.java.net/browse/JDK-8156615 >> >> @Attila, Thank you for the comments. >> >> Regards, >> Srinivas >> >> -----Original Message----- >> From: Attila Szegedi [mailto:szegedia at gmail.com] >> Sent: Thursday, November 10, 2016 5:38 PM >> To: Nashorn-dev >> Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode >> >> I?m still not happy with this, although we?re getting there :-) >> >> - you changed getException() to return Expression, even though Sundar asked you to add a different method. I don?t like the fact that getException() returns Expression, since it can?t be an arbitrary expression; it?s limited to identifier and binding pattern, yet you have unchecked casts on its return value on invocation everywhere now. Maybe keep your ?Expression getException()? change, but add ?IdentNode getExceptionIdentifier() { return (IdentNode)exception; }? and have the callers use that now instead. That way, you encapsulate the cast and don?t force the users of the API to do it everywhere, and it?s easier to track with call hierarchy in the IDEs which callers presume the exception is an identifier. >> >> - the JavaDoc for getException() and setException() should be updated to reflect the value can be a binding pattern. Please use the wording ?binding pattern? instead of just ?pattern? in the documentation (including the field declaration) to avoid ambiguity. >> >> - Maybe throw an IllegalArgumentException if either the constructor or setException receive something that isn?t either an ident node or a binding pattern. That way, you could enforce an invariant in the class that the types of the expression are only legitimate ones. I?m unsure if it?s easy to recognize the binding pattern or not (e.g. if it just looks like an object/array literal). >> >> Attila. >> >>> On 10 Nov 2016, at 12:46, Srinivas Dama wrote: >>> >>> Hi, >>> >>> Please review >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>> webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.02/ >>> >>> Included all changes suggested with some modifications. >>> >>> Regards, >>> Srinivas >>> >>> -----Original Message----- >>> From: Attila Szegedi [mailto:szegedia at gmail.com] >>> Sent: Tuesday, November 08, 2016 7:40 PM >>> To: Nashorn-dev >>> Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in >>> ES6 mode >>> >>> What Sundar said. Additionally: >>> >>> + if (exception instanceof IdentNode) { >>> + this.exception = ((IdentNode) exception == null) ? null : >>> + ((IdentNode) exception).setIsInitializedHere(); >>> >>> First, casting an expression before a null comparison is silly :-). >>> Second, you don't even need to check for exception == null as "exception instanceof IdentNode" implies that exception != null. So that line should just be: >>> >>> + if (exception instanceof IdentNode) { >>> + this.exception = ((IdentNode) exception).setIsInitializedHere(); >>> >>> Attila. >>> >>>> On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: >>>> >>>> You need to update Parser API implementation to handle catch >>>> parameter being expression - rather than an IdentNode. >>>> >>>> => you need to >>>> >>>> * add another getter in CatchNode to expose Expression >>>> >>>> * Use it in IRTranslator (of Parser API impl.) to translate catch >>>> param as expression >>>> >>>> * You need to check for expression param in codegen pipeline to throw >>>> "not yet implemented" error. >>>> >>>> -Sundar >>>> >>>> On 11/7/2016 9:40 PM, Srinivas Dama wrote: >>>>> Please review: >>>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>>>> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >>>>> >>>>> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >>>>> >>>>> Regards, >>>>> Srinivas > From szegedia at gmail.com Mon Nov 14 12:44:13 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Mon, 14 Nov 2016 13:44:13 +0100 Subject: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode In-Reply-To: <9dc730df-18fa-59b9-9444-941aa4bb3bd6@oracle.com> References: <3eed0422-4b87-4257-a404-8c4b93554c19@default> <1690fe35-f79a-1443-fdec-d8c356d3613a@oracle.com> <837A879C-C607-4F49-87B2-B879456CBE88@gmail.com> <3BBF85E3-AE5A-40AA-B7DC-3608ABFE801D@gmail.com> <9dc730df-18fa-59b9-9444-941aa4bb3bd6@oracle.com> Message-ID: I?d say it?s good as it is now (so, +1 from me). See inline comment on array literal? Attila. > On 14 Nov 2016, at 04:09, Sundararajan Athijegannathan wrote: > > Looks good > > PS. LiteralNode in catch should be an array literal, right? i.e., false > or 3.14 or "hello" won't be accepted as catch param. Perhaps worth > adding a check (where catch param expression is checked). But, no biggie. Our literal class hierarchy is weird anyway at the moment (as tracked by >), I think it?d make sense to tackle that sometime and then get this rounded up as a dependent change. It?s really not high on the priority list, though. Attila. > > -Sundar > > > On 11/12/2016 12:17 AM, Srinivas Dama wrote: >> Hi, >> >> Please review >> webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.03/ >> Bug : https://bugs.openjdk.java.net/browse/JDK-8156615 >> >> @Attila, Thank you for the comments. >> >> Regards, >> Srinivas >> >> -----Original Message----- >> From: Attila Szegedi [mailto:szegedia at gmail.com] >> Sent: Thursday, November 10, 2016 5:38 PM >> To: Nashorn-dev >> Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in ES6 mode >> >> I?m still not happy with this, although we?re getting there :-) >> >> - you changed getException() to return Expression, even though Sundar asked you to add a different method. I don?t like the fact that getException() returns Expression, since it can?t be an arbitrary expression; it?s limited to identifier and binding pattern, yet you have unchecked casts on its return value on invocation everywhere now. Maybe keep your ?Expression getException()? change, but add ?IdentNode getExceptionIdentifier() { return (IdentNode)exception; }? and have the callers use that now instead. That way, you encapsulate the cast and don?t force the users of the API to do it everywhere, and it?s easier to track with call hierarchy in the IDEs which callers presume the exception is an identifier. >> >> - the JavaDoc for getException() and setException() should be updated to reflect the value can be a binding pattern. Please use the wording ?binding pattern? instead of just ?pattern? in the documentation (including the field declaration) to avoid ambiguity. >> >> - Maybe throw an IllegalArgumentException if either the constructor or setException receive something that isn?t either an ident node or a binding pattern. That way, you could enforce an invariant in the class that the types of the expression are only legitimate ones. I?m unsure if it?s easy to recognize the binding pattern or not (e.g. if it just looks like an object/array literal). >> >> Attila. >> >>> On 10 Nov 2016, at 12:46, Srinivas Dama wrote: >>> >>> Hi, >>> >>> Please review >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>> webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.02/ >>> >>> Included all changes suggested with some modifications. >>> >>> Regards, >>> Srinivas >>> >>> -----Original Message----- >>> From: Attila Szegedi [mailto:szegedia at gmail.com] >>> Sent: Tuesday, November 08, 2016 7:40 PM >>> To: Nashorn-dev >>> Subject: Re: RFR: 8156615:Catch parameter can be a BindingPattern in >>> ES6 mode >>> >>> What Sundar said. Additionally: >>> >>> + if (exception instanceof IdentNode) { >>> + this.exception = ((IdentNode) exception == null) ? null : >>> + ((IdentNode) exception).setIsInitializedHere(); >>> >>> First, casting an expression before a null comparison is silly :-). >>> Second, you don't even need to check for exception == null as "exception instanceof IdentNode" implies that exception != null. So that line should just be: >>> >>> + if (exception instanceof IdentNode) { >>> + this.exception = ((IdentNode) exception).setIsInitializedHere(); >>> >>> Attila. >>> >>>> On 08 Nov 2016, at 04:45, Sundararajan Athijegannathan wrote: >>>> >>>> You need to update Parser API implementation to handle catch >>>> parameter being expression - rather than an IdentNode. >>>> >>>> => you need to >>>> >>>> * add another getter in CatchNode to expose Expression >>>> >>>> * Use it in IRTranslator (of Parser API impl.) to translate catch >>>> param as expression >>>> >>>> * You need to check for expression param in codegen pipeline to throw >>>> "not yet implemented" error. >>>> >>>> -Sundar >>>> >>>> On 11/7/2016 9:40 PM, Srinivas Dama wrote: >>>>> Please review: >>>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8156615 >>>>> Webrev: http://cr.openjdk.java.net/~sdama/8156615/webrev.00/ >>>>> >>>>> Please note that, this contains only parsing support for catch parameter as BindingPattern or BindingIdentifier. >>>>> >>>>> Regards, >>>>> Srinivas > From hannes.wallnoefer at oracle.com Wed Nov 16 15:13:41 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Wed, 16 Nov 2016 16:13:41 +0100 Subject: RFR: 8162839: JavaAdapters do not work with ScriptObjectMirror objects Message-ID: Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8162839 Webrev: http://cr.openjdk.java.net/~hannesw/8162839/webrev.00/ This makes JavaAdapters work with ScriptObjectMirrors in addition to ScriptObjects and ScriptFunctions. A few notes: - NashornLinker.getSamTypeConverter now gets the constructor with Object.class extra parameter if sourceType is more generic than ScriptFunction.class. However, this really is an OverloadedMethod constructor, so the ScriptFunction constructor will be called if the argument happens to be a ScriptFunction. - Unfortunately the only way to get at the ScriptObject and Global of a ScriptObjectMirror is to use reflection, making the fields accessible. Since ScriptObjectMirror is in a package that?s exported to the world we can?t add public getters. Field accessors are created lazily and cached in JavaAdapterServices.MirrorFieldHolder. - When writing the test for this I noticed that some of our java tests are not run in ?ant run?. I added the missing test packages to build.xml. - This contains cleanup for indentation in JavaAdapterByteCodeGenerator.java. That class had wrong indentation in various places. Thanks, Hannes From sundararajan.athijegannathan at oracle.com Thu Nov 17 11:11:16 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Thu, 17 Nov 2016 16:41:16 +0530 Subject: RFR: 8162839: JavaAdapters do not work with ScriptObjectMirror objects In-Reply-To: References: Message-ID: Looks good! PS. Would be nice if we have with security manager test (perhaps .js test?) that exercises ScriptObjectMirror to adapter conversion. But, no biggie.. -Sundar On 11/16/2016 8:43 PM, Hannes Walln?fer wrote: > Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8162839 > Webrev: http://cr.openjdk.java.net/~hannesw/8162839/webrev.00/ > > This makes JavaAdapters work with ScriptObjectMirrors in addition to ScriptObjects and ScriptFunctions. > > A few notes: > - NashornLinker.getSamTypeConverter now gets the constructor with Object.class extra parameter if sourceType is more generic than ScriptFunction.class. However, this really is an OverloadedMethod constructor, so the ScriptFunction constructor will be called if the argument happens to be a ScriptFunction. > - Unfortunately the only way to get at the ScriptObject and Global of a ScriptObjectMirror is to use reflection, making the fields accessible. Since ScriptObjectMirror is in a package that?s exported to the world we can?t add public getters. Field accessors are created lazily and cached in JavaAdapterServices.MirrorFieldHolder. > - When writing the test for this I noticed that some of our java tests are not run in ?ant run?. I added the missing test packages to build.xml. > - This contains cleanup for indentation in JavaAdapterByteCodeGenerator.java. That class had wrong indentation in various places. > > Thanks, > Hannes From james.laskey at oracle.com Thu Nov 17 11:53:33 2016 From: james.laskey at oracle.com (Jim Laskey (Oracle)) Date: Thu, 17 Nov 2016 07:53:33 -0400 Subject: RFR: 8162839: JavaAdapters do not work with ScriptObjectMirror objects In-Reply-To: References: Message-ID: +1 > On Nov 17, 2016, at 7:11 AM, Sundararajan Athijegannathan wrote: > > Looks good! > > PS. Would be nice if we have with security manager test (perhaps .js > test?) that exercises ScriptObjectMirror to adapter conversion. But, no > biggie.. > > -Sundar > > > On 11/16/2016 8:43 PM, Hannes Walln?fer wrote: >> Please review: >> >> Bug: https://bugs.openjdk.java.net/browse/JDK-8162839 >> Webrev: http://cr.openjdk.java.net/~hannesw/8162839/webrev.00/ >> >> This makes JavaAdapters work with ScriptObjectMirrors in addition to ScriptObjects and ScriptFunctions. >> >> A few notes: >> - NashornLinker.getSamTypeConverter now gets the constructor with Object.class extra parameter if sourceType is more generic than ScriptFunction.class. However, this really is an OverloadedMethod constructor, so the ScriptFunction constructor will be called if the argument happens to be a ScriptFunction. >> - Unfortunately the only way to get at the ScriptObject and Global of a ScriptObjectMirror is to use reflection, making the fields accessible. Since ScriptObjectMirror is in a package that?s exported to the world we can?t add public getters. Field accessors are created lazily and cached in JavaAdapterServices.MirrorFieldHolder. >> - When writing the test for this I noticed that some of our java tests are not run in ?ant run?. I added the missing test packages to build.xml. >> - This contains cleanup for indentation in JavaAdapterByteCodeGenerator.java. That class had wrong indentation in various places. >> >> Thanks, >> Hannes > From ravikirans1271 at gmail.com Thu Nov 17 14:13:09 2016 From: ravikirans1271 at gmail.com (RAVI KIRAN) Date: Thu, 17 Nov 2016 19:43:09 +0530 Subject: Need Help on Building Nashorn Equivalent code for Below Programme(From Rhino) Message-ID: Hi Team, I am new to Java Scripting and now i need to Migrate all Rhino Script java service to Nashorn supported code. I need help from experts who can share the equivalent functions/methods/classes in Nashorn which Rhino was using earlier from below code snippet. Request you all to help 1) Equivalent function for Context(Rhino) in Nashorn. I believe it will be SimpleScriptContext. 2) Context.enter() replacement in Nashorn ? 3) how to set OptimizationLevel in Nashorn. In Rhino we used cx.setOptimizationLevel(9); 4) How to create and use shared scope as a prototype when creating the local .scope. Rhino way is Scriptable scope = cx.newObject(sharedScope); 5) Exit from the context in Nashorn? Rhino way is Context.exit(); 6) How to extend ContextFactory ? Rhino way is private static class MyFactory extends ContextFactory 7) How to Initialize the global scope to be reused by all service threads? Changing Below code in Nashorn by any Expert is really Appreciated. ----------------------------------------------------------------------------------------------------- package se.stubs.common.ruleEngine; import com.wm.data.*; import com.wm.util.Values; import com.wm.app.b2b.server.Service; import com.wm.app.b2b.server.ServiceException; import java.util.*; import com.wm.app.b2b.server.*; import com.wm.lang.ns.*; import org.mozilla.javascript.*; public final class executeJavaScript_SVC { /** * The primary method for the Java service * * @param pipeline * The IData pipeline * @throws ServiceException */ public static final void executeJavaScript(IData pipeline) throws ServiceException { // pipeline IDataCursor pipelineCursor = pipeline.getCursor(); // // Declare input variables // String script = IDataUtil.getString(pipelineCursor, "script"); String function = IDataUtil.getString(pipelineCursor, "functionToCall"); // Creates and enters a Context. The Context stores information // about the execution environment of a script. Context cx = Context.enter(); cx.setOptimizationLevel(9); try { //use the shared scope as a prototype when creating the local "scope" Scriptable scope = cx.newObject(sharedScope); scope.setPrototype(sharedScope); scope.setParentScope(null); // We want "scope" to be a new top-level // Evaluate the string received try{ cx.evaluateString(scope, script, "", 1, null); } catch (Exception e) { throw new ServiceException( "Error evaluating script, original exception message: " + e.getMessage()); } //call given function Object result=null; try { Object fObj = scope.get(function, scope); if (!(fObj instanceof Function)) { throw new ServiceException(function+" is undefined or not a function."); } else { Function f = (Function)fObj; result = f.call(cx, scope, scope, (Object[]) null); } } catch (Exception e) { throw new ServiceException("Error executing function (" + function + "), original exception message: " + e.getMessage()); } // Null return means no match => error. if (result == null) { throw new ServiceException("Function returned null: " + function); } //Although an array could be returned represented as a string // the stubs limit the results to these types. if (!(result instanceof String) && !(result instanceof Double) && !(result instanceof Integer)) { throw new ServiceException("Function returned nor string nor double: " + function); } IDataUtil.put( pipelineCursor, "result", Context.toString(result) ); } catch (Exception ex) { throw new ServiceException(ex); } finally { // Exit from the context. Context.exit(); } pipelineCursor.destroy(); } // --- <> --- //the shared scope variable private static ScriptableObject sharedScope=null; private static class MyFactory extends ContextFactory { @Override protected boolean hasFeature(Context cx, int featureIndex) { if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) { return true; } return super.hasFeature(cx, featureIndex); } } //Initialize the global scope to be reused by all service threads. //the scope is sealed, so any changes to its objects throw an exception. //each thread will have it own set of variables that do not colide. static { ContextFactory.initGlobal(new MyFactory()); // avoid init all the standard objects since this is a costly operation Context cx = Context.enter(); try { sharedScope = cx.initStandardObjects(null, true); sharedScope.sealObject(); } finally { Context.exit(); } } private static String getFirstPipelineValue(IData doc, String key) { IDataCursor idc = doc.getCursor(); String result = ""; while (idc.next() && result.equals("")) { Object placeholder = idc.getValue(); if (placeholder instanceof IData) { result = getFirstPipelineValue((IData)placeholder, key); } if (placeholder instanceof IData[]) { result = getFirstPipelineValue(((IData[])placeholder)[0], key); if ((result.equals("") || result.equals("SUCCESS")) && idc.getKey().equals("header:Status")) { IDataUtil.remove(idc, idc.getKey()); } } if (idc.getKey().equals(key)) { if (placeholder instanceof String[]) { result = ((String[])placeholder)[0]; } if (placeholder instanceof String) { result = (String) placeholder; } } } idc.destroy(); return result; } // --- <> --- /** * The service implementations given below are read-only and show only the * method definitions and not the complete implementation. */ public static final void removeSuccessHeader(IData pipeline) throws ServiceException { } final static executeJavaScript_SVC _instance = new executeJavaScript_SVC(); static executeJavaScript_SVC _newInstance() { return new executeJavaScript_SVC(); } static executeJavaScript_SVC _cast(Object o) { return (executeJavaScript_SVC)o; } } From szegedia at gmail.com Thu Nov 17 14:44:22 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Thu, 17 Nov 2016 15:44:22 +0100 Subject: RFR: 8162839: JavaAdapters do not work with ScriptObjectMirror objects In-Reply-To: References: Message-ID: <178A2ED8-CEED-41CC-9457-E7074A69CC75@gmail.com> +1 > On 16 Nov 2016, at 16:13, Hannes Walln?fer wrote: > > Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8162839 > Webrev: http://cr.openjdk.java.net/~hannesw/8162839/webrev.00/ > > This makes JavaAdapters work with ScriptObjectMirrors in addition to ScriptObjects and ScriptFunctions. > > A few notes: > - NashornLinker.getSamTypeConverter now gets the constructor with Object.class extra parameter if sourceType is more generic than ScriptFunction.class. However, this really is an OverloadedMethod constructor, so the ScriptFunction constructor will be called if the argument happens to be a ScriptFunction. > - Unfortunately the only way to get at the ScriptObject and Global of a ScriptObjectMirror is to use reflection, making the fields accessible. Since ScriptObjectMirror is in a package that?s exported to the world we can?t add public getters. Field accessors are created lazily and cached in JavaAdapterServices.MirrorFieldHolder. > - When writing the test for this I noticed that some of our java tests are not run in ?ant run?. I added the missing test packages to build.xml. > - This contains cleanup for indentation in JavaAdapterByteCodeGenerator.java. That class had wrong indentation in various places. > > Thanks, > Hannes From sundararajan.athijegannathan at oracle.com Thu Nov 17 15:07:56 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Thu, 17 Nov 2016 20:37:56 +0530 Subject: Need Help on Building Nashorn Equivalent code for Below Programme(From Rhino) In-Reply-To: References: Message-ID: Hi, The Rhino APIs you mention are all Rhino specific. There is no one-to-one correspondence between Rhino internals and Nashorn internals. If you had used javax.script (JSR-223) API to access Rhino from your Java code, it is lot simpler to migrate to Nashorn. Nashorn supports Nashorn specific API apart from javax.script (JSR-223): https://docs.oracle.com/javase/8/docs/jdk/api/nashorn/index.html?jdk/nashorn/api/scripting/ScriptObjectMirror.html We've a migration guide that deals with JS language & API differences between Rhino and Nashorn: https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide HTH, -Sundar On 11/17/2016 7:43 PM, RAVI KIRAN wrote: > Hi Team, > > I am new to Java Scripting and now i need to Migrate all Rhino Script java > service to Nashorn supported code. > I need help from experts who can share the equivalent > functions/methods/classes in Nashorn which Rhino was using earlier from > below code snippet. Request you all to help > > 1) Equivalent function for Context(Rhino) in Nashorn. I believe it will > be SimpleScriptContext. > 2) Context.enter() replacement in Nashorn ? > 3) how to set OptimizationLevel in Nashorn. In Rhino we used > cx.setOptimizationLevel(9); > 4) How to create and use shared scope as a prototype when creating the > local .scope. Rhino way is Scriptable scope = cx.newObject(sharedScope); > 5) Exit from the context in Nashorn? Rhino way is Context.exit(); > 6) How to extend ContextFactory ? Rhino way is private static class > MyFactory extends ContextFactory > 7) How to Initialize the global scope to be reused by all service threads? > > Changing Below code in Nashorn by any Expert is really Appreciated. > ----------------------------------------------------------------------------------------------------- > package se.stubs.common.ruleEngine; > > import com.wm.data.*; > import com.wm.util.Values; > import com.wm.app.b2b.server.Service; > import com.wm.app.b2b.server.ServiceException; > import java.util.*; > import com.wm.app.b2b.server.*; > import com.wm.lang.ns.*; > import org.mozilla.javascript.*; > > public final class executeJavaScript_SVC > > { > > /** > * The primary method for the Java service > * > * @param pipeline > * The IData pipeline > * @throws ServiceException > */ > public static final void executeJavaScript(IData pipeline) > throws ServiceException { > // pipeline > IDataCursor pipelineCursor = pipeline.getCursor(); > // > // Declare input variables > // > String script = IDataUtil.getString(pipelineCursor, "script"); > String function = IDataUtil.getString(pipelineCursor, "functionToCall"); > // Creates and enters a Context. The Context stores information > // about the execution environment of a script. > Context cx = Context.enter(); > cx.setOptimizationLevel(9); > try { > //use the shared scope as a prototype when creating the local > "scope" > Scriptable scope = cx.newObject(sharedScope); > scope.setPrototype(sharedScope); > scope.setParentScope(null); // We want "scope" to be a new > top-level > // Evaluate the string received > try{ > cx.evaluateString(scope, script, "", 1, null); > } catch (Exception e) { > throw new ServiceException( > "Error evaluating script, original exception message: " > + e.getMessage()); } > //call given function > Object result=null; > > try { > Object fObj = scope.get(function, scope); > if (!(fObj instanceof Function)) { > throw new ServiceException(function+" is undefined or not > a function."); > } else { > Function f = (Function)fObj; > result = f.call(cx, scope, scope, (Object[]) null); > } > } catch (Exception e) { > throw new ServiceException("Error executing function (" + function > + "), original exception message: " + e.getMessage()); } > // Null return means no match => error. > if (result == null) { > throw new ServiceException("Function returned null: " + function); > } > //Although an array could be returned represented as a string > // the stubs limit the results to these types. > if (!(result instanceof String) && !(result instanceof Double) && > !(result instanceof Integer)) { > throw new ServiceException("Function returned nor string nor > double: " + function); > } > IDataUtil.put( pipelineCursor, "result", > Context.toString(result) ); > } > catch (Exception ex) { > throw new ServiceException(ex); > } finally { > // Exit from the context. > Context.exit(); > } > pipelineCursor.destroy(); > } > // --- <> --- > //the shared scope variable > private static ScriptableObject sharedScope=null; > private static class MyFactory extends ContextFactory > { > @Override > protected boolean hasFeature(Context cx, int featureIndex) > { > if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) { > return true; > } > return super.hasFeature(cx, featureIndex); > } > } > //Initialize the global scope to be reused by all service threads. > //the scope is sealed, so any changes to its objects throw an exception. > //each thread will have it own set of variables that do not colide. > static { > ContextFactory.initGlobal(new MyFactory()); > // avoid init all the standard objects since this is a costly > operation > Context cx = Context.enter(); > try { > sharedScope = cx.initStandardObjects(null, true); > sharedScope.sealObject(); > } finally { > Context.exit(); > } > } > private static String getFirstPipelineValue(IData doc, String key) { > IDataCursor idc = doc.getCursor(); > String result = ""; > while (idc.next() && result.equals("")) { > Object placeholder = idc.getValue(); > if (placeholder instanceof IData) { > result = getFirstPipelineValue((IData)placeholder, key); > } > if (placeholder instanceof IData[]) { > result = getFirstPipelineValue(((IData[])placeholder)[0], key); > if ((result.equals("") || result.equals("SUCCESS")) && > idc.getKey().equals("header:Status")) { > IDataUtil.remove(idc, idc.getKey()); > } > } > if (idc.getKey().equals(key)) { > if (placeholder instanceof String[]) { > result = ((String[])placeholder)[0]; > } > if (placeholder instanceof String) { > result = (String) placeholder; > } > } > } > idc.destroy(); > return result; > } > // --- <> --- > > /** > * The service implementations given below are read-only and show only the > * method definitions and not the complete implementation. > */ > public static final void removeSuccessHeader(IData pipeline) > throws ServiceException { > } > > final static executeJavaScript_SVC _instance = new executeJavaScript_SVC(); > > static executeJavaScript_SVC _newInstance() { return new > executeJavaScript_SVC(); } > > static executeJavaScript_SVC _cast(Object o) { return > (executeJavaScript_SVC)o; } > > } From hannes.wallnoefer at oracle.com Thu Nov 17 15:50:29 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Thu, 17 Nov 2016 16:50:29 +0100 Subject: RFR: 8162839: JavaAdapters do not work with ScriptObjectMirror objects In-Reply-To: References: Message-ID: <61E36158-8BC5-4184-8A3E-FAA4DA0B845F@oracle.com> Thanks for the reviews. I already pushed the change, but I think the demand for a test that runs under SecurityManager makes sense, given that the change contains privileged code to access the ScriptObjectMirror fields. I field a new bug to add a simple test running with security on. Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8169886 Webrev: http://cr.openjdk.java.net/~hannesw/8169886/webrev/ Thanks, Hannes > Am 17.11.2016 um 12:11 schrieb Sundararajan Athijegannathan : > > Looks good! > > PS. Would be nice if we have with security manager test (perhaps .js > test?) that exercises ScriptObjectMirror to adapter conversion. But, no > biggie.. > > -Sundar > > > On 11/16/2016 8:43 PM, Hannes Walln?fer wrote: >> Please review: >> >> Bug: https://bugs.openjdk.java.net/browse/JDK-8162839 >> Webrev: http://cr.openjdk.java.net/~hannesw/8162839/webrev.00/ >> >> This makes JavaAdapters work with ScriptObjectMirrors in addition to ScriptObjects and ScriptFunctions. >> >> A few notes: >> - NashornLinker.getSamTypeConverter now gets the constructor with Object.class extra parameter if sourceType is more generic than ScriptFunction.class. However, this really is an OverloadedMethod constructor, so the ScriptFunction constructor will be called if the argument happens to be a ScriptFunction. >> - Unfortunately the only way to get at the ScriptObject and Global of a ScriptObjectMirror is to use reflection, making the fields accessible. Since ScriptObjectMirror is in a package that?s exported to the world we can?t add public getters. Field accessors are created lazily and cached in JavaAdapterServices.MirrorFieldHolder. >> - When writing the test for this I noticed that some of our java tests are not run in ?ant run?. I added the missing test packages to build.xml. >> - This contains cleanup for indentation in JavaAdapterByteCodeGenerator.java. That class had wrong indentation in various places. >> >> Thanks, >> Hannes > From sundararajan.athijegannathan at oracle.com Fri Nov 18 12:04:35 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Fri, 18 Nov 2016 17:34:35 +0530 Subject: RFR: 8162839: JavaAdapters do not work with ScriptObjectMirror objects In-Reply-To: <61E36158-8BC5-4184-8A3E-FAA4DA0B845F@oracle.com> References: <61E36158-8BC5-4184-8A3E-FAA4DA0B845F@oracle.com> Message-ID: +1 On 11/17/2016 9:20 PM, Hannes Walln?fer wrote: > Thanks for the reviews. > > I already pushed the change, but I think the demand for a test that runs under SecurityManager makes sense, given that the change contains privileged code to access the ScriptObjectMirror fields. > > I field a new bug to add a simple test running with security on. Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8169886 > Webrev: http://cr.openjdk.java.net/~hannesw/8169886/webrev/ > > Thanks, > Hannes > > >> Am 17.11.2016 um 12:11 schrieb Sundararajan Athijegannathan : >> >> Looks good! >> >> PS. Would be nice if we have with security manager test (perhaps .js >> test?) that exercises ScriptObjectMirror to adapter conversion. But, no >> biggie.. >> >> -Sundar >> >> >> On 11/16/2016 8:43 PM, Hannes Walln?fer wrote: >>> Please review: >>> >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8162839 >>> Webrev: http://cr.openjdk.java.net/~hannesw/8162839/webrev.00/ >>> >>> This makes JavaAdapters work with ScriptObjectMirrors in addition to ScriptObjects and ScriptFunctions. >>> >>> A few notes: >>> - NashornLinker.getSamTypeConverter now gets the constructor with Object.class extra parameter if sourceType is more generic than ScriptFunction.class. However, this really is an OverloadedMethod constructor, so the ScriptFunction constructor will be called if the argument happens to be a ScriptFunction. >>> - Unfortunately the only way to get at the ScriptObject and Global of a ScriptObjectMirror is to use reflection, making the fields accessible. Since ScriptObjectMirror is in a package that?s exported to the world we can?t add public getters. Field accessors are created lazily and cached in JavaAdapterServices.MirrorFieldHolder. >>> - When writing the test for this I noticed that some of our java tests are not run in ?ant run?. I added the missing test packages to build.xml. >>> - This contains cleanup for indentation in JavaAdapterByteCodeGenerator.java. That class had wrong indentation in various places. >>> >>> Thanks, >>> Hannes From tonyzakula at gmail.com Fri Nov 18 13:53:19 2016 From: tonyzakula at gmail.com (Tony Zakula) Date: Fri, 18 Nov 2016 06:53:19 -0700 Subject: Converting POJOs to ScriptObjects? Message-ID: Hey All, Seems there should be a way to do this that maybe I am missing? To pass JS objects to Java, we use: var data = {"myVar":"hello"}; Java.asJSONCompatible(data); We also want to pass a POJO created on the Java side back to JS and convert it to a ScriptObject so it acts like a standard JS object. We have a Java Object we built that is in global scope that the acts like a bridge to call back to Java. So the code works something like this right now: var order = JSON.parse(bridge.call("getOrder")); On the Java side: Order order = getOrderFromDB(); return convertObjectToJSON(order); This works fine, and the performance is decent, but it would seem that we could reduce objects and overhead if we could convert the Order object to a ScriptObject. Maybe if we even created an empty ScriptObject and copied in the properties. Am I missing an easy way to do this all on the Java side? I have thought about calling back to the JS from Java to create the JS object and then populate it from Java? Any input is appreciated. Nashorn is awesome. Thanks! Tony From florian.beese at gmail.com Fri Nov 18 09:36:36 2016 From: florian.beese at gmail.com (Florian Beese) Date: Fri, 18 Nov 2016 10:36:36 +0100 Subject: Nashorn JSObject with JDK 9 Message-ID: Hi together, I got a question relating the usage of JSObject Interface and AbstractJSObject class with JDK 9. I hope you can tell me where to look or whom to talk to. My problem is, that when I want to access ScriptRuntime.UNDEFINED to be abled to return "undefined" for members of my object, that do not exist, I cannot access that class attribute as the ScriptRuntime class is not exported. How shall I then tell the engine, that a member does not exist? (null is not an option as this is not compatible to normal JS behavior). See the following code example, which runs with JDK 8, but not with JDK 9 anymore. Thanks in advance and best regards Florian ============ Code Example ============== package com.your.test.package; import static org.junit.Assert.assertEquals; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; import javax.script.Compilable; import javax.script.CompiledScript; import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; import org.junit.Test; import jdk.nashorn.api.scripting.AbstractJSObject; import jdk.nashorn.api.scripting.JSObject; import jdk.nashorn.internal.runtime.ScriptRuntime; /* see the JSMapWrapper.getMember() method to understand the problem */ public class NashornWrapMapTest { @SuppressWarnings("restriction") private class JSMapWrapper extends AbstractJSObject implements JSObject { protected Map wrappedMap = null; public JSMapWrapper(Map mapToWrap) { wrappedMap = mapToWrap; } public Map getMap() { return wrappedMap; } @Override public Object call(Object thiz, Object... args) { return super.call(thiz, args); } @Override public Object newObject(Object... args) { return super.newObject(args); } @Override public Object eval(String s) { return super.eval(s); } @Override public Object getMember(String name) { if (!wrappedMap.containsKey(name)) { /* HERE is the problem with JDK as ScriptRuntime is not Exported */ return ScriptRuntime.UNDEFINED; } return wrappedMap.get(name); } @Override public Object getSlot(int index) { return null; } @Override public boolean hasMember(String name) { return wrappedMap.containsKey(name); } @Override public boolean hasSlot(int slot) { return false; } @Override public void removeMember(String name) { wrappedMap.remove(name); } @Override public void setMember(String name, Object value) { wrappedMap.put(name, value); } @Override public void setSlot(int index, Object value) { super.setSlot(index, value); } @Override public Set keySet() { return wrappedMap.keySet(); } @Override public Collection values() { return wrappedMap.values(); } @Override public boolean isInstance(Object instance) { return super.isInstance(instance); } @Override public boolean isInstanceOf(Object clazz) { return super.isInstanceOf(clazz); } @Override public String getClassName() { return super.getClassName(); } @Override public boolean isFunction() { return false; } @Override public boolean isStrictFunction() { return false; } @Override public double toNumber() { return super.toNumber(); } @Override public boolean isArray() { return false; } @Override public String toString() { String s = "Object(Map) : {"; boolean isFirst = true; for (Map.Entry entry : wrappedMap.entrySet()) { if (!isFirst) { s += ", "; isFirst = false; } s += entry.getKey() + ": " + entry.getValue().toString(); } s += "}"; return s; } } @Test public void testUndefinedValue() throws ScriptException, NoSuchMethodException { final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); final Compilable compilable = (Compilable) engine; final Invocable invocable = (Invocable) engine; final String okReturn = "OK: did not contain testKey2"; final String scriptFunction = "function testMap(map) { " + "if (typeof map.testKey2 === 'undefined') { return '" + okReturn + "'; } return 'ERROR: should not happen: ' + map.testKey; };"; final CompiledScript compiled = compilable.compile(scriptFunction); compiled.eval(); Map map = new HashMap(); map.put("testKey", "testVal"); //change the key to testKey2 to see the test failing JSMapWrapper wrapper = new JSMapWrapper(map); String ret = (String) invocable.invokeFunction("testMap", wrapper); assertEquals(okReturn, ret); } } From artfiedler at gmail.com Fri Nov 18 20:58:35 2016 From: artfiedler at gmail.com (Art Fiedler) Date: Fri, 18 Nov 2016 14:58:35 -0600 Subject: What about JSObject? Object.prototype.hasOwnProperty.call(obj, prop) Message-ID: 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 From ravikirans1271 at gmail.com Mon Nov 21 10:46:45 2016 From: ravikirans1271 at gmail.com (RAVI KIRAN) Date: Mon, 21 Nov 2016 16:16:45 +0530 Subject: Need Help on Building Nashorn Equivalent code for Below Programme(From Rhino) In-Reply-To: References: Message-ID: Hi Sundar, Thank you for responding. Unfortunately our existing Rhino Java code doesn't use javax.script (JSR-223) API . Only Rhino specific code is used which uses org.mozilla.javascript.* Could you suggest the best way to Migrate Rhino to Nashorn. I understood from our earlier conversation below could be possibility 1) Extend Existing Rhino Specif java code to use javax.script (JSR-223) API 2) Next Migrate Java Code from Point 1 to get compatible Use javax.script (JSR-223) API in Nashorn The other way i found is to Load Nashorn Compatibility scripts that Rhino/Mozilla extensions support. But as i am aware that Rhino extensions may get deprecated in future for any reason then my code will be need to re modified. Main challenge is i am unable to find one to one correspondence between Rhino and Nashorn Internals. Ex: 1) How to create Shared scope in Nashorn ? 2) How to extend my class using contextfactory ? etc... Regards Ravi kiran On Thu, Nov 17, 2016 at 8:37 PM, Sundararajan Athijegannathan < sundararajan.athijegannathan at oracle.com> wrote: > Hi, > > The Rhino APIs you mention are all Rhino specific. There is no > one-to-one correspondence between Rhino internals and Nashorn > internals. If you had used javax.script (JSR-223) API to access Rhino > from your Java code, it is lot simpler to migrate to Nashorn. Nashorn > supports Nashorn specific API apart from javax.script (JSR-223): > > > https://docs.oracle.com/javase/8/docs/jdk/api/nashorn/ > index.html?jdk/nashorn/api/scripting/ScriptObjectMirror.html > > We've a migration guide that deals with JS language & API differences > between Rhino and Nashorn: > > https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide > > HTH, > > -Sundar > > > On 11/17/2016 7:43 PM, RAVI KIRAN wrote: > > Hi Team, > > > > I am new to Java Scripting and now i need to Migrate all Rhino Script > java > > service to Nashorn supported code. > > I need help from experts who can share the equivalent > > functions/methods/classes in Nashorn which Rhino was using earlier from > > below code snippet. Request you all to help > > > > 1) Equivalent function for Context(Rhino) in Nashorn. I believe it will > > be SimpleScriptContext. > > 2) Context.enter() replacement in Nashorn ? > > 3) how to set OptimizationLevel in Nashorn. In Rhino we used > > cx.setOptimizationLevel(9); > > 4) How to create and use shared scope as a prototype when creating the > > local .scope. Rhino way is Scriptable scope = cx.newObject(sharedScope); > > 5) Exit from the context in Nashorn? Rhino way is Context.exit(); > > 6) How to extend ContextFactory ? Rhino way is private static class > > MyFactory extends ContextFactory > > 7) How to Initialize the global scope to be reused by all service > threads? > > > > Changing Below code in Nashorn by any Expert is really Appreciated. > > ------------------------------------------------------------ > ----------------------------------------- > > package se.stubs.common.ruleEngine; > > > > import com.wm.data.*; > > import com.wm.util.Values; > > import com.wm.app.b2b.server.Service; > > import com.wm.app.b2b.server.ServiceException; > > import java.util.*; > > import com.wm.app.b2b.server.*; > > import com.wm.lang.ns.*; > > import org.mozilla.javascript.*; > > > > public final class executeJavaScript_SVC > > > > { > > > > /** > > * The primary method for the Java service > > * > > * @param pipeline > > * The IData pipeline > > * @throws ServiceException > > */ > > public static final void executeJavaScript(IData pipeline) > > throws ServiceException { > > // pipeline > > IDataCursor pipelineCursor = pipeline.getCursor(); > > // > > // Declare input variables > > // > > String script = IDataUtil.getString(pipelineCursor, "script"); > > String function = IDataUtil.getString(pipelineCursor, "functionToCall"); > > // Creates and enters a Context. The Context stores information > > // about the execution environment of a script. > > Context cx = Context.enter(); > > cx.setOptimizationLevel(9); > > try { > > //use the shared scope as a prototype when creating the local > > "scope" > > Scriptable scope = cx.newObject(sharedScope); > > scope.setPrototype(sharedScope); > > scope.setParentScope(null); // We want "scope" to be a new > > top-level > > // Evaluate the string received > > try{ > > cx.evaluateString(scope, script, "", 1, null); > > } catch (Exception e) { > > throw new ServiceException( > > "Error evaluating script, original exception message: " > > + e.getMessage()); } > > //call given function > > Object result=null; > > > > try { > > Object fObj = scope.get(function, scope); > > if (!(fObj instanceof Function)) { > > throw new ServiceException(function+" is undefined or > not > > a function."); > > } else { > > Function f = (Function)fObj; > > result = f.call(cx, scope, scope, (Object[]) null); > > } > > } catch (Exception e) { > > throw new ServiceException("Error executing function (" + function > > + "), original exception message: " + e.getMessage()); } > > // Null return means no match => error. > > if (result == null) { > > throw new ServiceException("Function returned null: " + function); > > } > > //Although an array could be returned represented as a string > > // the stubs limit the results to these types. > > if (!(result instanceof String) && !(result instanceof Double) && > > !(result instanceof Integer)) { > > throw new ServiceException("Function returned nor string nor > > double: " + function); > > } > > IDataUtil.put( pipelineCursor, "result", > > Context.toString(result) ); > > } > > catch (Exception ex) { > > throw new ServiceException(ex); > > } finally { > > // Exit from the context. > > Context.exit(); > > } > > pipelineCursor.destroy(); > > } > > // --- <> --- > > //the shared scope variable > > private static ScriptableObject sharedScope=null; > > private static class MyFactory extends ContextFactory > > { > > @Override > > protected boolean hasFeature(Context cx, int featureIndex) > > { > > if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) { > > return true; > > } > > return super.hasFeature(cx, featureIndex); > > } > > } > > //Initialize the global scope to be reused by all service threads. > > //the scope is sealed, so any changes to its objects throw an exception. > > //each thread will have it own set of variables that do not colide. > > static { > > ContextFactory.initGlobal(new MyFactory()); > > // avoid init all the standard objects since this is a costly > > operation > > Context cx = Context.enter(); > > try { > > sharedScope = cx.initStandardObjects(null, true); > > sharedScope.sealObject(); > > } finally { > > Context.exit(); > > } > > } > > private static String getFirstPipelineValue(IData doc, String key) { > > IDataCursor idc = doc.getCursor(); > > String result = ""; > > while (idc.next() && result.equals("")) { > > Object placeholder = idc.getValue(); > > if (placeholder instanceof IData) { > > result = getFirstPipelineValue((IData)placeholder, key); > > } > > if (placeholder instanceof IData[]) { > > result = getFirstPipelineValue(((IData[])placeholder)[0], key); > > if ((result.equals("") || result.equals("SUCCESS")) && > > idc.getKey().equals("header:Status")) { > > IDataUtil.remove(idc, idc.getKey()); > > } > > } > > if (idc.getKey().equals(key)) { > > if (placeholder instanceof String[]) { > > result = ((String[])placeholder)[0]; > > } > > if (placeholder instanceof String) { > > result = (String) placeholder; > > } > > } > > } > > idc.destroy(); > > return result; > > } > > // --- <> --- > > > > /** > > * The service implementations given below are read-only and show only the > > * method definitions and not the complete implementation. > > */ > > public static final void removeSuccessHeader(IData pipeline) > > throws ServiceException { > > } > > > > final static executeJavaScript_SVC _instance = new > executeJavaScript_SVC(); > > > > static executeJavaScript_SVC _newInstance() { return new > > executeJavaScript_SVC(); } > > > > static executeJavaScript_SVC _cast(Object o) { return > > (executeJavaScript_SVC)o; } > > > > } > > From sundararajan.athijegannathan at oracle.com Mon Nov 21 14:14:38 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Mon, 21 Nov 2016 19:44:38 +0530 Subject: RFR 8170099: Nashorn test failures with stricter reflection access checks in jake forest Message-ID: <5833014E.50502@oracle.com> Please review http://cr.openjdk.java.net/~sundar/8170099/webrev.00/ for https://bugs.openjdk.java.net/browse/JDK-8170099 Thanks, -Sundar From james.laskey at oracle.com Mon Nov 21 14:10:42 2016 From: james.laskey at oracle.com (Jim Laskey (Oracle)) Date: Mon, 21 Nov 2016 10:10:42 -0400 Subject: RFR 8170099: Nashorn test failures with stricter reflection access checks in jake forest In-Reply-To: <5833014E.50502@oracle.com> References: <5833014E.50502@oracle.com> Message-ID: <7F5C3FAA-C3E9-4D7B-B29F-EA5A460A2FE6@oracle.com> +1 > On Nov 21, 2016, at 10:14 AM, Sundararajan Athijegannathan wrote: > > Please review http://cr.openjdk.java.net/~sundar/8170099/webrev.00/ for https://bugs.openjdk.java.net/browse/JDK-8170099 > > Thanks, > -Sundar From Alan.Bateman at oracle.com Mon Nov 21 14:13:39 2016 From: Alan.Bateman at oracle.com (Alan Bateman) Date: Mon, 21 Nov 2016 14:13:39 +0000 Subject: RFR 8170099: Nashorn test failures with stricter reflection access checks in jake forest In-Reply-To: <5833014E.50502@oracle.com> References: <5833014E.50502@oracle.com> Message-ID: On 21/11/2016 14:14, Sundararajan Athijegannathan wrote: > Please review http://cr.openjdk.java.net/~sundar/8170099/webrev.00/ > for https://bugs.openjdk.java.net/browse/JDK-8170099 This looks okay although you could replace the setAccessible methods in Reflector that take Method and Constructor with one that takes an Executable. -Alan From sundararajan.athijegannathan at oracle.com Mon Nov 21 15:06:47 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Mon, 21 Nov 2016 20:36:47 +0530 Subject: RFR 8170099: Nashorn test failures with stricter reflection access checks in jake forest In-Reply-To: References: <5833014E.50502@oracle.com> Message-ID: <58330D87.70005@oracle.com> Thanks for the review. Fixing Reflection with your suggesting and pushing it. Updated webrev for the record: http://cr.openjdk.java.net/~sundar/8170099/webrev.01/ -Sundar On 21/11/16, 7:43 PM, Alan Bateman wrote: > > > On 21/11/2016 14:14, Sundararajan Athijegannathan wrote: >> Please review http://cr.openjdk.java.net/~sundar/8170099/webrev.00/ >> for https://bugs.openjdk.java.net/browse/JDK-8170099 > This looks okay although you could replace the setAccessible methods > in Reflector that take Method and Constructor with one that takes an > Executable. > > -Alan From mb404a at att.com Mon Nov 21 21:33:27 2016 From: mb404a at att.com (BOBBA, MANOJ) Date: Mon, 21 Nov 2016 21:33:27 +0000 Subject: ECMAScript Exception Message-ID: <06FEB05751085E42B9174CDDDC1C7C380ABC610A@MOKSCY3MSGUSRGG.ITServices.sbc.com> Hi, I recently upgraded my java version from java 1.7 to java 1.8. After the upgrade i am getting this error Caused by: ECMAScript Exception: TypeError: Can not find a common class loader for ScriptObject and My Interface Name Can you please tell me how i can fix this error. Thanks & Regards, Manoj Bobba. From mb404a at att.com Mon Nov 21 22:25:49 2016 From: mb404a at att.com (BOBBA, MANOJ) Date: Mon, 21 Nov 2016 22:25:49 +0000 Subject: ECMAScript Exception Message-ID: <06FEB05751085E42B9174CDDDC1C7C380ABC6121@MOKSCY3MSGUSRGG.ITServices.sbc.com> Also please tell me which version jdk 1.8 version I should use. Regards, Manoj Bobba. From: BOBBA, MANOJ Sent: Monday, November 21, 2016 3:33 PM To: 'nashorn-dev at openjdk.java.net' Subject: ECMAScript Exception Hi, I recently upgraded my java version from java 1.7 to java 1.8. After the upgrade i am getting this error Caused by: ECMAScript Exception: TypeError: Can not find a common class loader for ScriptObject and My Interface Name Can you please tell me how i can fix this error. Thanks & Regards, Manoj Bobba. From sundararajan.athijegannathan at oracle.com Tue Nov 22 03:00:59 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Tue, 22 Nov 2016 08:30:59 +0530 Subject: ECMAScript Exception In-Reply-To: <06FEB05751085E42B9174CDDDC1C7C380ABC610A@MOKSCY3MSGUSRGG.ITServices.sbc.com> References: <06FEB05751085E42B9174CDDDC1C7C380ABC610A@MOKSCY3MSGUSRGG.ITServices.sbc.com> Message-ID: <19a9bce6-70b0-3daf-4e00-48a72e8dbdee@oracle.com> Hi, I assume you've been using Rhino JS engine shipped with JDK 1.7 and you're migrating to use JDK 8. But, you've *not* provided any details on the script used! It is not possible to debug or offer any suggestion based without additional information. You've to provide an reproduceable test script that throws the mentioned exception with JDK 8. -Sundar On 11/22/2016 3:03 AM, BOBBA, MANOJ wrote: > Hi, > > I recently upgraded my java version from java 1.7 to java 1.8. After the upgrade i am getting this error > Caused by: ECMAScript Exception: TypeError: Can not find a common class loader for ScriptObject and My Interface Name > > Can you please tell me how i can fix this error. > > > > Thanks & Regards, > > Manoj Bobba. > From sundararajan.athijegannathan at oracle.com Wed Nov 23 05:06:17 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Wed, 23 Nov 2016 10:36:17 +0530 Subject: What about JSObject? Object.prototype.hasOwnProperty.call(obj, prop) In-Reply-To: References: Message-ID: 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 From hannes.wallnoefer at oracle.com Fri Nov 25 11:52:03 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Fri, 25 Nov 2016 12:52:03 +0100 Subject: RFR: 8170322: Specialized functions convert booleans to numbers Message-ID: Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8170322 Webrev: http://cr.openjdk.java.net/~hannesw/8170322/webrev/ This adds a new ?convertsNumericArgs? property to the SpecializedFunction annotation that defines whether it is safe to convert non-numeric arguments for this function to numbers. This is used at link time to decide whether the specialised function can be used with a boolean parameter. I also removed a few specialised functions with long parameters which are no longer in use. Thanks, Hannes From james.laskey at oracle.com Fri Nov 25 12:19:23 2016 From: james.laskey at oracle.com (Jim Laskey (Oracle)) Date: Fri, 25 Nov 2016 08:19:23 -0400 Subject: RFR: 8170322: Specialized functions convert booleans to numbers In-Reply-To: References: Message-ID: +1 > On Nov 25, 2016, at 7:52 AM, Hannes Walln?fer wrote: > > Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8170322 > Webrev: http://cr.openjdk.java.net/~hannesw/8170322/webrev/ > > This adds a new ?convertsNumericArgs? property to the SpecializedFunction annotation that defines whether it is safe to convert non-numeric arguments for this function to numbers. This is used at link time to decide whether the specialised function can be used with a boolean parameter. I also removed a few specialised functions with long parameters which are no longer in use. > > Thanks, > Hannes From szegedia at gmail.com Fri Nov 25 13:31:54 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Fri, 25 Nov 2016 14:31:54 +0100 Subject: RFR: 8170322: Specialized functions convert booleans to numbers In-Reply-To: References: Message-ID: +1. If I understand it correctly, it was only Array.concat and Array.push that needed this? That?s good, it means it wasn't a really widespread problem. Attila. > On 25 Nov 2016, at 12:52, Hannes Walln?fer wrote: > > Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8170322 > Webrev: http://cr.openjdk.java.net/~hannesw/8170322/webrev/ > > This adds a new ?convertsNumericArgs? property to the SpecializedFunction annotation that defines whether it is safe to convert non-numeric arguments for this function to numbers. This is used at link time to decide whether the specialised function can be used with a boolean parameter. I also removed a few specialised functions with long parameters which are no longer in use. > > Thanks, > Hannes From hannes.wallnoefer at oracle.com Fri Nov 25 14:02:32 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Fri, 25 Nov 2016 15:02:32 +0100 Subject: RFR: 8170322: Specialized functions convert booleans to numbers In-Reply-To: References: Message-ID: <4B266AC4-150E-45AC-9291-F8F8F4653F7E@oracle.com> Thanks for the review. > Am 25.11.2016 um 14:31 schrieb Attila Szegedi : > > If I understand it correctly, it was only Array.concat and Array.push that needed this? That?s good, it means it wasn't a really widespread problem. > Yes, those are the only number-specialized functions we have that don?t actually expect a number - they?re just to prevent boxing and keep the array type primitive. I must admit I only went through the list of specialised functions using ?common sense? and running some quick comparisons with V8, but I?m pretty sure I didn?t oversee anything. :) Hannes From hannes.wallnoefer at oracle.com Fri Nov 25 15:19:14 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Fri, 25 Nov 2016 16:19:14 +0100 Subject: RFR: 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions Message-ID: <1180ED3E-8297-4AF2-A86D-611F8F4BCD89@oracle.com> Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8161579 Webrev: http://cr.openjdk.java.net/~hannesw/8161579/webrev/ Thanks, Hannes From james.laskey at oracle.com Fri Nov 25 18:34:25 2016 From: james.laskey at oracle.com (Jim Laskey (Oracle)) Date: Fri, 25 Nov 2016 14:34:25 -0400 Subject: RFR: 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions In-Reply-To: <1180ED3E-8297-4AF2-A86D-611F8F4BCD89@oracle.com> References: <1180ED3E-8297-4AF2-A86D-611F8F4BCD89@oracle.com> Message-ID: +1 > On Nov 25, 2016, at 11:19 AM, Hannes Walln?fer wrote: > > Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8161579 > Webrev: http://cr.openjdk.java.net/~hannesw/8161579/webrev/ > > Thanks, > Hannes From szegedia at gmail.com Sat Nov 26 10:02:32 2016 From: szegedia at gmail.com (Attila Szegedi) Date: Sat, 26 Nov 2016 11:02:32 +0100 Subject: RFR: 8161579: Array-like AbstractJSObject-based instance not treated as array by native array functions In-Reply-To: <1180ED3E-8297-4AF2-A86D-611F8F4BCD89@oracle.com> References: <1180ED3E-8297-4AF2-A86D-611F8F4BCD89@oracle.com> Message-ID: <640C31F2-597A-4823-B785-A78477E973C2@gmail.com> +1 > On 25 Nov 2016, at 16:19, Hannes Walln?fer wrote: > > Please review: > > Bug: https://bugs.openjdk.java.net/browse/JDK-8161579 > Webrev: http://cr.openjdk.java.net/~hannesw/8161579/webrev/ > > Thanks, > Hannes From Martin.Hiller at cas.de Mon Nov 28 10:32:12 2016 From: Martin.Hiller at cas.de (Martin Hiller) Date: Mon, 28 Nov 2016 10:32:12 +0000 Subject: Caching of CompiledScripts and related time zone issues Message-ID: Hi, we are using Nashorn in a web application scenario where currently each session has its own scripting engine. As most of the executed scripts are the same across the different sessions, we actually want to employ a single engine for the whole application and benefit from the common class cache and globally cached CompiledScripts (of course every script would be executed with a separate Global/Bindings). However, each session potentially needs to run scripts in its own time zone, which can afaik only be set during engine creation. So it seems to me that one engine per session (or at least one engine per time zone) is the minimum requirement in our scenario, isn't it? On the other hand, if we stick to our one-engine-per-session rule, it seems impossible to cache and reuse CompiledScripts on a global level because a CompiledScript is tied to the engine it was created from, and this CompiledScript will therefore always use the time zone of its corresponding engine. Is there an easy method or workaround to profit from global caching of compiled scripts in a way that the time zone is retrieved at script runtime and not fixed at engine creation time? Or do you have any other suggestion on how to improve the depicted scenario? Thank you for your time! Best regards, Martin From sundararajan.athijegannathan at oracle.com Mon Nov 28 13:14:00 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Mon, 28 Nov 2016 18:44:00 +0530 Subject: Caching of CompiledScripts and related time zone issues In-Reply-To: References: Message-ID: <583C2D98.1010601@oracle.com> I think you've to go with one engine per timezone (and you could still share engines with many sessions - as I'd presume there would many sessions in each timezone). Also, only Date objects (NativeDate instances in nashorn impl.) copy timezone from "environment" (per engine object) at the time of object creation. It does not seem anyway to avoid this. Thanks, -Sundar On 28/11/16, 4:02 PM, Martin Hiller wrote: > Hi, > > we are using Nashorn in a web application scenario where currently each session has its own scripting engine. As most of the executed scripts are the same across the different sessions, we actually want to employ a single engine for the whole application and benefit from the common class cache and globally cached CompiledScripts (of course every script would be executed with a separate Global/Bindings). > > However, each session potentially needs to run scripts in its own time zone, which can afaik only be set during engine creation. So it seems to me that one engine per session (or at least one engine per time zone) is the minimum requirement in our scenario, isn't it? > > On the other hand, if we stick to our one-engine-per-session rule, it seems impossible to cache and reuse CompiledScripts on a global level because a CompiledScript is tied to the engine it was created from, and this CompiledScript will therefore always use the time zone of its corresponding engine. > > Is there an easy method or workaround to profit from global caching of compiled scripts in a way that the time zone is retrieved at script runtime and not fixed at engine creation time? Or do you have any other suggestion on how to improve the depicted scenario? > > Thank you for your time! > > Best regards, > Martin From Martin.Hiller at cas.de Mon Nov 28 13:56:44 2016 From: Martin.Hiller at cas.de (Martin Hiller) Date: Mon, 28 Nov 2016 13:56:44 +0000 Subject: Caching of CompiledScripts and related time zone issues In-Reply-To: <583C2D98.1010601@oracle.com> References: <583C2D98.1010601@oracle.com> Message-ID: Hi Sundar, thank you for your quick response! One engine per time zone is the strategy we will pursue, as there are indeed many sessions from the same time zone. I wanted to make sure there isn't a trivial obvious solution that I'm overseeing here (e.g., somehow running a CompiledScript in the context of a different engine or similar). Best regards, Martin -----Original Message----- From: nashorn-dev [mailto:nashorn-dev-bounces at openjdk.java.net] On Behalf Of Sundararajan Athijegannathan Sent: Monday, November 28, 2016 2:14 PM To: nashorn-dev at openjdk.java.net Subject: Re: Caching of CompiledScripts and related time zone issues I think you've to go with one engine per timezone (and you could still share engines with many sessions - as I'd presume there would many sessions in each timezone). Also, only Date objects (NativeDate instances in nashorn impl.) copy timezone from "environment" (per engine object) at the time of object creation. It does not seem anyway to avoid this. Thanks, -Sundar On 28/11/16, 4:02 PM, Martin Hiller wrote: > Hi, > > we are using Nashorn in a web application scenario where currently each session has its own scripting engine. As most of the executed scripts are the same across the different sessions, we actually want to employ a single engine for the whole application and benefit from the common class cache and globally cached CompiledScripts (of course every script would be executed with a separate Global/Bindings). > > However, each session potentially needs to run scripts in its own time zone, which can afaik only be set during engine creation. So it seems to me that one engine per session (or at least one engine per time zone) is the minimum requirement in our scenario, isn't it? > > On the other hand, if we stick to our one-engine-per-session rule, it seems impossible to cache and reuse CompiledScripts on a global level because a CompiledScript is tied to the engine it was created from, and this CompiledScript will therefore always use the time zone of its corresponding engine. > > Is there an easy method or workaround to profit from global caching of compiled scripts in a way that the time zone is retrieved at script runtime and not fixed at engine creation time? Or do you have any other suggestion on how to improve the depicted scenario? > > Thank you for your time! > > Best regards, > Martin From sundararajan.athijegannathan at oracle.com Mon Nov 28 15:17:00 2016 From: sundararajan.athijegannathan at oracle.com (Sundararajan Athijegannathan) Date: Mon, 28 Nov 2016 20:47:00 +0530 Subject: RFR 8170402: Compilation warning with NashornException Message-ID: <583C4A6C.7000909@oracle.com> Please review http://cr.openjdk.java.net/~sundar/8170402/webrev.00/ for https://bugs.openjdk.java.net/browse/JDK-8170402 Thanks, -Sundar From hannes.wallnoefer at oracle.com Mon Nov 28 15:10:13 2016 From: hannes.wallnoefer at oracle.com (=?utf-8?Q?Hannes_Walln=C3=B6fer?=) Date: Mon, 28 Nov 2016 16:10:13 +0100 Subject: RFR 8170402: Compilation warning with NashornException In-Reply-To: <583C4A6C.7000909@oracle.com> References: <583C4A6C.7000909@oracle.com> Message-ID: +1 Hannes > Am 28.11.2016 um 16:17 schrieb Sundararajan Athijegannathan : > > Please review http://cr.openjdk.java.net/~sundar/8170402/webrev.00/ for https://bugs.openjdk.java.net/browse/JDK-8170402 > > Thanks, > -Sundar > From james.laskey at oracle.com Mon Nov 28 15:31:27 2016 From: james.laskey at oracle.com (Jim Laskey (Oracle)) Date: Mon, 28 Nov 2016 11:31:27 -0400 Subject: RFR 8170402: Compilation warning with NashornException In-Reply-To: <583C4A6C.7000909@oracle.com> References: <583C4A6C.7000909@oracle.com> Message-ID: <6E006E82-D4E9-4094-94BC-A9915466670C@oracle.com> +1 > On Nov 28, 2016, at 11:17 AM, Sundararajan Athijegannathan wrote: > > Please review http://cr.openjdk.java.net/~sundar/8170402/webrev.00/ for https://bugs.openjdk.java.net/browse/JDK-8170402 > > Thanks, > -Sundar > From Joerg.Frantzius at aperto.com Tue Nov 29 17:41:50 2016 From: Joerg.Frantzius at aperto.com (=?utf-8?B?RnJhbnR6aXVzLCBKw7ZyZw==?=) Date: Tue, 29 Nov 2016 17:41:50 +0000 Subject: java.lang.VerifyError: Inconsistent stackmap frames at branch target Message-ID: <1457EC63-39E7-4AE7-BAB0-F77352D6743A@aperto.com> Hi, with JDK 1.8.0_112 (on Mac OS X) I?m running into the following error. When querying bugs.openjdk.java.net for "Current frame's stack size doesn't match stackmap?, I only found bugs dating from 2013, so this may not be known yet? Unfortunately I can?t see the Javascript file name or line number in the error message. The last known source location node/lib/fs.js:374 that I can step to in the Netbeans debugger is calling a constructor ?Buffer(size)?, which is likely this source: https://github.com/nodejs/node/blob/v0.12.7-release/lib/buffer.js#L48 Following is the error message: java.lang.VerifyError: Inconsistent stackmap frames at branch target 404 Exception Details: Location: jdk/nashorn/internal/scripts/Script$Recompilation$414$1806AA$\^function\_.L:1#Buffer(Ljdk/nashorn/internal/runtime/ScriptFunction;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; @382: goto Reason: Current frame's stack size doesn't match stackmap. Current Frame: bci: @382 flags: { } locals: { 'jdk/nashorn/internal/runtime/ScriptFunction', 'java/lang/Object', 'java/lang/Object', 'java/lang/Object', 'jdk/nashorn/internal/runtime/ScriptObject' } stack: { } Stackmap Frame: bci: @404 flags: { } locals: { 'jdk/nashorn/internal/runtime/ScriptFunction', 'java/lang/Object', 'java/lang/Object', 'java/lang/Object', 'jdk/nashorn/internal/runtime/ScriptObject' } stack: { 'java/lang/Object' } Bytecode: 0x0000000: 2ab6 0014 3a04 1904 ba00 2000 0059 ba00 0x0000010: 2300 005f 2bba 0027 0000 9a00 1219 04ba 0x0000020: 002a 0000 2c2d ba00 2e00 00b0 1904 ba00 0x0000030: 2000 0059 ba00 3100 005f 2cba 0034 0000 0x0000040: 9900 102b 2cb8 003a ba00 3e00 00a7 00d5 0x0000050: 1904 ba00 2000 0059 ba00 4100 005f 2cba 0x0000060: 0044 0000 9900 4d19 04ba 0020 0000 59ba 0x0000070: 0041 0000 5f2d ba00 4400 0099 0012 2dba 0x0000080: 0047 0000 b800 4a03 8798 9a00 0912 4cb8 0x0000090: 0050 4e2b 1904 ba00 5500 0059 ba00 5800 0x00000a0: 005f 2c2d ba00 5c00 00ba 005f 0000 a700 0x00000b0: 7419 04ba 0020 0000 59ba 0062 0000 5f2c 0x00000c0: ba00 6500 0099 0043 2cba 0068 0000 126a 0x00000d0: b800 7099 0026 1904 ba00 2000 0059 ba00 0x00000e0: 7300 005f 2cba 0076 0000 ba00 7900 0099 0x00000f0: 000a 2cba 0076 0000 4d2b 2cba 007b 0000 0x0000100: ba00 3e00 00a7 001d 1904 b600 80ba 0083 0x0000110: 0000 1285 ba00 8900 0012 8b10 4507 b800 0x0000120: 91bf 2bba 0047 0000 1904 ba00 9400 00b8 0x0000130: 0097 9900 3a19 04b6 0080 ba00 9a00 0012 0x0000140: 9c19 04ba 0094 0000 59ba 009f 0000 5f10 0x0000150: 10ba 00a3 0000 b800 a712 a9b8 00a7 ba00 0x0000160: ac00 0012 8b10 4907 b800 91bf 2bba 007b 0x0000170: 0000 0e98 9c00 0d2b 03ba 00af 0000 a700 0x0000180: 162b 592b ba00 4700 00b8 00b3 b800 b7ba 0x0000190: 003e 0000 2b19 04b6 0080 ba00 ba00 00ba 0x00001a0: 00bd 0000 2bba 0047 0000 1904 ba00 5500 0x00001b0: 00ba 00c0 0000 047c b800 b75d 58b8 003a 0x00001c0: 5e58 989d 00c3 2bba 007b 0000 0e97 9e00 0x00001d0: b82b ba00 4700 0019 04ba 00c2 0000 1904 0x00001e0: ba00 c500 005f b800 3a5d 58b8 003a 675d 0x00001f0: 58b8 003a 5e58 979e 0013 1904 ba00 c800 0x0000200: 00b2 00cc ba00 d000 0057 2b19 04ba 00d3 0x0000210: 0000 b200 cc19 04ba 00d6 0000 2b19 04ba 0x0000220: 00c5 0000 1904 ba00 c500 002b ba00 4700 0x0000230: 00b8 00a7 ba00 da00 00ba 00bd 0000 1904 0x0000240: 1904 ba00 c500 002b ba00 4700 00b8 00a7 0x0000250: ba00 dd00 0019 04ba 00df 0000 1007 7e99 0x0000260: 0024 1904 1904 ba00 df00 0010 0780 ba00 0x0000270: e100 0019 0419 04ba 00e3 0000 0f63 ba00 0x0000280: e500 00a7 001a 1904 ba00 e800 00b2 00cc 0x0000290: 2b2b ba00 4700 00ba 00ec 0000 5719 04ba 0x00002a0: 0020 0000 59ba 0031 0000 5f2c ba00 3400 0x00002b0: 0099 0007 b200 ccb0 1904 ba00 2000 0059 0x00002c0: ba00 4100 005f 2cba 0044 0000 9900 8b2b 0x00002d0: 59ba 00ef 0000 5f2c 2dba 00f2 0000 3a05 0x00002e0: 1905 2bba 0047 0000 b800 f599 0064 2bba 0x00002f0: 0047 0000 3a06 2b19 05ba 005f 0000 1904 0x0000300: ba00 f800 00b2 00cc 2b2b ba00 4700 00ba 0x0000310: 00fb 0000 572b ba00 fe00 0019 04b6 0080 0x0000320: ba00 ba00 00b8 0101 9900 2419 0419 04ba 0x0000330: 00c5 0000 1906 b800 3a19 05b8 003a 675d 0x0000340: 58b8 003a 5e58 67ba 00e5 0000 a700 08b2 0x0000350: 00cc 3a06 a700 9e19 04ba 0020 0000 59ba 0x0000360: 0023 0000 5f2c ba00 2700 0099 001d 2c59 0x0000370: ba01 0400 005f 2b03 032b ba00 4700 00ba 0x0000380: 0108 0000 57a7 0063 1904 ba00 2000 0059 0x0000390: ba00 3100 005f 2cba 0047 0000 ba00 3400 0x00003a0: 009a 001a 1904 ba00 2000 0059 ba00 7300 0x00003b0: 005f 2cba 0079 0000 9900 3003 3607 1507 0x00003c0: 8739 0818 082b ba00 7b00 0098 9c00 1c2b 0x00003d0: 1808 2c18 08ba 010e 0000 ba01 1200 0018 0x00003e0: 080f 6339 08a7 ffde b200 cc3a 06b2 00cc 0x00003f0: 3a05 b200 ccb0 Stackmap Table: append_frame(@44,Object[#125]) same_frame(@80) same_frame(@141) same_frame(@147) same_frame(@177) same_frame_extended(@249) same_frame(@264) same_frame(@290) same_frame_extended(@364) same_frame(@385) same_locals_1_stack_item_frame(@404,Object[#286]) same_locals_1_stack_item_extended(@522,Object[#286]) same_locals_1_stack_item_extended(@643,Object[#286]) same_locals_1_stack_item_frame(@646,Object[#286]) same_locals_1_stack_item_frame(@669,Object[#286]) same_locals_1_stack_item_frame(@696,Object[#286]) full_frame(@844,{Object[#16],Object[#286],Object[#286],Object[#286],Object[#125],Object[#286],Object[#286]},{Object[#286]}) full_frame(@847,{Object[#16],Object[#286],Object[#286],Object[#286],Object[#125],Object[#286]},{Object[#286]}) full_frame(@852,{Object[#16],Object[#286],Object[#286],Object[#286],Object[#125],Object[#286],Object[#286]},{Object[#286]}) full_frame(@855,{Object[#16],Object[#286],Object[#286],Object[#286],Object[#125]},{Object[#286]}) same_locals_1_stack_item_frame(@904,Object[#286]) same_locals_1_stack_item_frame(@955,Object[#286]) full_frame(@963,{Object[#16],Object[#286],Object[#286],Object[#286],Object[#125],Top,Top,Integer,Double},{Object[#286]}) full_frame(@1000,{Object[#16],Object[#286],Object[#286],Object[#286],Object[#125]},{Object[#286]}) full_frame(@1010,{Object[#16],Object[#286],Object[#286],Object[#286],Object[#125],Object[#286],Object[#286]},{Object[#286]}) at java.lang.Class.getDeclaredFields0(Native Method) at java.lang.Class.privateGetDeclaredFields(Class.java:2583) at java.lang.Class.getDeclaredField(Class.java:2068) at jdk.nashorn.internal.runtime.Context$ContextCodeInstaller$1.run(Context.java:209) at jdk.nashorn.internal.runtime.Context$ContextCodeInstaller$1.run(Context.java:204) at java.security.AccessController.doPrivileged(Native Method) at jdk.nashorn.internal.runtime.Context$ContextCodeInstaller.initialize(Context.java:204) at jdk.nashorn.internal.codegen.CompilationPhase$InstallPhase.transform(CompilationPhase.java:508) at jdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:624) at jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:655) at jdk.nashorn.internal.runtime.RecompilableScriptFunctionData.compileTypeSpecialization(RecompilableScriptFunctionData.java:725) at jdk.nashorn.internal.runtime.RecompilableScriptFunctionData.getBest(RecompilableScriptFunctionData.java:905) at jdk.nashorn.internal.runtime.ScriptFunctionData.getBest(ScriptFunctionData.java:375) at jdk.nashorn.internal.runtime.ScriptFunctionData.getBestConstructor(ScriptFunctionData.java:247) at jdk.nashorn.internal.runtime.ScriptFunction.findNewMethod(ScriptFunction.java:758) at jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1827) at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:104) at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:98) at jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:176) at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124) at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:154) at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:253) at jdk.nashorn.internal.scripts.Script$Recompilation$402$9044AA$\^function\_.L:1#readFileSync(node/lib/fs.js:374) [..] Any help or hints would be very appreciated! Regards, J?rg --- Dipl. Inf. J?rg von Frantzius, Technical Director E-Mail joerg.frantzius at aperto.com Phone +49 30 283921-318 Fax +49 30 283921-29 Aperto GmbH ? An IBM Company Chausseestra?e 5, D-10115 Berlin http://www.aperto.com http://www.facebook.com/aperto https://www.xing.com/companies/apertoag HRB 77049 B, AG Berlin Charlottenburg Vorstand: Dirk Buddensiek (Vorsitzender), Kai Gro?mann, Stephan Haagen, Daniel Simon Aufsichtsrat: Matthew Candy (Vorsitzender) From srinivas.dama at oracle.com Wed Nov 30 18:11:12 2016 From: srinivas.dama at oracle.com (Srinivas Dama) Date: Wed, 30 Nov 2016 10:11:12 -0800 (PST) Subject: 8130351: JDK-8130127.js fails under cygwin: cygwin path pased to Java Message-ID: <3886bfaf-ad50-4f1c-b37e-84694bf9effd@default> Hi, Please review http://cr.openjdk.java.net/~sdama/8130351/webrev.02/ for https://bugs.openjdk.java.net/browse/JDK-8130351 Note: I cannot reproduce the errors mentioned in the bug. But I do see some other kind of issue related to $EXEC. Moved test files from currently-failing directory to nosecurity directory to include them in test run and added fix for $EXEC issue. Fix is adding '\n' to interactive input as jline used by jjs expects it. Regards, Srinivas From james.laskey at oracle.com Wed Nov 30 18:15:50 2016 From: james.laskey at oracle.com (Jim Laskey (Oracle)) Date: Wed, 30 Nov 2016 14:15:50 -0400 Subject: 8130351: JDK-8130127.js fails under cygwin: cygwin path pased to Java In-Reply-To: <3886bfaf-ad50-4f1c-b37e-84694bf9effd@default> References: <3886bfaf-ad50-4f1c-b37e-84694bf9effd@default> Message-ID: <28D4F344-04DB-46A6-837A-0874B6833D6F@oracle.com> +1 > On Nov 30, 2016, at 2:11 PM, Srinivas Dama wrote: > > Hi, > > Please review http://cr.openjdk.java.net/~sdama/8130351/webrev.02/ > for https://bugs.openjdk.java.net/browse/JDK-8130351 > > Note: I cannot reproduce the errors mentioned in the bug. But I do see some other kind of issue related to $EXEC. > Moved test files from currently-failing directory to nosecurity directory to include them in test run and added fix for $EXEC issue. > Fix is adding '\n' to interactive input as jline used by jjs expects it. > > Regards, > Srinivas From artfiedler at gmail.com Wed Nov 30 19:06:21 2016 From: artfiedler at gmail.com (Art Fiedler) Date: Wed, 30 Nov 2016 13:06:21 -0600 Subject: JSObject call() is passed undefined/null for the argument 'thiz'? Message-ID: @Sundararajan When calling the following code, I expected the call to myJSObject inside testJSOCall to pass the current scope as a ScriptObjectMirror to JSObjectImpl's call method as the thiz argument. In this case without modifying the call to myJSObject() should 'this' automatically be passed to the call() method? Thanks, Arthur Fiedler public class NashornBugTest { public static void main(String[] args) throws Exception { NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); ScriptEngine scriptEngine = factory.getScriptEngine(); scriptEngine.put("myJSObject", new JSObjectImpl()); scriptEngine.eval( "var a = 42;\n" + "function testJSOCall(b) {\n" + " myJSObject('text purposely did not pass b');\n" + "}\n" + "testJSOCall(a);\n"); } public static class JSObjectImpl extends AbstractJSObject { @Override public Object call(Object thiz, Object... args) { if (ScriptObjectMirror.isUndefined(thiz) || thiz == null) throw new IllegalArgumentException("'thiz' is undefined/null"); // TODO: need the value of 'b' in the calling function return super.call(thiz, args); } @Override public boolean isFunction() { return true; } } } From artfiedler at gmail.com Wed Nov 30 19:43:44 2016 From: artfiedler at gmail.com (Art Fiedler) Date: Wed, 30 Nov 2016 13:43:44 -0600 Subject: JavaScript Array slot/member == undefined instead of null? Message-ID: @Sundararajan, I was previously using .getSlot(index) when extracting items from a ScriptObjectMirror when that mirror was an array until I ran into a undefined element and that is not equal to null as I had for my condition... so I swapped .getSlot(i) with .get(Integer.toString(i)) Are getMember(), get(), and getSlot() suppose to all return the same null or undefined value? Or is it expected to have getMember() and getSlot() to return Undefined object and get() to return null? As a side note... If this is the intended behavior this might be a better way to get the Undefined object instead of making a call out of nashorn to a public static method. Here is an example... (jdk8 1.8.0_102) Thanks, Arthur Fiedler public static void main(String[] args) throws Exception { NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); ScriptEngine scriptEngine = factory.getScriptEngine(); scriptEngine.eval("globalArray = ['line1',undefined,null];"); ScriptObjectMirror array = (ScriptObjectMirror)scriptEngine.get("globalArray"); System.out.println("size(): " + array.size()); for(int i = 0; i < array.size(); i++) { System.out.println("Index: " + i); String iStr = String.valueOf(i); System.out.println(" GetMember('"+iStr+"'): " + array.getMember(iStr)); System.out.println(" Get('"+iStr+"'): " + array.get(iStr)); System.out.println(" GetSlot("+iStr+"): " + array.getSlot(i)); } } /* size(): 3 Index: 0 GetMember('0'): line1 Get('0'): line1 GetSlot(0): line1 Index: 1 GetMember('1'): undefined Get('1'): null GetSlot(1): undefined Index: 2 GetMember('2'): null Get('2'): null GetSlot(2): null */ From artfiedler at gmail.com Wed Nov 30 20:02:11 2016 From: artfiedler at gmail.com (Art Fiedler) Date: Wed, 30 Nov 2016 14:02:11 -0600 Subject: Confusing ScriptObjectMirror size() vs mirror.get("length") Message-ID: @Sundararajan When looping an array in javascript I would typically do something like this... for(var i = 0; i < arr.length; i++) { console.log('Index: ' + i + ' = ' + arr[i]); } When looping a javascript array using the ScriptObjectMirror I would initially think to use the same syntax, however I would swap .length with .size() since that method is available. .size() however is not the same as .length in this case. I'm not saying that is a bug, just noting the confusion it could cause when/if someone write's a java loop like that and in the future they run into an undefined item in the middle of the javascript array. See this example... Thanks, Arthur Fiedler public static void main(String[] args) throws Exception { NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); ScriptEngine scriptEngine = factory.getScriptEngine(); scriptEngine.eval( "globalArray = new Array(3);\n" + "globalArray[0] = 'line1';\n"+ "globalArray[2] = 'line3';\n"); // Note index 1 was skipped ScriptObjectMirror array = (ScriptObjectMirror)scriptEngine.get("globalArray"); System.out.println("entrySet.size(): " + array.entrySet().size()); System.out.println("keySet.size(): " + array.keySet().size()); System.out.println("values.size(): " + array.values().size()); System.out.println("length: " + array.get("length")); System.out.println("size(): " + array.size()); for(int i = 0; i < array.size(); i++) { System.out.println("Index: " + i); String iStr = String.valueOf(i); System.out.println(" Get('"+iStr+"'): " + array.get(iStr)); } System.out.println("what happened to index 2?? oops!"); } /* entrySet.size(): 2 keySet.size(): 2 values.size(): 2 length: 3 size(): 2 Index: 0 Get('0'): line1 Index: 1 Get('1'): null what happened to index 2?? oops! */ From artfiedler at gmail.com Wed Nov 30 20:54:32 2016 From: artfiedler at gmail.com (Art Fiedler) Date: Wed, 30 Nov 2016 14:54:32 -0600 Subject: Undefined should be part of the exposed nashorn API Message-ID: @Sundararajan I ran into an issue with a JSObject I implemented and some code in LessCSS. The team is likely aware by now of a need to return Undefined from JSObject's getMember() and possibly call(), and getSlot()... You had previously asked a long time ago why someone would want to do that and I responded here: http://stackoverflow.com/questions/30528083/passing-undefined-to-nashorn-javascript-in-scala-java/30533897#30533897 with a comment: Why pass undefined? Let's say your calling an existing javascript lib (like lesscss) that calls something like this... var variables = options.variables; // keep in mind typeof null === 'object' and typeof undefined === 'undefined' if (typeof variables === 'object') { var keys = Object.keys(variables); //error 'null is not an Object' } Now to put into perspective, 'options' is an implementation of AbstractJSObject... how else would you specify in getMember that the member does not exist, returning null would throw an error when Object.keys() is called. I used this workaround... because in my sandbox that runs lesscss etc java accessibility is removed and I would not be able to make the callback... // Code Fragment if (Undefined.getUndefined() == null) { // Get the undefined object now, in its own script engine, to avoid problems with permissions/security factory.getScriptEngine().eval("Java.type('io.github.artfiedler.nashorn.Undefined').setUndefined(undefined);"); } /** * Used to reference the Undefined value used in nashorn. * * This is a standalone class to avoid a passing a reference * to an object like NashornSandbox to javascript that may be * exploited in some way unexpected way. */ public final class Undefined { private static Object undefinedObject; public static void setUndefined(Object undefined) { undefinedObject = undefined; } /** * Provides and easy way to get the undefined javascript value used by nashorn. * This value is not populated until after a NashornSandbox has been initialized * * @return the internal Nashorn object used to reference undefined */ public static Object getUndefined() { return undefinedObject; } } Now using my Undefined class I can do the following in my AbstractJSObject... and this will now support the existing lesscss code without modifications. @Override public Object getMember(String name) { return spill.getOrDefault(name, Undefined.getUndefined()); } I know that Undefined is defined at jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED && jdk.nashorn.internal.runtime.Undefined.getUndefined() and the team may not want to expose those specific classes to the API but I believe at least something like this should be done... @Exported public final class ScriptObjectMirror extends AbstractJSObject implements Bindings { // This already exists... public static boolean isUndefined(Object obj) { return obj == ScriptRuntime.UNDEFINED; } // Add... public static Object getUndefined() { return ScriptRuntime.UNDEFINED; } ... } -- or -- @Exported public interface JSObject { Object Undefined = ScriptRuntime.UNDEFINED; ... } -- or -- @Exported public interface JSObject { Object Undefined = new Object() { @Override public String toString() {return "undefined";} }; ... } // This would require any usages of JSObject to check for JSObject.Undefined coming out of getMember(), call(), getSlot(), eval(), newObject() From artfiedler at gmail.com Wed Nov 30 22:02:54 2016 From: artfiedler at gmail.com (Art Fiedler) Date: Wed, 30 Nov 2016 16:02:54 -0600 Subject: Error Stack Column number Message-ID: When making an implementation of console.count([label]) part of the Mozilla's developer docs https://developer.mozilla.org/en-US/docs/Web/API/Console/count mentions when label is omitted, the function will count the number of times count() was called on that line... however, if the javascript code has been minified all lines of code may be on the same line... messing up all console.count() calls... I was providing that implementation by using new Error().stack and parsing the current file:line... however I could fix the minify issue if new Error().stack output the column also for instance... other browser seem to be doing file:line:column in the stack trace. Including nodejs see: https://nodejs.org/api/errors.html#errors_error_stack Microsoft Edge's dev console outputs... new Error().stack: "Error at eval code (eval code:1:1)" Firefox since FF30: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack Currently nashorn error stacks only include the line number... public static void main(String[] args) throws Exception { NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); ScriptEngine scriptEngine = factory.getScriptEngine(); scriptEngine.put(ScriptEngine.FILENAME, "myfile.js"); scriptEngine.eval("print('fileName: ' + new Error().fileName);"); scriptEngine.eval("print('lineNumber: ' + new Error().lineNumber);"); scriptEngine.eval("print('columnNumber: ' + new Error().columnNumber);"); scriptEngine.eval("print('stack: ' + new Error().stack);"); } /* fileName: myfile.js lineNumber: 1 columnNumber: -1 stack: Error at (myfile.js:1) */ Would be nice to add the column number to the stacks and error object in nashorn. Thanks, Arthur Fiedler From artfiedler at gmail.com Wed Nov 30 23:05:32 2016 From: artfiedler at gmail.com (Art Fiedler) Date: Wed, 30 Nov 2016 17:05:32 -0600 Subject: SourceMaps Message-ID: Would be nice to provide SourceMaps to the ScriptEngine... I've seen here... http://stackoverflow.com/questions/35137455/nashorn-use-of-source-maps That nashorn doesn't support source maps, and I'm sure there is a library out there that is catching the exception and formatting it before it would come to my code. Also note new Error() doesn't seem to provide the columnNumber to do my own source map conversion. I would propose supporting inline source maps in the js code... or implementing in java by starting out with something like a SourceMapProvider interface... public interface SourceMapProvider { public SourceMapConsumer getConsumer(String filename); public SourceMapConsumer putConsumer(String filename, SourceMapConsumer consumer); public SourcePosition getOriginalPosition(String filename, int line, int column); public SourcePosition getOriginalPosition(String filename, int offset); public SourcePosition getGeneratedPosition(String filename, int line, int column); public SourcePosition getGeneratedPosition(String filename, int offset); } public interface SourceMapConsumer { public String getFilename(); public SourcePosition getOriginalPosition(int line, int column); public SourcePosition getOriginalPosition(int offset); public SourcePosition getGeneratedPosition(int line, int column); public SourcePosition getGeneratedPosition(int offset); } public interface SourcePosition { public String getFilename(); public int getOriginalLine(); public int getOriginalColumn(); public int getOriginalOffset(); public String getOriginalName(); // Original Identifier, I believe this would be used for replaced variable names etc public int getGeneratedLine(); public int getGeneratedColumn(); public int getGeneratedOffset(); } scriptEngine.setSourceMapProvider(mySourceMaps); scriptEngine.eval("//@sourceURL=myfile.js\n... minified or transformed code ..."); scriptEngine.eval("//@sourceURL=myotherfile.js\n... minified or transformed code ..."); The idea would be that the CodeGenerator, etc... would query the provider for line/column info passed to an error if a SourceMapProvider was specified and a SourceMapConsumer exists for that the file. -Arthur Fiedler