Esempio n. 1
0
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");
	}
}
Esempio n. 2
0
    std::ostream& operator<<(std::ostream& s, const v8::TryCatch* try_catch) {
        v8::HandleScope handle_scope;
        v8::String::Utf8Value exceptionText(try_catch->Exception());
        v8::Handle<v8::Message> message = try_catch->Message();

        if (message.IsEmpty()) {
            s << *exceptionText << endl;
        }
        else {
            v8::String::Utf8Value filename(message->GetScriptResourceName());
            int linenum = message->GetLineNumber();
            cout << *filename << ":" << linenum << " " << *exceptionText << 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;
        }
        return s;
    }
Esempio n. 3
0
/* 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);
    }
  }
}
Esempio n. 4
0
void
ASTNode::warning (const char *format, ...)
{
    va_list ap;
    va_start (ap, format);
    std::string errmsg = format ? Strutil::vformat (format, ap) : "unknown warning";
    va_end (ap);
    m_compiler->warning (sourcefile(), sourceline(), "%s", errmsg.c_str());
}
Esempio n. 5
0
void
ASTNode::error (const char *format, ...)
{
    va_list ap;
    va_start (ap, format);
    std::string errmsg = format ? Strutil::vformat (format, ap) : "syntax error";
    va_end (ap);
    m_compiler->error (sourcefile(), sourceline(), "%s", errmsg.c_str());
}
void report_exception(v8::TryCatch* try_catch) {
	// todo: refactor to something that returns a string without printing directly to console.

	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\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);  
		std::string sourceline_str(sourceline_string);
		printf("%s\n", sourceline_string);
		// Print wavy underline (GetUnderline is deprecated).
		int start = message->GetStartColumn();
		for (int i =0; i < start; i++) {  
			if (i < sourceline_str.size()) {
				if (sourceline_str.at(i) == '\t')
					printf("\t");
				else
					printf("");  
			} else {
				printf("");    
			}
		}
		int end = message->GetEndColumn();
		for (int i = start; i < end; i++) {   
			if (i < sourceline_str.size()) {
				if (sourceline_str.at(i) == '\t')
					printf("\t");
				else
					printf("^");  
			} else {
				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);    
		}  
		printf("\n");  
	}
}
Esempio n. 7
0
	void V8GL::logException(v8::TryCatch* try_catch) {

		v8::HandleScope scope;

		v8::String::Utf8Value exception(try_catch->Exception());

		const char* exception_string = *exception;
		v8::Handle<v8::Message> message = try_catch->Message();

		fprintf(stderr, "\n");

		if (message.IsEmpty()) {

			fprintf(stderr, "%s\n", exception_string);

		} else {

			// Print (filename):(line number): (message).
			v8::String::Utf8Value filename(message->GetScriptResourceName());
			const char* filename_string = *filename;
			int linenum = message->GetLineNumber();
			fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string);

			// Print line of source code.
			v8::String::Utf8Value sourceline(message->GetSourceLine());
			const char* sourceline_string = *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");


			v8::String::Utf8Value stack_trace(try_catch->StackTrace());
			if (stack_trace.length() > 0) {
				const char* stack_trace_string = *stack_trace;
				fprintf(stderr, "%s\n", stack_trace_string);
			}

		}

	}
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";
  }
}
Esempio n. 9
0
/**
 * 吉里吉里に対して例外通知
 */
void
JSEXCEPTION(Isolate* isolate, TryCatch *try_catch)
{
	HandleScope handle_scope(isolate);

	//HandleScope handle_scope;
	String::Value exception(try_catch->Exception());

	Local<Message> message = try_catch->Message();
	if (!message.IsEmpty()) {
		// 例外表示
		String::Value filename(message->GetScriptResourceName());
		ttstr msg;
		msg += *filename;
		msg += ":";
		msg += tTJSVariant(message->GetLineNumber());
		msg += ":";
		msg += *exception;

		TVPAddLog(msg);
		
		// Print (filename):(line number): (message).
		String::Value sourceline(message->GetSourceLine());
		TVPAddLog(ttstr(*sourceline));

		// エラー行表示
		ttstr wavy;
		int start = message->GetStartColumn();
		for (int i = 0; i < start; i++) {
			wavy += " ";
		}
		int end = message->GetEndColumn();
		for (int i = start; i < end; i++) {
			wavy +="^";
		}
		TVPAddLog(wavy);

		// スタックトレース表示
		String::Value stack_trace(try_catch->StackTrace());
		if (stack_trace.length() > 0) {
			TVPAddLog(ttstr(*stack_trace));
		}
	}
	TVPThrowExceptionMessage(*exception);
}
Esempio n. 10
0
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, "--------------------------------------------------------------------------------");
}
Esempio n. 11
0
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);
        }
    }
}
Esempio n. 12
0
    std::string toSTLString( const v8::TryCatch * try_catch ) {

        stringstream ss;

        //while ( try_catch ){ // disabled for v8 bleeding edge

        v8::String::Utf8Value exception(try_catch->Exception());
        Handle<v8::Message> message = try_catch->Message();

        if (message.IsEmpty()) {
            ss << *exception << endl;
        }
        else {

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

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

            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 << endl;
        }

        //try_catch = try_catch->next_;
        //}

        return ss.str();
    }
