forked from rogchap/v8go
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherrors.cc
50 lines (40 loc) · 1.3 KB
/
errors.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <sstream>
#include "deps/include/v8-exception.h"
#include "deps/include/v8-message.h"
#include "deps/include/v8-primitive.h"
#include "errors.h"
#include "utils.h"
using namespace v8;
RtnError ExceptionError(TryCatch& try_catch, Isolate* iso, Local<Context> ctx) {
HandleScope handle_scope(iso);
RtnError rtn = {nullptr, nullptr, nullptr};
if (try_catch.HasTerminated()) {
rtn.msg =
CopyString("ExecutionTerminated: script execution has been terminated");
return rtn;
}
String::Utf8Value exception(iso, try_catch.Exception());
rtn.msg = CopyString(exception);
Local<Message> msg = try_catch.Message();
if (!msg.IsEmpty()) {
String::Utf8Value origin(iso, msg->GetScriptOrigin().ResourceName());
std::ostringstream sb;
sb << *origin;
Maybe<int> line = try_catch.Message()->GetLineNumber(ctx);
if (line.IsJust()) {
sb << ":" << line.ToChecked();
}
Maybe<int> start = try_catch.Message()->GetStartColumn(ctx);
if (start.IsJust()) {
sb << ":"
<< start.ToChecked() + 1; // + 1 to match output from stack trace
}
rtn.location = CopyString(sb.str());
}
Local<Value> mstack;
if (try_catch.StackTrace(ctx).ToLocal(&mstack)) {
String::Utf8Value stack(iso, mstack);
rtn.stack = CopyString(stack);
}
return rtn;
}