当前位置: 首页>>代码示例>>C++>>正文


C++ Handle::GetLineNumber方法代码示例

本文整理汇总了C++中Handle::GetLineNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::GetLineNumber方法的具体用法?C++ Handle::GetLineNumber怎么用?C++ Handle::GetLineNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Handle的用法示例。


在下文中一共展示了Handle::GetLineNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: exception

    std::ostream& operator<<( std::ostream &s, const v8::TryCatch * try_catch ){
        HandleScope handle_scope;
        v8::String::Utf8Value exception(try_catch->Exception());
        Handle<v8::Message> message = try_catch->Message();
    
        if (message.IsEmpty()) {
            s << *exception << endl;
        } 
        else {

            v8::String::Utf8Value filename(message->GetScriptResourceName());
            int linenum = message->GetLineNumber();
            cout << *filename << ":" << linenum << " " << *exception << endl;

            v8::String::Utf8Value sourceline(message->GetSourceLine());
            cout << *sourceline << endl;

            int start = message->GetStartColumn();
            for (int i = 0; i < start; i++)
                cout << " ";

            int end = message->GetEndColumn();
            for (int i = start; i < end; i++)
                cout << "^";

            cout << endl;
        }    

        //if ( try_catch->next_ ) // disabled for v8 bleeding edge
        //    s << try_catch->next_;

        return s;
    }
开发者ID:lizalbin,项目名称:mongo,代码行数:33,代码来源:v8_utils.cpp

示例2:

void V8Util::openJSErrorDialog(TryCatch &tryCatch)
{
	JNIEnv *env = JNIUtil::getJNIEnv();
	if (!env) {
		return;
	}

	Handle<Message> message = tryCatch.Message();

	jstring title = env->NewStringUTF("Runtime Error");
	jstring errorMessage = TypeConverter::jsValueToJavaString(message->Get());
	jstring resourceName = TypeConverter::jsValueToJavaString(message->GetScriptResourceName());
	jstring sourceLine = TypeConverter::jsValueToJavaString(message->GetSourceLine());

	env->CallStaticVoidMethod(
		JNIUtil::krollRuntimeClass,
		JNIUtil::krollRuntimeDispatchExceptionMethod,
		title,
		errorMessage,
		resourceName,
		message->GetLineNumber(),
		sourceLine,
		message->GetEndColumn());

	env->DeleteLocalRef(title);
	env->DeleteLocalRef(errorMessage);
	env->DeleteLocalRef(resourceName);
	env->DeleteLocalRef(sourceLine);

}
开发者ID:1rp,项目名称:titanium_mobile,代码行数:30,代码来源:V8Util.cpp

示例3: msV8ReportException

/* Handler for Javascript Exceptions. Not exposed to JavaScript, used internally.
   Most of the code from v8 shell example.
*/
void msV8ReportException(TryCatch* try_catch, const char *msg = "")
{
  HandleScope handle_scope;

  if (!try_catch || !try_catch->HasCaught()) {
    msSetError(MS_V8ERR, "%s.", "msV8ReportException()", msg);
    return;
  }

  String::Utf8Value exception(try_catch->Exception());
  const char* exception_string = *exception;
  Handle<Message> message = try_catch->Message();
  if (message.IsEmpty()) {
    msSetError(MS_V8ERR, "Javascript Exception: %s.", "msV8ReportException()",
               exception_string);
  } else {
    String::Utf8Value filename(message->GetScriptResourceName());
    const char* filename_string = *filename;
    int linenum = message->GetLineNumber();
    msSetError(MS_V8ERR, "Javascript Exception: %s:%i: %s", "msV8ReportException()",
               filename_string, linenum, exception_string);
    String::Utf8Value sourceline(message->GetSourceLine());
    const char* sourceline_string = *sourceline;
    msSetError(MS_V8ERR, "Exception source line: %s", "msV8ReportException()",
               sourceline_string);
    String::Utf8Value stack_trace(try_catch->StackTrace());
    if (stack_trace.length() > 0) {
      const char* stack_trace_string = *stack_trace;
      msSetError(MS_V8ERR, "Exception StackTrace: %s", "msV8ReportException()",
                 stack_trace_string);
    }
  }
}
开发者ID:BentleySystems,项目名称:mapserver,代码行数:36,代码来源:mapv8.cpp

