bool ExecuteString(v8::Handle<v8::String> source, v8::Handle<v8::Value> name, bool print_result, bool report_exceptions) { v8::HandleScope handle_scope; v8::TryCatch try_catch; v8::Handle<v8::Script> script = v8::Script::Compile(source, name); if (script.IsEmpty()) { // Print errors that happened during compilation. if (report_exceptions) ReportException(&try_catch); return false; } else { v8::Handle<v8::Value> result = script->Run(); if (result.IsEmpty()) { // Print errors that happened during execution. if (report_exceptions) ReportException(&try_catch); return false; } else { if (print_result && !result->IsUndefined()) { // If all went well and the result wasn't undefined then print // the returned value. v8::String::Utf8Value str(result); const char* cstr = ToCString(str); printf("%s\n", cstr); } return true; } } }
/** * Name: ToggleControls(bool showCheckbox, bool showIPEntry) * Desc: Shows or hides the ethernet controls and toggles * the ethernet checkbox and local ID entry, filling * each appropriately. **/ void DeviceSetupDialog::ToggleControls(bool showCheckbox, bool showIPEntry) { if(showCheckbox) { ethernetLabel.ShowWindow(SW_SHOW); ethernetCheck.ShowWindow(SW_SHOW); } else { ethernetLabel.ShowWindow(SW_HIDE); ethernetCheck.ShowWindow(SW_HIDE); } if(showIPEntry) { ethernetCheck.SetCheck(BST_CHECKED); ipAddressLabel.ShowWindow(SW_SHOW); ipEntry.ShowWindow(SW_SHOW); idEntry.EnableWindow(FALSE); // Fill the IP address entry ipEntry.SetWindowText(GetIPAddress()); } else { ethernetCheck.SetCheck(BST_UNCHECKED); ipAddressLabel.ShowWindow(SW_HIDE); ipEntry.ShowWindow(SW_HIDE); idEntry.EnableWindow(TRUE); // Fill the ID entry idEntry.SetWindowText(ToCString(GetID())); } }
v8::Handle<v8::Value> LogD(const v8::Arguments& args) { v8::String::Utf8Value str(args[0]); const char* cstr = ToCString(str); printf("<JS Debug>: %s\n", cstr); return v8::Undefined(); }
void Msg_Struct::build_buffer_arg(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) { if(field_info.field_type == "int8") { int8_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } buffer.write_int8(val); } else if(field_info.field_type == "int16") { int16_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } buffer.write_int16(val); } else if(field_info.field_type == "int32") { int32_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } buffer.write_int32(val); } else if(field_info.field_type == "int64") { int64_t val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } buffer.write_int64(val); } else if(field_info.field_type == "double") { double val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } buffer.write_double(val); } else if(field_info.field_type == "bool") { bool val = 0; if (value->IsBoolean()) { val = value->BooleanValue(isolate->GetCurrentContext()).FromJust(); } buffer.write_bool(val); } else if(field_info.field_type == "string") { std::string val = ""; if (value->IsString()) { String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked()); std::stringstream stream; stream << ToCString(str); val = stream.str(); } buffer.write_string(val); } else { LOG_ERROR("Can not find the field_type:%s, struct_name:%s", field_info.field_type.c_str(), struct_name().c_str()); } }
bool encodeObject(bson *bb, const char *name, v8::Local<v8::Value> element, bool doJson) { v8::Local<v8::Object> object = element->ToObject(); if (doJson) { v8::Local<v8::Value> jsonFun = object->Get( v8::String::NewFromUtf8(isolate, "toJSON", v8::String::kNormalString, 6)); if (!IsEmpty(jsonFun) && jsonFun->IsFunction()) { v8::Local<v8::Value> p = v8::String::NewFromUtf8(isolate, name ? name : ""); v8::Local<v8::Value> element1 = v8::Local<v8::Function>::Cast( jsonFun)->Call(object, 1, &p); if (name) { encodeValue(bb, name, element1, false); return true; } if (!element1->IsObject()) return false; object = element1->ToObject(); } } if (!name && (object->IsDate() || object->IsArray() || object->IsRegExp() || Buffer_base::getInstance(object))) return false; if (name) bson_append_start_object(bb, name); v8::Local<v8::Array> properties = object->GetPropertyNames(); for (int i = 0; i < (int) properties->Length(); i++) { v8::Local<v8::Value> prop_name = properties->Get(i); v8::Local<v8::Value> prop_val = object->Get(prop_name); v8::String::Utf8Value n(prop_name); const char *pname = ToCString(n); encodeValue(bb, pname, prop_val); } if (name) bson_append_finish_object(bb); return true; }
void jsMyClassSetName( Local<String> property, Local<Value> value, const PropertyCallbackInfo<void>& info) { Local<Object> self = info.Holder(); ObjectWrap* pMyClass = ObjectWrap::Unwrap<ObjectWrap>(self); String::Utf8Value str(value); static_cast<MyClass*>(pMyClass)->setName(ToCString(str)); }
result_t throwSyntaxError(TryCatch &try_catch) { v8::String::Utf8Value exception(try_catch.Exception()); v8::Local<v8::Message> message = try_catch.Message(); if (message.IsEmpty()) ThrowError(ToCString(exception)); else { std::string strError; v8::String::Utf8Value filename(message->GetScriptResourceName()); if (qstrcmp(ToCString(exception), "SyntaxError: ", 13)) { strError.append(ToCString(exception)); strError.append("\n at "); } else { strError.append((ToCString(exception) + 13)); strError.append("\n at "); } strError.append(ToCString(filename)); int lineNumber = message->GetLineNumber(); if (lineNumber > 0) { char numStr[32]; strError.append(1, ':'); sprintf(numStr, "%d", lineNumber); strError.append(numStr); strError.append(1, ':'); sprintf(numStr, "%d", message->GetStartColumn() + 1); strError.append(numStr); } return Runtime::setError(strError); } return CALL_E_JAVASCRIPT; }
v8::Handle<v8::Value> InterpreterData::loadJSModule(v8::Isolate* isolate, const char* name) { v8::EscapableHandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = v8::Local<v8::Context>::New(isolate, context); Path file = util::findFile("~/.jshmodules", name); switch (file.type()) { case Path::File: break; case Path::Directory: file += "/module.js"; break; } if (!file.isFile()) return handle_scope.Escape(v8::Local<v8::Value>()); v8::Context::Scope contextScope(ctx); v8::Handle<v8::String> fileName = v8::String::NewFromUtf8(isolate, name); v8::Handle<v8::String> source = v8::String::NewFromUtf8(isolate, file.readAll().constData()); v8::TryCatch try_catch; v8::Handle<v8::Script> script = v8::Script::Compile(source, fileName); if (script.IsEmpty()) { error() << "script" << name << "didn't compile"; return handle_scope.Escape(v8::Local<v8::Value>()); } const v8::Local<v8::Value> result = script->Run(); if (try_catch.HasCaught()) { const v8::Handle<v8::Message> msg = try_catch.Message(); { const v8::String::Utf8Value str(msg->Get()); error() << ToCString(str); } { const v8::String::Utf8Value str(msg->GetScriptResourceName()); error() << String::format<64>("At %s:%d", ToCString(str), msg->GetLineNumber()); } return handle_scope.Escape(v8::Local<v8::Value>()); } return handle_scope.Escape(result); }
static void Require(const v8::FunctionCallbackInfo<v8::Value>& args) { v8::Isolate* isolate = args.GetIsolate(); InterpreterData* interpreter = static_cast<InterpreterData*>(isolate->GetData(0)); v8::HandleScope handle_scope(isolate); v8::Handle<v8::Value> ret; if (args.Length() == 1 && args[0]->IsString()) { v8::String::Utf8Value str(args[0]); ret = interpreter->loadJSModule(isolate, ToCString(str)); if (!ret.IsEmpty()) { args.GetReturnValue().Set(ret); return; } ret = interpreter->loadNativeModule(isolate, ToCString(str)); if (!ret.IsEmpty()) { args.GetReturnValue().Set(ret); return; } } }
void Fragment::Script::ScriptEngine::ReportException(v8::Isolate *isolate, v8::TryCatch *try_catch) { v8::HandleScope handle_scope(isolate); v8::String::Utf8Value exception(try_catch->Exception()); const char *exception_string = ToCString(exception); v8::Local<v8::Message> message = try_catch->Message(); if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // print the exception. fprintf(stderr, "%s\n", exception_string); } else { // Print (filename):(line number): (message). v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName()); v8::Local<v8::Context> context(isolate->GetCurrentContext()); const char *filename_string = ToCString(filename); int linenum = message->GetLineNumber(context).FromJust(); fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string); // Print line of source code. v8::String::Utf8Value sourceline( message->GetSourceLine(context).ToLocalChecked()); const char *sourceline_string = ToCString(sourceline); fprintf(stderr, "%s\n", sourceline_string); // Print wavy underline (GetUnderline is deprecated). int start = message->GetStartColumn(context).FromJust(); for (int i = 0; i < start; i++) { fprintf(stderr, " "); } int end = message->GetEndColumn(context).FromJust(); for (int i = start; i < end; i++) { fprintf(stderr, "^"); } fprintf(stderr, "\n"); v8::Local<v8::Value> stack_trace_string; if (try_catch->StackTrace(context).ToLocal(&stack_trace_string) && stack_trace_string->IsString() && v8::Local<v8::String>::Cast(stack_trace_string)->Length() > 0) { v8::String::Utf8Value stack_trace(stack_trace_string); const char *stack_trace_string = ToCString(stack_trace); fprintf(stderr, "%s\n", stack_trace_string); } } }
void SMJS_Plugin::ReportException(TryCatch* try_catch){ HandleScope handle_scope(isolate); fprintf(stderr, "----------------------------- JAVASCRIPT EXCEPTION -----------------------------"); String::Utf8Value exception(try_catch->Exception()); const char* exception_string = ToCString(exception); Handle<Message> message = try_catch->Message(); if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // print the exception. fprintf(stderr, "%s\n", exception_string); } else { // Print (filename):(line number): (message). String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = ToCString(filename); int linenum = message->GetLineNumber(); fprintf(stderr, "%s:%d: %s\n", filename_string, linenum, exception_string); // Print line of source code. String::Utf8Value sourceline(message->GetSourceLine()); const char* sourceline_string = ToCString(sourceline); fprintf(stderr, "%s\n", sourceline_string); // Print wavy underline (GetUnderline is deprecated). int start = message->GetStartColumn(); for (int i = 0; i < start; i++) { fprintf(stderr, " "); } int end = message->GetEndColumn(); for (int i = start; i < end; i++) { fprintf(stderr, "^"); } fprintf(stderr, "\n"); String::Utf8Value stack_trace(try_catch->StackTrace()); if (stack_trace.length() > 0) { const char* stack_trace_string = ToCString(stack_trace); fprintf(stderr, "%s\n", stack_trace_string); } } fprintf(stderr, "--------------------------------------------------------------------------------"); }
QString Mparse::markdownToHtml(QString markdown) { v8::TryCatch tryCatch; v8::Context::Scope scope(markedContext); QString cmd = QString("marked(\"%1\");").arg(markdown); v8::Handle<v8::String> source = v8::String::New(cmd.toStdString().data()); v8::Handle<v8::Script> script = v8::Script::Compile(source); v8::Handle<v8::Value> result = script->Run(); v8::String::Utf8Value str(result); return QString(ToCString(str)); }
// INSERT THIS AT END OF FILE // The callback that is invoked by v8 whenever the JavaScript 'alert' // function is called. Displays a GTK+ notification. void Alert(const v8::FunctionCallbackInfo<v8::Value>& args) { v8::String::Utf8Value str(args[0]); // Convert first argument to V8 String const char* cstr = ToCString(str); // Convert V8 String to C string Notify::init("Basic"); // Arguments: title, content, icon Notify::Notification n("Alert", cstr, "terminal"); // Display notification n.show(); return; }
void ReportException (v8::TryCatch* try_catch) { v8::HandleScope handle_scope; v8::String::Utf8Value exception(try_catch->Exception()); const char* exception_string = ToCString(exception); v8::Handle<v8::Message> message = try_catch->Message(); if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // print the exception. printf("%s\n", exception_string); } else { // Print (filename):(line number): (message). v8::String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = ToCString(filename); int linenum = message->GetLineNumber(); printf("%s:%i: %s\n", filename_string, linenum, exception_string); // Print line of source code. v8::String::Utf8Value sourceline(message->GetSourceLine()); const char* sourceline_string = ToCString(sourceline); printf("%s\n", sourceline_string); // Print wavy underline (GetUnderline is deprecated). int start = message->GetStartColumn(); for (int i = 0; i < start; i++) { printf(" "); } int end = message->GetEndColumn(); for (int i = start; i < end; i++) { printf("^"); } printf("\n"); v8::String::Utf8Value stack_trace(try_catch->StackTrace()); if (stack_trace.length() > 0) { const char* stack_trace_string = ToCString(stack_trace); printf("%s\n", stack_trace_string); } else { printf("no stack trace available\n"); } } }
int ReportError(TryCatch& try_catch){ cs::String str; HandleScope handle_scope; v8::String::Value exception(try_catch.Exception()); const wchar_t* exception_string = ToCString(exception); Handle<v8::Message> message = try_catch.Message(); if (message.IsEmpty()) { str.Format(L"%s\n",exception_string); } else { cs::String buf; v8::String::Value filename(message->GetScriptResourceName()); const wchar_t* filename_string = ToCString(filename); int linenum = message->GetLineNumber(); buf.Format(L"file:\t%s\r\nline:\t%i\r\n%s\r\n\r\n", filename_string, linenum, exception_string); str += buf; v8::String::Value sourceline(message->GetSourceLine()); const wchar_t* sourceline_string = ToCString(sourceline); buf.Format(L"%s", sourceline_string); int start = message->GetStartColumn(); for (int i = 0; i < start; i++) { //str += L" "; } buf.Insert('^',start); buf.Trim(); str += buf; int end = message->GetEndColumn(); for (int i = start; i < end; i++) { //str += L"^"; } /*str += L"\n"; v8::String::Value stack_trace(try_catch.StackTrace()); if (stack_trace.length() > 0) { const wchar_t* stack_trace_string = ToCString(stack_trace); buf.Format(L"%s\n", stack_trace_string); str += buf; }*/ } return MessageBox(0,str,L"Error",MB_ICONERROR); }
TSTRING MergeSql(const Arguments&args) { String::Utf8Value str(args[0]); const char * pstr = ToCString(str); TSTRING s1; #ifdef OS_WIN32 s1 = encodeConv::CodingConv::Utf82Unicode(pstr); #elif defined OS_LINUX s1 = pstr; #endif vector<TSTRING> vc; int length = args.Length(); if (args[length-1]->IsFunction()) { length -= 1; } for(int i = 1; i<length;i++) { String::Utf8Value str1(args[i]); const char * pstr_tmp = ToCString(str1); //cout<<"pstr_tmp:"<<pstr_tmp<<endl; TSTRING tmp; #ifdef OS_WIN32 tmp = encodeConv::CodingConv::Utf82Unicode(pstr_tmp); #elif defined OS_LINUX tmp = pstr_tmp; #endif vc.push_back(tmp); } TSTRING sql=Replace(s1,_T("?"),vc); return sql; }
void Msg_Struct::build_http_msg_buffer(Isolate* isolate, v8::Local<v8::Object> object, std::string &str) { std::stringstream stream; for(std::vector<Field_Info>::const_iterator iter = field_vec().begin(); iter != field_vec().end(); iter++) { stream.str(""); stream << "\"" << iter->field_name << "\":"; Local<Value> value = object->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); if(iter->field_type == "int8" || iter->field_type == "int16" || iter->field_type == "int32") { int32_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "int64") { int64_t val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "double") { double val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "bool") { bool val = 0; if (value->IsBoolean()) { val = value->BooleanValue(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "string") { if (value->IsString()) { String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked()); stream << "\"" << ToCString(str) << "\","; } else { stream << "\"\","; } } else { LOG_ERROR("Can not find the field_type:%s, struct_name:%s", iter->field_type.c_str(), struct_name().c_str()); } str += stream.str(); } }
void ReportException(const v8::TryCatch& try_catch, OutT& out) { v8::HandleScope handle_scope; v8::String::Utf8Value exception(try_catch.Exception()); const char* exception_string = ToCString(exception); v8::Handle<v8::Message> message = try_catch.Message(); if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // print the exception. out << exception_string << std::endl; } else { // Print (filename):(line number): (message). v8::String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = ToCString(filename); int linenum = message->GetLineNumber(); out << filename_string << ":" << linenum << ": " << exception_string << std::endl; // Print line of source code. v8::String::Utf8Value sourceline(message->GetSourceLine()); const char* sourceline_string = ToCString(sourceline); out << sourceline_string << std::endl; // Print wavy underline (GetUnderline is deprecated). int start = message->GetStartColumn(); for (int i = 0; i < start; i++) { out << (" "); } int end = message->GetEndColumn(); for (int i = start; i < end; i++) { out << ("^"); } out << std::endl; } }
void nsCommentNode::List(FILE* out, int32_t aIndent) const { int32_t indx; for (indx = aIndent; --indx >= 0; ) fputs(" ", out); fprintf(out, "Comment@%p refcount=%d<!--", (void*)this, mRefCnt.get()); nsAutoString tmp; ToCString(tmp, 0, mText.GetLength()); fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); fputs("-->\n", out); }
void nsXMLCDATASection::List(FILE* out, int32_t aIndent) const { int32_t index; for (index = aIndent; --index >= 0; ) fputs(" ", out); fprintf(out, "CDATASection refcount=%d<", mRefCnt.get()); nsAutoString tmp; ToCString(tmp, 0, mText.GetLength()); fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); fputs(">\n", out); }
inline Value InterpreterData::v8ValueToValue(const v8::Handle<v8::Value>& value) { if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) return Value(); else if (value->IsTrue()) return Value(true); else if (value->IsFalse()) return Value(false); else if (value->IsInt32()) return Value(value->ToInt32()->Value()); else if (value->IsNumber()) return Value(value->ToNumber()->Value()); else if (value->IsString()) { const v8::String::Utf8Value str(value); return Value(ToCString(str)); } else if (value->IsObject()) { const v8::String::Utf8Value str(toJSON(value)); return Value::fromJSON(ToCString(str)); } else { error() << "Unknown v8 value in Interpreter::v8ValueToValue"; } return Value(); }
std::string GetException(TryCatch &try_catch, result_t hr) { if (try_catch.HasCaught()) { v8::String::Utf8Value exception(try_catch.Exception()); v8::Local<v8::Message> message = try_catch.Message(); if (message.IsEmpty()) return ToCString(exception); else { v8::Local<v8::Value> trace_value = try_catch.StackTrace(); if (!IsEmpty(trace_value)) { v8::String::Utf8Value stack_trace(trace_value); return ToCString(stack_trace); } std::string strError; v8::String::Utf8Value filename(message->GetScriptResourceName()); if (qstrcmp(ToCString(exception), "SyntaxError: ", 13)) { strError.append(ToCString(exception)); strError.append("\n at "); } else { strError.append((ToCString(exception) + 13)); strError.append("\n at "); } strError.append(ToCString(filename)); int lineNumber = message->GetLineNumber(); if (lineNumber > 0) { char numStr[32]; strError.append(1, ':'); sprintf(numStr, "%d", lineNumber); strError.append(numStr); strError.append(1, ':'); sprintf(numStr, "%d", message->GetStartColumn() + 1); strError.append(numStr); } return strError; } } else if (hr < 0) return getResultMessage(hr); return ""; }
void jsMyFunction1(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 1) { args.GetIsolate()->ThrowException( String::NewFromUtf8(args.GetIsolate(), "Bad parameters", NewStringType::kNormal).ToLocalChecked()); return; } String::Utf8Value str(args[0]); const char* cstr = ToCString(str); myFunction1(cstr); }
void nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const { PRInt32 index; for (index = aIndent; --index >= 0; ) fputs(" ", out); fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get()); nsAutoString tmp; ToCString(tmp, 0, mText.GetLength()); tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0); fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); fputs(">\n", out); }
void timestep_view_set_filterColor(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { //LOG("in timestep_view set filterColor"); v8::Local<v8::Object> thiz = info.Holder(); timestep_view *obj = (timestep_view*) v8::Local<v8::External>::Cast(thiz->GetInternalField(0))->Value(); if (value->IsString()) { String::Utf8Value s(value); const char *str = ToCString(s); rgba color; rgba_parse(&color, str); obj->filter_color = color; } //LOG("done in timestep_view set filterColor"); }
void nsCommentNode::List(FILE* out, PRInt32 aIndent) const { NS_PRECONDITION(IsInDoc(), "bad content"); PRInt32 indx; for (indx = aIndent; --indx >= 0; ) fputs(" ", out); fprintf(out, "Comment@%p refcount=%d<!--", this, mRefCnt.get()); nsAutoString tmp; ToCString(tmp, 0, mText.GetLength()); fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs("-->\n", out); }
void nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const { NS_PRECONDITION(IsInDoc(), "bad content"); PRInt32 index; for (index = aIndent; --index >= 0; ) fputs(" ", out); fprintf(out, "CDATASection refcount=%d<", mRefCnt.get()); nsAutoString tmp; ToCString(tmp, 0, mText.GetLength()); fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out); fputs(">\n", out); }
// The callback that is invoked by v8 whenever the JavaScript 'print' // function is called. Prints its arguments on stdout separated by // spaces and ending with a newline. void Fragment::Script::ScriptEngine::Print(const v8::FunctionCallbackInfo<v8::Value> &args) { bool first = true; for (int i = 0; i < args.Length(); i++) { v8::HandleScope handle_scope(args.GetIsolate()); if (first) { first = false; } else { printf(" "); } v8::String::Utf8Value str(args[i]); const char *cstr = ToCString(str); printf("%s", cstr); } printf("\n"); fflush(stdout); }
void get_master_player_by_name(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 1) { LOG_ERROR("get_master_player_by_name args error, length: %d\n", args.Length()); args.GetReturnValue().SetNull(); return; } String::Utf8Value str(args[0]); std::string role_name(ToCString(str)); Master_Player *player = MASTER_MANAGER->find_role_name_master_player(role_name); if (player) { args.GetReturnValue().Set(wrap_master_player(args.GetIsolate(), player)); } else { //设置对象为空 args.GetReturnValue().SetNull(); } }
void jsMyClassMethod2(const FunctionCallbackInfo<Value>& args) { if (args.Length() != 1) { args.GetIsolate()->ThrowException( String::NewFromUtf8(args.GetIsolate(), "Bad parameters", NewStringType::kNormal).ToLocalChecked()); return; } String::Utf8Value str(args[0]); const char* cstr = ToCString(str); Local<Object> self = args.Holder(); ObjectWrap* pMyClass = ObjectWrap::Unwrap<ObjectWrap>(self); pMyClass->Method2(cstr); }