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

Print this page

        

@@ -75,11 +75,13 @@
 import jdk.nashorn.internal.ir.BreakNode;
 import jdk.nashorn.internal.ir.CallNode;
 import jdk.nashorn.internal.ir.CaseNode;
 import jdk.nashorn.internal.ir.CatchNode;
 import jdk.nashorn.internal.ir.ContinueNode;
+import jdk.nashorn.internal.ir.DebuggerNode;
 import jdk.nashorn.internal.ir.EmptyNode;
+import jdk.nashorn.internal.ir.ErrorNode;
 import jdk.nashorn.internal.ir.Expression;
 import jdk.nashorn.internal.ir.ExpressionStatement;
 import jdk.nashorn.internal.ir.ForNode;
 import jdk.nashorn.internal.ir.FunctionNode;
 import jdk.nashorn.internal.ir.FunctionNode.CompilationState;

@@ -354,11 +356,12 @@
             functionDeclarations = null;
 
             restoreBlock(body);
             body.setFlag(Block.NEEDS_SCOPE);
 
-            final Block functionBody = new Block(functionToken, source.getLength() - 1, body.getFlags(), body.getStatements());
+            final Block functionBody = new Block(functionToken, source.getLength() - 1, 
+                body.getFlags() | Block.IS_SYNTHETIC, body.getStatements());
             lc.pop(function);
 
             expect(EOF);
 
             final FunctionNode functionNode = createFunctionNode(

@@ -538,11 +541,12 @@
         // Block closing brace.
         if (needsBraces) {
             expect(RBRACE);
         }
 
-        return new Block(blockToken, finish, newBlock.getFlags(), newBlock.getStatements());
+        final int flags = newBlock.getFlags() | (needsBraces? 0 : Block.IS_SYNTHETIC);
+        return new Block(blockToken, finish, flags, newBlock.getStatements());
     }
 
 
     /**
      * Get all the statements generated by a single statement.

@@ -557,11 +561,11 @@
         try {
             statement(false, false, true);
         } finally {
             restoreBlock(newBlock);
         }
-        return new Block(newBlock.getToken(), finish, newBlock.getFlags(), newBlock.getStatements());
+        return new Block(newBlock.getToken(), finish, newBlock.getFlags() | Block.IS_SYNTHETIC, newBlock.getStatements());
     }
 
     /**
      * Detect calls to special functions.
      * @param ident Called function.

@@ -710,11 +714,11 @@
         addFunctionDeclarations(script);
         functionDeclarations = null;
 
         restoreBlock(body);
         body.setFlag(Block.NEEDS_SCOPE);
-        final Block programBody = new Block(functionToken, functionLine, body.getFlags(), body.getStatements());
+        final Block programBody = new Block(functionToken, functionLine, body.getFlags() | Block.IS_SYNTHETIC, body.getStatements());
         lc.pop(script);
         script.setLastToken(token);
 
         expect(EOF);
 

@@ -824,12 +828,17 @@
                                 }
                             }
                         }
                     }
                 } catch (final Exception e) {
+                    final int errorLine = line;
+                    final long errorToken = token;
                     //recover parsing
                     recover(e);
+                    final ErrorNode errorExpr = new ErrorNode(errorToken, finish);
+                    final ExpressionStatement expressionStatement = new ExpressionStatement(errorLine, errorToken, finish, errorExpr);
+                    appendStatement(expressionStatement);
                 }
 
                 // No backtracking from here on.
                 stream.commit(k);
             }

@@ -1851,11 +1860,11 @@
                     final Block catchBody = getBlock(true);
                     final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody, false);
                     appendStatement(catchNode);
                 } finally {
                     restoreBlock(catchBlock);
-                    catchBlocks.add(new Block(catchBlock.getToken(), finish, catchBlock.getFlags(), catchBlock.getStatements()));
+                    catchBlocks.add(new Block(catchBlock.getToken(), finish, catchBlock.getFlags() | Block.IS_SYNTHETIC, catchBlock.getStatements()));
                 }
 
                 // If unconditional catch then should to be the end.
                 if (ifExpression == null) {
                     break;

@@ -1881,11 +1890,11 @@
             appendStatement(tryNode);
         } finally {
             restoreBlock(outer);
         }
 
-        appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags(), outer.getStatements())));
+        appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags() | Block.IS_SYNTHETIC, outer.getStatements())));
     }
 
     /**
      * DebuggerStatement :
      *      debugger ;

@@ -1899,11 +1908,11 @@
         final int  debuggerLine  = line;
         final long debuggerToken = token;
         // DEBUGGER tested in caller.
         next();
         endOfLine();
-        appendStatement(new ExpressionStatement(debuggerLine, debuggerToken, finish, new RuntimeNode(debuggerToken, finish, RuntimeNode.Request.DEBUGGER, Collections.<Expression>emptyList())));
+        appendStatement(new DebuggerNode(debuggerLine, debuggerToken, finish));
     }
 
     /**
      * PrimaryExpression :
      *      this

@@ -2880,11 +2889,10 @@
         ParserContextBlockNode body = null;
         final long bodyToken = token;
         Block functionBody;
         int bodyFinish = 0;
 
-
         final boolean parseBody;
         Object endParserState = null;
         try {
             // Create a new function block.
             body = newBlock();