示例4: GetExtendLocation

bool MetadataNode::GetExtendLocation(string& extendLocation)
{
	stringstream extendLocationStream;
	Local<StackTrace> stackTrace = StackTrace::CurrentStackTrace(Isolate::GetCurrent(), 1, StackTrace::kOverview);
	if (!stackTrace.IsEmpty())
	{
		Handle<StackFrame> frame = stackTrace->GetFrame(0);
		if (!frame.IsEmpty())
		{
			auto scriptName = frame->GetScriptName();
			if (scriptName.IsEmpty())
			{
				extendLocationStream << "unkown location";
				extendLocation = extendLocationStream.str();
				return false;
			}

			string srcFileName = ConvertToString(scriptName);

			string hardcodedPathToSkip = Constants::APP_ROOT_FOLDER_PATH;

			int startIndex = hardcodedPathToSkip.length();
			int strToTakeLen = (srcFileName.length() - startIndex - 3); // 3 refers to .js at the end of file name
			string fullPathToFile = srcFileName.substr(startIndex, strToTakeLen);

			std::replace(fullPathToFile.begin(), fullPathToFile.end(), '/', '_');
			std::replace(fullPathToFile.begin(), fullPathToFile.end(), '.', '_');
			int lineNumber = frame->GetLineNumber();
			if (lineNumber < 0)
			{
				extendLocationStream << fullPathToFile.c_str() << " unkown line number";
				extendLocation = extendLocationStream.str();
				return false;
			}

			if (lineNumber > Constants::MODULE_LINES_OFFSET)
			{
				lineNumber -= Constants::MODULE_LINES_OFFSET;
			}

			int column = frame->GetColumn();
			if (column < 0)
			{
				extendLocationStream << fullPathToFile.c_str() << " line:" << lineNumber << " unkown column number";
				extendLocation = extendLocationStream.str();
				return false;
			}


			extendLocationStream << "f" << fullPathToFile.c_str() << "_l" << lineNumber << "_c" << column << "__";
			//DEBUG_WRITE("EXTEND_LOCATION %s", extendLocationStream.str().c_str());
		}
	}

	extendLocation = extendLocationStream.str();
	return true;
}
开发者ID:frodoking,项目名称:NativeScriptAndroidRuntime,代码行数:57,代码来源:MetadataNode.cpp

示例5:

static void logV8Exception(Handle<Message> msg, Handle<Value> data)
{
	HandleScope scope;

	// Log reason and location of the error.
	LOGD(TAG, *String::Utf8Value(msg->Get()));
	LOGD(TAG, "%s @ %d >>> %s",
		*String::Utf8Value(msg->GetScriptResourceName()),
		msg->GetLineNumber(),
		*String::Utf8Value(msg->GetSourceLine()));
}
开发者ID:EnochManohar,项目名称:titanium_mobile,代码行数:11,代码来源:V8Runtime.cpp

示例6: ReportException

