示例#1
0
文件: Repl.java 项目: afeinberg/dynjs
 public void run() {
   ConsoleReader console = null;
   try {
     console = new ConsoleReader(in, out);
     console.println(WELCOME_MESSAGE);
     String statement = null;
     while ((statement = console.readLine(PROMPT)) != null) {
       if ("exit".equals(statement.trim())) {
         return;
       } else {
         try {
           dynJS.eval(context, statement);
         } catch (DynJSException e) {
           console.println(e.getClass().getSimpleName());
           console.println(e.getLocalizedMessage());
           console.println("Error parsing statement: " + statement.toString());
         } catch (Exception e) {
           e.printStackTrace(new PrintWriter(out));
         }
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
示例#2
0
 private void check(String scriptlet, Object expected) {
   dynJS.eval(context, scriptlet);
   Object result = context.getScope().resolve("result");
   assertThat(result).isEqualTo(expected);
 }