#include "globals.h" #include "V8Script.h" #include "V8Wrappers.h" #include using namespace v8; #ifdef UNICODE # define V8_TCHAR uint16_t #else # define V8_TCHAR char #endif V8Wrappers *wrappers = NULL; void V8Script::initializeEngine() { if (wrappers != NULL) return; wrappers = new V8Wrappers(); } V8Script::V8Script() : exceptionCallback(NULL), exceptionCallbackParam(NULL) { } V8Script::~V8Script() { dispose(); } bool V8Script::compile(const TCHAR *source, Dialog *dlg) { dispose(); HandleScope handle_scope; context = Context::New(NULL, wrappers->getGlobalTemplate()); Context::Scope context_scope(context); context->Global()->Set(String::New("window"), wrappers->newDialogState(), ReadOnly); context->Global()->Set(String::New("opts"), wrappers->newOptions(), ReadOnly); context->Global()->Set(String::New("info"), wrappers->newDialogInfo(), ReadOnly); for(unsigned int i = 0; i < dlg->getFieldCount(); i++) { Field *field = dlg->getField(i); context->Global()->Set(String::New(field->getName()), wrappers->newState(field->getType()), ReadOnly); } TryCatch try_catch; Local