< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java

Print this page




2590         final int  tryLine  = line;
2591         final long tryToken = token;
2592         // TRY tested in caller.
2593         next();
2594 
2595         // Container block needed to act as target for labeled break statements
2596         final int startLine = line;
2597         final ParserContextBlockNode outer = newBlock();
2598         // Create try.
2599 
2600         try {
2601             final Block       tryBody     = getBlock(true);
2602             final List<Block> catchBlocks = new ArrayList<>();
2603 
2604             while (type == CATCH) {
2605                 final int  catchLine  = line;
2606                 final long catchToken = token;
2607                 next();
2608                 expect(LPAREN);
2609 
2610                 // FIXME: ES6 catch parameter can be a BindingIdentifier or a BindingPattern
2611                 // We need to generalize this here!
2612                 // http://www.ecma-international.org/ecma-262/6.0/
2613                 final IdentNode exception = getIdent();
2614 









2615                 // ECMA 12.4.1 strict mode restrictions
2616                 verifyStrictIdent(exception, "catch argument");


2617 
2618                 // Nashorn extension: catch clause can have optional
2619                 // condition. So, a single try can have more than one
2620                 // catch clause each with it's own condition.
2621                 final Expression ifExpression;
2622                 if (!env._no_syntax_extensions && type == IF) {
2623                     next();
2624                     // Get the exception condition.
2625                     ifExpression = expression();
2626                 } else {
2627                     ifExpression = null;
2628                 }
2629 
2630                 expect(RPAREN);
2631 
2632                 final ParserContextBlockNode catchBlock = newBlock();
2633                 try {
2634                     // Get CATCH body.
2635                     final Block catchBody = getBlock(true);
2636                     final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody, false);




2590         final int  tryLine  = line;
2591         final long tryToken = token;
2592         // TRY tested in caller.
2593         next();
2594 
2595         // Container block needed to act as target for labeled break statements
2596         final int startLine = line;
2597         final ParserContextBlockNode outer = newBlock();
2598         // Create try.
2599 
2600         try {
2601             final Block       tryBody     = getBlock(true);
2602             final List<Block> catchBlocks = new ArrayList<>();
2603 
2604             while (type == CATCH) {
2605                 final int  catchLine  = line;
2606                 final long catchToken = token;
2607                 next();
2608                 expect(LPAREN);
2609 
2610                 // ES6 catch parameter can be a BindingIdentifier or a BindingPattern

2611                 // http://www.ecma-international.org/ecma-262/6.0/
2612                 final String contextString = "catch argument";
2613                 final Expression exception = bindingIdentifierOrPattern(contextString);
2614                 final boolean isDestructuring = !(exception instanceof IdentNode);
2615                 if (isDestructuring) {
2616                     verifyDestructuringBindingPattern(exception, new Consumer<IdentNode>() {
2617                         @Override
2618                         public void accept(final IdentNode identNode) {
2619                             verifyIdent(identNode, contextString);
2620                         }
2621                     });
2622                 } else {
2623                     // ECMA 12.4.1 strict mode restrictions
2624                     verifyStrictIdent((IdentNode) exception, "catch argument");
2625                 }
2626 
2627 
2628                 // Nashorn extension: catch clause can have optional
2629                 // condition. So, a single try can have more than one
2630                 // catch clause each with it's own condition.
2631                 final Expression ifExpression;
2632                 if (!env._no_syntax_extensions && type == IF) {
2633                     next();
2634                     // Get the exception condition.
2635                     ifExpression = expression();
2636                 } else {
2637                     ifExpression = null;
2638                 }
2639 
2640                 expect(RPAREN);
2641 
2642                 final ParserContextBlockNode catchBlock = newBlock();
2643                 try {
2644                     // Get CATCH body.
2645                     final Block catchBody = getBlock(true);
2646                     final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody, false);


< prev index next >