Esempio n. 13
0
	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);
	}
Esempio n. 14
0
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;
  }
}
Esempio n. 15
0
// Slight modification to an original function found in the V8 sample shell.cc.
void Global::reportException(TryCatch* tryCatch) {
    HandleScope handleScope(fIsolate);
    String::Utf8Value exception(tryCatch->Exception());
    const char* exceptionString = to_cstring(exception);
    Handle<Message> message = tryCatch->Message();
    if (message.IsEmpty()) {
        // V8 didn't provide any extra information about this error; just
        // print the exception.
        fprintf(stderr, "%s\n", exceptionString);
    } else {
        // Print (filename):(line number): (message).
        String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
        const char* filenameString = to_cstring(filename);
        int linenum = message->GetLineNumber();
        fprintf(stderr,
                "%s:%i: %s\n", filenameString, linenum, exceptionString);
        // Print line of source code.
        String::Utf8Value sourceline(message->GetSourceLine());
        const char* sourceLineString = to_cstring(sourceline);
        fprintf(stderr, "%s\n", sourceLineString);
        // Print wavy underline.
        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 stackTrace(tryCatch->StackTrace());
        if (stackTrace.length() > 0) {
            const char* stackTraceString = to_cstring(stackTrace);
            fprintf(stderr, "%s\n", stackTraceString);
        }
    }
}
Esempio n. 16
0
static void AppendExceptionLine(Environment* env, v8::Handle<v8::Value> er, v8::Handle<v8::Message> message)
{
    if (message.IsEmpty())
        return;

    v8::HandleScope scope(env->isolate());
    v8::Local<v8::Object> err_obj;
    if (!er.IsEmpty() && er->IsObject()) {
        err_obj = er.As<v8::Object>();

        // Do it only once per message
        if (!err_obj->GetHiddenValue(env->processed_string()).IsEmpty())
            return;
        err_obj->SetHiddenValue(env->processed_string(), True(env->isolate()));
    }

    static char arrow[1024];

    // Print (filename):(line number): (message).
    v8::String::Utf8Value filename(message->GetScriptResourceName());
    const char* filename_string = *filename;
    int linenum = message->GetLineNumber();
    // Print line of source code.
    v8::String::Utf8Value sourceline(message->GetSourceLine());
    const char* sourceline_string = *sourceline;

    // Because of how node modules work, all scripts are wrapped with a
    // "function (module, exports, __filename, ...) {"
    // to provide script local variables.
    //
    // When reporting errors on the first line of a script, this wrapper
    // function is leaked to the user. There used to be a hack here to
    // truncate off the first 62 characters, but it caused numerous other
    // problems when vm.runIn*Context() methods were used for non-module
    // code.
    //
    // If we ever decide to re-instate such a hack, the following steps
    // must be taken:
    //
    // 1. Pass a flag around to say "this code was wrapped"
    // 2. Update the stack frame output so that it is also correct.
    //
    // It would probably be simpler to add a line rather than add some
    // number of characters to the first line, since V8 truncates the
    // sourceline to 78 characters, and we end up not providing very much
    // useful debugging info to the user if we remove 62 characters.

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

    int off = snprintf(arrow, sizeof(arrow), "%s:%i\n%s\n", filename_string, linenum, sourceline_string);
    assert(off >= 0);

    // Print wavy underline (GetUnderline is deprecated).
    for (int i = 0; i < start; i++) {
        if (sourceline_string[i] == '\0' || static_cast<size_t>(off) >= sizeof(arrow)) {
            break;
        }
        assert(static_cast<size_t>(off) < sizeof(arrow));
        arrow[off++] = (sourceline_string[i] == '\t') ? '\t' : ' ';
    }
    for (int i = start; i < end; i++) {
        if (sourceline_string[i] == '\0' || static_cast<size_t>(off) >= sizeof(arrow)) {
            break;
        }
        assert(static_cast<size_t>(off) < sizeof(arrow));
        arrow[off++] = '^';
    }
    assert(static_cast<size_t>(off - 1) <= sizeof(arrow) - 1);
    arrow[off++] = '\n';
    arrow[off] = '\0';

    v8::Local<v8::String> arrow_str = v8::String::NewFromUtf8(env->isolate(), arrow);
    v8::Local<v8::Value> msg;
    v8::Local<v8::Value> stack;

    // Allocation failed, just print it out
    if (arrow_str.IsEmpty() || err_obj.IsEmpty() || !err_obj->IsNativeError())
        goto print;

    msg = err_obj->Get(env->message_string());
    stack = err_obj->Get(env->stack_string());

    if (msg.IsEmpty() || stack.IsEmpty())
        goto print;

    err_obj->Set(env->message_string(), v8::String::Concat(arrow_str, msg->ToString()));
    err_obj->Set(env->stack_string(), v8::String::Concat(arrow_str, stack->ToString()));
    return;

    print: if (env->printed_error())
        return;
    env->set_printed_error(true);
//  uv_tty_reset_mode();
    fprintf(stderr, "\n%s", arrow);
}