Javascript interpreter supports for JSC and V8 simultaneously.
Before, one had to build two different versions.
This commit is contained in:
parent
008adca72f
commit
caa6827daf
5 changed files with 40 additions and 15 deletions
|
|
@ -29,15 +29,9 @@ int main(int argc, char* argv[]) {
|
|||
std::string module_name(argv[idx]);
|
||||
module_names.push_back(module_name);
|
||||
} else if(strcmp(argv[idx], "-v8") == 0) {
|
||||
#ifndef USE_V8
|
||||
std::cerr << "V8 support is not enabled" << std::endl;
|
||||
exit(-1);
|
||||
#endif
|
||||
shell = JSShell::Create(JSShell::V8);
|
||||
} else if(strcmp(argv[idx], "-jsc") == 0) {
|
||||
#ifndef USE_JSC
|
||||
std::cerr << "JSC support is not enabled" << std::endl;
|
||||
exit(-1);
|
||||
#endif
|
||||
shell = JSShell::Create(JSShell::JSC);
|
||||
} else if(strcmp(argv[idx], "-i") == 0) {
|
||||
interactive = true;
|
||||
} else {
|
||||
|
|
@ -45,7 +39,9 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
shell = JSShell::Create();
|
||||
if (shell == 0) {
|
||||
shell = JSShell::Create();
|
||||
}
|
||||
|
||||
bool failed = false;
|
||||
for(std::vector<std::string>::iterator it = module_names.begin();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
#error "implement dll loading"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
JSShell::~JSShell() {
|
||||
|
||||
for(std::vector<HANDLE>::iterator it = loaded_modules.begin();
|
||||
|
|
@ -93,3 +95,32 @@ std::string JSShell::ReadFile(const std::string& fileName)
|
|||
|
||||
return script;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_JSC
|
||||
extern JSShell* JSCShell_Create();
|
||||
#endif
|
||||
#ifdef ENABLE_V8
|
||||
extern JSShell* V8Shell_Create();
|
||||
#endif
|
||||
|
||||
typedef JSShell*(*ShellFactory)();
|
||||
|
||||
static ShellFactory js_shell_factories[2] = {
|
||||
#ifdef ENABLE_JSC
|
||||
JSCShell_Create,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
#ifdef ENABLE_V8
|
||||
V8Shell_Create,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
};
|
||||
|
||||
JSShell *JSShell::Create(Engine engine) {
|
||||
if(js_shell_factories[engine] == 0) {
|
||||
throw "Engine not supported.";
|
||||
}
|
||||
return js_shell_factories[engine]();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class JSShell {
|
|||
|
||||
public:
|
||||
enum Engine {
|
||||
JSC,
|
||||
JSC = 0,
|
||||
V8
|
||||
};
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ public:
|
|||
|
||||
virtual ~JSShell() = 0;
|
||||
|
||||
static JSShell* Create();
|
||||
static JSShell* Create(Engine engine = JSC);
|
||||
|
||||
bool ImportModule(const std::string& name);
|
||||
|
||||
|
|
@ -46,6 +46,4 @@ protected:
|
|||
|
||||
};
|
||||
|
||||
typedef JSShell* (*JSShellFactory)();
|
||||
|
||||
#endif // JS_SHELL_H
|
||||
|
|
|
|||
|
|
@ -160,6 +160,6 @@ void JSCShell::PrintError(JSContextRef ctx, JSValueRef err, const std::string& n
|
|||
std::cerr << name << ":" << line << ":" << errMsg << std::endl;
|
||||
}
|
||||
|
||||
JSShell* JSShell::Create() {
|
||||
JSShell* JSCShell_Create() {
|
||||
return new JSCShell();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,6 +285,6 @@ const char* V8Shell::ToCString(const v8::String::Utf8Value& value) {
|
|||
return *value ? *value : "<string conversion failed>";
|
||||
}
|
||||
|
||||
JSShell* JSShell::Create() {
|
||||
JSShell* V8Shell_Create() {
|
||||
return new V8Shell();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue