std::string V8Engine::compileScript(std::string script) { HandleScope handleScope; TryCatch tc; Local<String> source = String::New(script.c_str()); // Compile the source code. Local<Script> code = Script::Compile(source); if (!code.IsEmpty()) return ""; // There were errors, return them std::string ret = ""; Handle<Object> exception = tc.Exception()->ToObject(); String::AsciiValue exception_str(exception); ret += *exception_str; ret += "\n"; Local<Message> message = tc.Message(); ret += *(v8::String::Utf8Value( message->Get() )); ret += "\n"; ret += "Source line: "; ret += *(v8::String::Utf8Value( message->GetSourceLine() )); ret += "\n"; ret += "Source line number: "; ret += Utility::toString(message->GetLineNumber()); ret += "\n"; return ret; }
void JSHandler::done() { if (!done_cb.IsEmpty()) { Local<Value> argv[0] = { }; TryCatch trycatch; Handle<Value> v = done_cb->Call(Context::GetCurrent()->Global(), 0, argv); if (v.IsEmpty()) { Handle<Value> exception = trycatch.Exception(); String::AsciiValue exception_str(exception); printf("Exception: %s\n", *exception_str); exit(1); } } }
void handleException(TryCatch& tc) { Logging::log(Logging::ERROR, "V8 exception:\r\n"); HandleScope handleScope; Handle<Object> exception = tc.Exception()->ToObject(); String::AsciiValue exception_str(exception); Logging::log(Logging::ERROR, " : %s\r\n", *exception_str); /* Handle<Array> names = exception->GetPropertyNames(); for (unsigned int i = 0; i < names->Length(); i++) { std::string strI = Utility::toString((int)i); Logging::log(Logging::ERROR, " %d : %s : %s\r\n", i, *(v8::String::Utf8Value(names->Get(String::New(strI.c_str()))->ToString())), *(v8::String::Utf8Value(exception->Get(names->Get(String::New(strI.c_str()))->ToString())->ToString())) ); } */ Local<Message> message = tc.Message(); Logging::log(Logging::ERROR, "Message: Get: %s\r\n", *(v8::String::Utf8Value( message->Get() ))); Logging::log(Logging::ERROR, "Message: GetSourceLine: %s\r\n", *(v8::String::Utf8Value( message->GetSourceLine() ))); Logging::log(Logging::ERROR, "Message: GetScriptResourceName: %s\r\n", *(v8::String::Utf8Value( message->GetScriptResourceName()->ToString() ))); Logging::log(Logging::ERROR, "Message: GetLineNumber: %d\r\n", message->GetLineNumber() ); Local<Value> stackTrace = tc.StackTrace(); if (!stackTrace.IsEmpty()) { Logging::log(Logging::ERROR, "Stack trace: %s\r\n", *(v8::String::Utf8Value( stackTrace->ToString() ))); printf("\r\n\r\n^Stack trace^: %s\r\n", *(v8::String::Utf8Value( stackTrace->ToString() ))); } else Logging::log(Logging::ERROR, "No stack trace available in C++ handler (see above for possible in-script stack trace)\r\n"); #ifdef SERVER std::string clientMessage = *(v8::String::Utf8Value( message->Get() )); clientMessage += " - "; clientMessage += *(v8::String::Utf8Value( message->GetSourceLine() )); ServerSystem::fatalMessageToClients(clientMessage); #endif // assert(0); throw ScriptException("Bad!"); }
void JSHandler::dispatch_object(const input_iterator& it) { HandleScope scope; switch (it->type()) { case osmium::item_type::node: if (!node_cb.IsEmpty() && (!node_callback_for_tagged_only || !it->tags().empty())) { const int argc = 1; Handle<Value> ext = External::New(new OSMNodeWrap(it)); Local<Object> obj = OSMNodeWrap::constructor->GetFunction()->NewInstance(1, &ext); Local<Value> argv[argc] = { obj }; TryCatch trycatch; Handle<Value> v = node_cb->Call(Context::GetCurrent()->Global(), argc, argv); if (v.IsEmpty()) { Handle<Value> exception = trycatch.Exception(); String::AsciiValue exception_str(exception); printf("Exception: %s\n", *exception_str); exit(1); } } break; case osmium::item_type::way: if (!way_cb.IsEmpty()) { const int argc = 1; Handle<Value> ext = External::New(new OSMWayWrap(it)); Local<Object> obj = OSMWayWrap::constructor->GetFunction()->NewInstance(1, &ext); Local<Value> argv[argc] = { obj }; TryCatch trycatch; Handle<Value> v = way_cb->Call(Context::GetCurrent()->Global(), argc, argv); if (v.IsEmpty()) { Handle<Value> exception = trycatch.Exception(); String::AsciiValue exception_str(exception); printf("Exception: %s\n", *exception_str); exit(1); } } break; case osmium::item_type::relation: if (!relation_cb.IsEmpty()) { const int argc = 1; Handle<Value> ext = External::New(new OSMRelationWrap(it)); Local<Object> obj = OSMRelationWrap::constructor->GetFunction()->NewInstance(1, &ext); Local<Value> argv[argc] = { obj }; TryCatch trycatch; Handle<Value> v = relation_cb->Call(Context::GetCurrent()->Global(), argc, argv); if (v.IsEmpty()) { Handle<Value> exception = trycatch.Exception(); String::AsciiValue exception_str(exception); printf("Exception: %s\n", *exception_str); exit(1); } } break; default: break; } }