void ReportException(TryCatch* tryCatch)
{
    //	HandleScope handleScope;
    
	String::Utf8Value exception(tryCatch->Exception());
	const char* exceptionString = ToCString(exception);
	Handle<Message> message = tryCatch->Message();
    
	if (message.IsEmpty()) {
		// V8 didn't provide any extra information about this error; just
		// print the exception.
		throw  std::runtime_error("Unknown error "+ std::string(exceptionString));
        
	} else {
		// Print (filename):(line number): (message).
		String::Utf8Value filename(message->GetScriptResourceName());
		const char* filenameString = ToCString(filename);
		int linenum = message->GetLineNumber();
        
        std::stringstream ss;
        
        // Print filename and linenum if applicable
        if(!message->GetScriptResourceName()->IsUndefined()) {
            ss << filenameString <<":"<< linenum <<" ";
        }
        
		ss << exceptionString << std::endl;
        
		// Print line of source code.
		String::Utf8Value sourceline(message->GetSourceLine());
		const char* sourceline_string = ToCString(sourceline);
        
		ss << sourceline_string << std::endl;
        
		// Print wavy underline (GetUnderline is deprecated).
		int start = message->GetStartColumn();
		for (int i = 0; i < start; i++) {
			ss << " ";
		}
		int end = message->GetEndColumn();
		for (int i = start; i < end; i++) {
			ss << "^";
		}
		ss << std::endl;
        
		String::Utf8Value stack_trace(tryCatch->StackTrace());
		if (stack_trace.length() > 0) {
			const char* stack_trace_string = ToCString(stack_trace);
			ss << stack_trace_string;
		}
        
        throw std::runtime_error(ss.str());
	}
}
开发者ID:audionerd,项目名称:FieldKit.cpp,代码行数:54,代码来源:ScriptContext.cpp

示例7: report_error

void report_error(TryCatch * err) {
  String::Utf8Value exception(err->Exception());
  String::Utf8Value stack(err->StackTrace());
  Handle<Message> message = err->Message();
  fprintf(stderr, "%s\n", *exception);
  if(! message.IsEmpty()) {
    String::Utf8Value file(message->GetScriptResourceName());
    int line = message->GetLineNumber();
    fprintf(stderr, "%s:%d\n", *file, line);
  }
  if(stack.length() > 0) 
    fprintf(stderr, "%s\n", *stack);
}
开发者ID:alMysql,项目名称:mysql-js,代码行数:13,代码来源:async_common.cpp

示例8: DisplayExceptionLine

void DisplayExceptionLine (TryCatch &try_catch, std::string& err_msg) {
  // Prevent re-entry into this function.
  static bool displayed_error = false;

  if (displayed_error) return;
  displayed_error = true;

  HandleScope scope;

  Handle<Message> message = try_catch.Message();

  fprintf(stderr, "\n");
  err_msg = "JavaScript Exception\n\n";

  if (!message.IsEmpty()) {
    // Print (filename):(line number): (message).
    String::Utf8Value filename(message->GetScriptResourceName());
    const char* filename_string = *filename;
    int linenum = message->GetLineNumber();
    fprintf(stderr, "%s:%i\n", filename_string, linenum);
    err_msg += filename_string;
    err_msg += ":";
    char num_conv[10];
    sprintf(num_conv, "%i", linenum);
    err_msg += num_conv;
    err_msg += "\n";
    // Print line of source code.
    String::Utf8Value sourceline(message->GetSourceLine());
    const char* sourceline_string = *sourceline;

    int start = message->GetStartColumn();
    int end = message->GetEndColumn();

    // fprintf(stderr, "---\nsourceline:%s\noffset:%d\nstart:%d\nend:%d\n---\n", sourceline_string, start, end);

    fprintf(stderr, "%s\n", sourceline_string);
    err_msg += sourceline_string;
    err_msg += "\n";
    // Print wavy underline (GetUnderline is deprecated).
    for (int i = 0; i < start; i++) {
      fputc((sourceline_string[i] == '\t') ? '\t' : ' ', stderr);
    }
    for (int i = start; i < end; i++) {
      fputc('^', stderr);
    }
    fputc('\n', stderr);
    err_msg += "\n";
  }
}
开发者ID:HazemKhaled,项目名称:titanium_mobile_blackberry,代码行数:49,代码来源:V8Utils.cpp

