Permalink
Browse files

repl, feat: add 'Thown:' prefix in repl (#385)

when throw exception.
  • Loading branch information...
ngot authored and xicilion committed Dec 4, 2017
1 parent 1c6b513 commit 33f3c01fc44dc678c93ac520196409cfa7808d5d
Showing with 12 additions and 8 deletions.
  1. +2 −2 fibjs/include/utils.h
  2. +8 −4 fibjs/src/base/utils.cpp
  3. +2 −2 fibjs/src/sandbox/SandBox_repl.cpp
View
@@ -1145,8 +1145,8 @@ inline result_t SocketError()
exlib::string getResultMessage(result_t hr);
v8::Local<v8::Value> ThrowResult(result_t hr);
void ReportException(TryCatch& try_catch, result_t hr);
exlib::string GetException(TryCatch& try_catch, result_t hr);
void ReportException(TryCatch& try_catch, result_t hr, bool repl = false);
exlib::string GetException(TryCatch& try_catch, result_t hr, bool repl = false);
result_t throwSyntaxError(TryCatch& try_catch);
#ifdef _WIN32
View
@@ -115,7 +115,7 @@ v8::Local<v8::Value> ThrowResult(result_t hr)
return isolate->m_isolate->ThrowException(e);
}
exlib::string GetException(TryCatch& try_catch, result_t hr)
exlib::string GetException(TryCatch& try_catch, result_t hr, bool repl)
{
Isolate* isolate = Isolate::current();
v8::HandleScope handle_scope(isolate->m_isolate);
@@ -176,7 +176,11 @@ exlib::string GetException(TryCatch& try_catch, result_t hr)
v8::Local<v8::Value> message;
v8::Local<v8::Value> name;
if (err->IsObject()) {
if (repl) {
strError.append("Thrown: ");
}
if (!repl && err->IsObject()) {
message = err_obj->Get(isolate->NewString("message"));
name = err_obj->Get(isolate->NewString("name"));
}
@@ -216,10 +220,10 @@ result_t throwSyntaxError(TryCatch& try_catch)
return CALL_E_JAVASCRIPT;
}
void ReportException(TryCatch& try_catch, result_t hr)
void ReportException(TryCatch& try_catch, result_t hr, bool repl)
{
if (try_catch.HasCaught() || hr < 0)
errorLog(GetException(try_catch, hr));
errorLog(GetException(try_catch, hr, repl));
}
result_t CheckConfig(v8::Local<v8::Object> opts, const char** keys)
@@ -203,7 +203,7 @@ result_t SandBox::Context::repl(v8::Local<v8::Array> cmds, Stream_base* out)
v8::String::Utf8Value exception(try_catch.Exception());
if (*exception && qstrcmp(*exception, "SyntaxError: Unexpected end of input")) {
buf.clear();
ReportException(try_catch, 0);
ReportException(try_catch, 0, true);
}
continue;
}
@@ -212,7 +212,7 @@ result_t SandBox::Context::repl(v8::Local<v8::Array> cmds, Stream_base* out)
v = script->Run();
if (v.IsEmpty())
ReportException(try_catch, 0);
ReportException(try_catch, 0, true);
}
}

0 comments on commit 33f3c01

Please sign in to comment.