2004/01/11 01:43:16
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:44:10 +0000 (07:44 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:44:10 +0000 (07:44 +0000)
darcs-hash:20040130074410-2ba56-4c29ab3d6f37bad77d1073f7e9598dd4aa8a4d08.gz

src/org/xwt/js/Parser.java

index ee04b7e..0583202 100644 (file)
@@ -727,20 +727,57 @@ class Parser extends Lexer implements ByteCodes {
             int catchJMPDistance = -1;
             if (peekToken() == CATCH) {
                 catchJMPDistance = b.size - tryInsn;
-                String exceptionVar;
-                getToken();
-                consume(LP);
-                consume(NAME);
-                exceptionVar = string;
-                consume(RP);
-                b.add(parserLine, TOPSCOPE);                        // the exception is on top of the stack; put it to the chosen name
-                b.add(parserLine, SWAP);
-                b.add(parserLine, LITERAL,exceptionVar);
-                b.add(parserLine, SWAP);
-                b.add(parserLine, PUT);
-                b.add(parserLine, POP);
-                b.add(parserLine, POP);
-                parseStatement(b, null);
+                while(peekToken() == CATCH) {
+                    String exceptionVar;
+                    getToken();
+                    consume(LP);
+                    consume(NAME);
+                    exceptionVar = string;
+                    int[] writebacks = new int[] { -1, -1, -1 };
+                    if (peekToken() != RP) {
+                        // extended XWT catch block: catch(e faultCode "foo.bar.baz")
+                        consume(NAME);
+                        String propName = string;
+                        b.add(parserLine, DUP);
+                        b.add(parserLine, LITERAL, string);
+                        b.add(parserLine, GET);
+                        b.add(parserLine, DUP);
+                        b.add(parserLine, LITERAL, null);
+                        b.add(parserLine, EQ);
+                        b.add(parserLine, JT);
+                        writebacks[0] = b.size - 1;
+                        if (peekToken() == STRING) {
+                            consume(STRING);
+                            b.add(parserLine, DUP);
+                            b.add(parserLine, LITERAL, string);
+                            b.add(parserLine, LT);
+                            b.add(parserLine, JT);
+                            writebacks[1] = b.size - 1;
+                            b.add(parserLine, LITERAL, string + "/");   // (slash is ASCII after dot)
+                            b.add(parserLine, GE);
+                            b.add(parserLine, JT);
+                            writebacks[2] = b.size - 1;
+                        } else {
+                            consume(NUMBER);
+                            b.add(parserLine, LITERAL, number);
+                            b.add(parserLine, EQ);
+                            b.add(parserLine, JF);
+                            writebacks[1] = b.size - 1;
+                        }
+                    }
+                    consume(RP);
+                    // the exception is on top of the stack; put it to the chosen name
+                    b.add(parserLine, TOPSCOPE);
+                    b.add(parserLine, SWAP);
+                    b.add(parserLine, LITERAL,exceptionVar);
+                    b.add(parserLine, SWAP);
+                    b.add(parserLine, PUT);
+                    b.add(parserLine, POP);
+                    b.add(parserLine, POP);
+                    parseStatement(b, null);
+                    b.add(parserLine, LITERAL, null);   // so we have something to pop
+                    for(int i=0; i<3; i++) if (writebacks[i] != -1) b.set(i, JS.N(b.size - i));
+                }
                 // pop the try and catch markers
                 b.add(parserLine,POP);
                 b.add(parserLine,POP);