Review request for JDK-8006984
Attila Szegedi
attila.szegedi at oracle.com
Mon Feb 25 09:46:48 PST 2013
Excellent…
On that note, I want to make you aware that we'll soon make Nashorn reject with a syntax error those function declarations that occur within "with" and "catch" blocks; we're shooting for 100% ECMAScript 5.1 compliance, and it disallows function declarations except directly on the top-level of script and in another function's body. In such cases, you'll need to use a function expression instead. So this:
var guiPkgs = { JFrame: function() { print("created"); } };
with (guiPkgs) {
function main() { // <---- this is not legal in ECMAScript 5.1
var frame;
function createFrame() {
frame = new JFrame();
}
createFrame();
}
}
main();
will soon stop working. If you want the "main" function and whatever is in it to be affected by the with() block, you'll have to use a function expression instead like this:
with (guiPkgs) {
var main = function() { // <---- this expresses your actual intent, and is the only valid construct here in ES5.1
var frame;
function createFrame() { // <-- this is still okay, as it's defined directly on the function body level of main()
frame = new JFrame();
}
createFrame();
}
}
main();
Attila.
On Feb 25, 2013, at 6:37 PM, Andreas Rieber <rieberandreas at gmail.com> wrote:
> Hi Attila,
>
> i found that fix and retested. One line more and another one... couldn't break it ;-)
>
> Andreas
>
> On 25.02.13 16:36, Attila Szegedi wrote:
>> Second review request, now with the test: http://cr.openjdk.java.net/~attila/8006984/webrev.01/
>>
>> On Feb 25, 2013, at 3:43 PM, Attila Szegedi <attila.szegedi at oracle.com> wrote:
>>
>>> Please review JDK-8006984 at http://cr.openjdk.java.net/~attila/8006984/webrev.00
>>>
>>> Thanks,
>>> Attila.
More information about the nashorn-dev
mailing list