示例9: ReportException

   ////////////////////////////////////////////////////////////////////////////////
   // lifted from node.js file node.cc
   void ReportException(TryCatch *try_catch) 
   {
        
	  HandleScope scope;

      Handle<Message> message = try_catch->Message();
	  std::string filename_string = "";
	  std::string sourceline_string = "";
	  int linenum = 0;
	  int start = 0;
	  int end = 0;

      if (!message.IsEmpty()) {
       
         String::Utf8Value filename(message->GetScriptResourceName());
         filename_string = *filename;
         linenum = message->GetLineNumber();       
         String::Utf8Value sourceline(message->GetSourceLine());
         sourceline_string = *sourceline;
         start = message->GetStartColumn();       
         end = message->GetEndColumn();

      }

     String::Utf8Value trace(try_catch->StackTrace());
     std::string tracestr;

     if(trace.length() != 0)
     {
         tracestr = *trace;
     }
     
	  std::ostringstream os;
     os << std::endl << sourceline_string << std::endl;	  

	  for (int i = 0; i < start; i++) 
	  {
         os << " ";
	  }
	  for (int i = start; i < end; i++) 
	  {
         os << "^";
      }

     os << tracestr << "\n";
	 
	  std::string msg = os.str();
      dtEntity::LogManager::GetInstance().LogMessage(dtEntity::LogLevel::LVL_ERROR, filename_string, "", linenum, msg);     
   }
开发者ID:flyskyosg,项目名称:dtentity,代码行数:51,代码来源:v8helpers.cpp

示例10: set_perl_error

void set_perl_error(const TryCatch& try_catch) {
    Handle<Message> msg = try_catch.Message();

    char message[1024];
    snprintf(
        message,
        1024,
        "%s at %s:%d",
        *(String::Utf8Value(try_catch.Exception())),
        !msg.IsEmpty() ? *(String::AsciiValue(msg->GetScriptResourceName())) : "EVAL",
        !msg.IsEmpty() ? msg->GetLineNumber() : 0
    );

    sv_setpv(ERRSV, message);
    sv_utf8_upgrade(ERRSV);
}
开发者ID:nordicdyno,项目名称:javascript-v8,代码行数:16,代码来源:V8Context.cpp

示例11: stringifyException

std::string stringifyException(const v8::TryCatch& try_catch, bool suppressBacktrace) {
	HandleScope scope;
	std::string output = "";

	Handle<Message> message = try_catch.Message();
	if (suppressBacktrace || message.IsEmpty()) {

		std::string exception_string = V8::stringToStdString(try_catch.Exception().As<String>());

		// V8 didn't provide any extra information about this error; just
		// print the exception.
		output += exception_string;
		output += "\n";

	} else {

		// filename:line
		output += V8::stringToStdString(
			message->GetScriptResourceName().As<String>()
		) + ":" + boost::lexical_cast<std::string>(
			message->GetLineNumber()
		) + "\n";

		// Print line of source code.
		output += V8::stringToStdString(message->GetSourceLine()) + "\n";

		// Print wavy underline (GetUnderline is deprecated).
		int start = message->GetStartColumn();
		for (int i = 0; i < start; i++) {
			output += " ";
		}
		int end = message->GetEndColumn();
		for (int i = start; i < end; i++) {
			output += "^";
		}
		output += "\n";

		// Print out the stack trace.
		std::string stackTrace = V8::stringToStdString(try_catch.StackTrace().As<String>());
		if (stackTrace.length() > 0) {
			output += stackTrace + "\n";
		}
	}

	return output;
}
开发者ID:cha0s,项目名称:avocado-spi-v8,代码行数:46,代码来源:avocado-v8.cpp

