Refactored custom javascript engines to support primitive 'require' statements.

This commit is contained in:
Oliver Buchtala 2013-09-06 00:38:07 +03:00
commit 4794fa1884
5 changed files with 203 additions and 131 deletions

View file

@ -14,21 +14,12 @@ void print_usage() {
int main(int argc, char* argv[]) {
std::string scriptPath = "";
std::vector<std::string> module_names;
bool interactive = false;
JSShell* shell = 0;
for (int idx = 1; idx < argc; ++idx) {
if(strcmp(argv[idx], "-l") == 0) {
idx++;
if(idx > argc) {
print_usage();
exit(-1);
}
std::string module_name(argv[idx]);
module_names.push_back(module_name);
} else if(strcmp(argv[idx], "-v8") == 0) {
if(strcmp(argv[idx], "-v8") == 0) {
shell = JSShell::Create(JSShell::V8);
} else if(strcmp(argv[idx], "-jsc") == 0) {
shell = JSShell::Create(JSShell::JSC);
@ -44,19 +35,6 @@ int main(int argc, char* argv[]) {
}
bool failed = false;
for(std::vector<std::string>::iterator it = module_names.begin();
it != module_names.end(); ++it) {
std::string module_name = *it;
bool success = shell->ImportModule(module_name);
failed |= !success;
}
if (failed) {
delete shell;
printf("FAIL: Some modules could not be loaded.\n");
return -1;
}
if(interactive) {
failed = !(shell->RunShell());