< prev index next >

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

Print this page




2602         final int  tryLine  = line;
2603         final long tryToken = token;
2604         // TRY tested in caller.
2605         next();
2606 
2607         // Container block needed to act as target for labeled break statements
2608         final int startLine = line;
2609         final ParserContextBlockNode outer = newBlock();
2610         // Create try.
2611 
2612         try {
2613             final Block       tryBody     = getBlock(true);
2614             final List<Block> catchBlocks = new ArrayList<>();
2615 
2616             while (type == CATCH) {
2617                 final int  catchLine  = line;
2618                 final long catchToken = token;
2619                 next();
2620                 expect(LPAREN);
2621 
2622                 // FIXME: ES6 catch parameter can be a BindingIdentifier or a BindingPattern
2623                 // We need to generalize this here!
2624                 // http://www.ecma-international.org/ecma-262/6.0/
2625                 final IdentNode exception = getIdent();
2626 









2627                 // ECMA 12.4.1 strict mode restrictions
2628                 verifyStrictIdent(exception, "catch argument");


2629 
2630                 // Nashorn extension: catch clause can have optional
2631                 // condition. So, a single try can have more than one
2632                 // catch clause each with it's own condition.
2633                 final Expression ifExpression;
2634                 if (!env._no_syntax_extensions && type == IF) {
2635                     next();
2636                     // Get the exception condition.
2637                     ifExpression = expression();
2638                 } else {
2639                     ifExpression = null;
2640                 }
2641 
2642                 expect(RPAREN);
2643 
2644                 final ParserContextBlockNode catchBlock = newBlock();
2645                 try {
2646                     // Get CATCH body.
2647                     final Block catchBody = getBlock(true);
2648                     final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody, false);




2602         final int  tryLine  = line;
2603         final long tryToken = token;
2604         // TRY tested in caller.
2605         next();
2606 
2607         // Container block needed to act as target for labeled break statements
2608         final int startLine = line;
2609         final ParserContextBlockNode outer = newBlock();
2610         // Create try.
2611 
2612         try {
2613             final Block       tryBody     = getBlock(true);
2614             final List<Block> catchBlocks = new ArrayList<>();
2615 
2616             while (type == CATCH) {
2617                 final int  catchLine  = line;
2618                 final long catchToken = token;
2619                 next();
2620                 expect(LPAREN);
2621 
2622                 // ES6 catch parameter can be a BindingIdentifier or a BindingPattern

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


< prev index next >