示例12:

  ~ScriptScopeImpl ()
  {
    GumScriptPrivate * priv = parent->priv;

    if (trycatch.HasCaught ())
    {
      Handle<Message> message = trycatch.Message ();
      Handle<Value> exception = trycatch.Exception ();
      String::Utf8Value exception_str (exception);
      gchar * exception_str_escaped = g_strescape (*exception_str, "");
      gchar * error = g_strdup_printf (
          "{\"type\":\"error\",\"lineNumber\":%d,\"description\":\"%s\"}",
          message->GetLineNumber (), exception_str_escaped);
      _gum_script_core_emit_message (&priv->core, error, NULL, 0);
      g_free (exception_str_escaped);
      g_free (error);
    }
  }
开发者ID:lq10secboy,项目名称:frida-gum,代码行数:18,代码来源:gumscript.cpp

示例13: GetExceptionInfo

const string JSMain::GetExceptionInfo(Isolate* isolate, TryCatch* try_catch)
{
	HandleScope handle_scope(isolate);
	String::Utf8Value exception(try_catch->Exception());
	const char *exception_string = js_safe_str(*exception);
	Handle<Message> message = try_catch->Message();
	string res;

	if (message.IsEmpty()) {
		// V8 didn't provide any extra information about this error; just return the exception.
		res = exception_string;
	} else {
		String::Utf8Value filename(message->GetScriptResourceName());
		const char *filename_string = js_safe_str(*filename);
		int linenum = message->GetLineNumber();

		ostringstream ss;

		ss << filename_string << ":" << linenum << ": " << exception_string << "\r\n";
		
		// Print line of source code.
		String::Utf8Value sourceline(message->GetSourceLine());
		const char *sourceline_string = js_safe_str(*sourceline);

		ss << sourceline_string << "\r\n";

		// Print wavy underline.
		int start = message->GetStartColumn();

		for (int i = 0; i < start; i++) {
			ss << " ";
		}

		int end = message->GetEndColumn();

		for (int i = start; i < end; i++) {
			ss << "^";
		}

		res = ss.str();
	}

	return res;
}
开发者ID:lzcykevin,项目名称:FreeSWITCH,代码行数:44,代码来源:jsmain.cpp

示例14: filename

void V8Util::reportException(TryCatch &tryCatch, bool showLine)
{
	HandleScope scope;
	Handle<Message> message = tryCatch.Message();

	if (nameSymbol.IsEmpty()) {
		nameSymbol = SYMBOL_LITERAL("name");
		messageSymbol = SYMBOL_LITERAL("message");
	}

	if (showLine) {
		Handle<Message> message = tryCatch.Message();
		if (!message.IsEmpty()) {
			String::Utf8Value filename(message->GetScriptResourceName());
			String::Utf8Value msg(message->Get());
			int linenum = message->GetLineNumber();
			LOGE(EXC_TAG, "Exception occurred at %s:%i: %s", *filename, linenum, *msg);
		}
	}

	Local<Value> stackTrace = tryCatch.StackTrace();
	String::Utf8Value trace(tryCatch.StackTrace());

	if (trace.length() > 0 && !stackTrace->IsUndefined()) {
		LOGD(EXC_TAG, *trace);
	} else {
		Local<Value> exception = tryCatch.Exception();
		if (exception->IsObject()) {
			Handle<Object> exceptionObj = exception->ToObject();
			Handle<Value> message = exceptionObj->Get(messageSymbol);
			Handle<Value> name = exceptionObj->Get(nameSymbol);

			if (!message->IsUndefined() && !name->IsUndefined()) {
				String::Utf8Value nameValue(name);
				String::Utf8Value messageValue(message);
				LOGE(EXC_TAG, "%s: %s", *nameValue, *messageValue);
			}
		} else {
			String::Utf8Value error(exception);
			LOGE(EXC_TAG, *error);
		}
	}
}
开发者ID:1rp,项目名称:titanium_mobile,代码行数:43,代码来源:V8Util.cpp

示例15: ReportException

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, "--------------------------------------------------------------------------------");
}
开发者ID:joeystandrew,项目名称:SourceMod.js,代码行数:41,代码来源:SMJS_Plugin.cpp


注:本文中的Handle::GetLineNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。