浏览代码

js: Make printing of the last result optional

Andreas Kling 5 年之前
父节点
当前提交
12b8cd8c10
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      Userland/js.cpp

+ 4 - 1
Userland/js.cpp

@@ -42,10 +42,12 @@ int main(int argc, char** argv)
 {
     bool dump_ast = false;
     bool gc_on_every_allocation = false;
+    bool print_last_result = false;
     const char* script_path = nullptr;
 
     Core::ArgsParser args_parser;
     args_parser.add_option(dump_ast, "Dump the AST", "ast-dump", 'A');
+    args_parser.add_option(dump_ast, "Print last result", "print-last-result", 'l');
     args_parser.add_option(gc_on_every_allocation, "GC on every allocation", "gc-on-every-allocation", 'g');
     args_parser.add_positional_argument(script_path, "Path to script file", "script");
     args_parser.parse(argc, argv);
@@ -80,7 +82,8 @@ int main(int argc, char** argv)
     auto result = interpreter.run(*program);
     dbg() << "Interpreter returned " << result;
 
-    printf("%s\n", result.to_string().characters());
+    if (print_last_result)
+        printf("%s\n", result.to_string().characters());
 
     dbg() << "Collecting garbage on exit...";
     interpreter.heap().collect_garbage();