summaryrefslogtreecommitdiff
path: root/Tools/javascript/javascript.cxx
blob: 5e7cc0b2076bc9004e2d32982e03c6af4511d13d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>

#include "js_shell.h"

void print_usage() {
  std::cout << "javascript [-i] [-jsc|-v8] [-l module] <js-file>" << std::endl;
}

int main(int argc, char* argv[]) {

#if defined(JAVASCRIPT_INTERPRETER_STOP)
  std::cout << "Attach your Debugger and press any key to continue" << std::endl;
  std::cin.get();
#endif

  std::string scriptPath = "";

  bool interactive = false;
  JSShell* shell = 0;

  std::vector<std::string> modulePath;
  modulePath.push_back(".");

  for (int idx = 1; idx < argc; ++idx) {
    if(strcmp(argv[idx], "-v8") == 0) {
      shell = JSShell::Create(JSShell::V8);
    } else if(strcmp(argv[idx], "-jsc") == 0) {
      shell = JSShell::Create(JSShell::JSC);
    } else if(strcmp(argv[idx], "-i") == 0) {
      interactive = true;
    } else if(strcmp(argv[idx], "-L") == 0) {
      modulePath.push_back(argv[++idx]);
    } else {
      scriptPath = argv[idx];
    }
  }

  if (shell == 0) {
    shell = JSShell::Create();
  }

  shell->setModulePath(modulePath);

  bool failed = false;

  if(interactive) {
    failed = !(shell->RunShell());
  } else {
    failed = !(shell->RunScript(scriptPath));
  }

  if (failed) {
    delete shell;
    printf("FAIL: Error during execution of script.\n");
    return 1;
  }

  delete shell;

  return 0;
}