Add process.getCurrentStackTrace(), returning V8::getCurrentStackTrace().
This commit is contained in:
parent
b3a2302283
commit
2b9a533d1d
3 changed files with 43 additions and 0 deletions
|
@ -7,17 +7,35 @@
|
||||||
#include "base/debug/debugger.h"
|
#include "base/debug/debugger.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "common/atom_version.h"
|
#include "common/atom_version.h"
|
||||||
|
#include "common/v8_conversions.h"
|
||||||
#include "vendor/node/src/node.h"
|
#include "vendor/node/src/node.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
static int kMaxCallStackSize = 200; // Same with WebKit.
|
||||||
|
|
||||||
static uv_async_t dummy_uv_handle;
|
static uv_async_t dummy_uv_handle;
|
||||||
|
|
||||||
void UvNoOp(uv_async_t* handle, int status) {
|
void UvNoOp(uv_async_t* handle, int status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Handle<v8::Object> DumpStackFrame(v8::Handle<v8::StackFrame> stack_frame) {
|
||||||
|
v8::Local<v8::Object> result = v8::Object::New();
|
||||||
|
result->Set(ToV8Value("line"), ToV8Value(stack_frame->GetLineNumber()));
|
||||||
|
result->Set(ToV8Value("column"), ToV8Value(stack_frame->GetColumn()));
|
||||||
|
|
||||||
|
v8::Handle<v8::String> script = stack_frame->GetScriptName();
|
||||||
|
if (!script.IsEmpty())
|
||||||
|
result->Set(ToV8Value("script"), script);
|
||||||
|
|
||||||
|
v8::Handle<v8::String> function = stack_frame->GetScriptNameOrSourceURL();
|
||||||
|
if (!function.IsEmpty())
|
||||||
|
result->Set(ToV8Value("function"), function);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// Defined in atom_extensions.cc.
|
// Defined in atom_extensions.cc.
|
||||||
|
@ -37,6 +55,7 @@ void AtomBindings::BindTo(v8::Handle<v8::Object> process) {
|
||||||
node::SetMethod(process, "crash", Crash);
|
node::SetMethod(process, "crash", Crash);
|
||||||
node::SetMethod(process, "activateUvLoop", ActivateUVLoop);
|
node::SetMethod(process, "activateUvLoop", ActivateUVLoop);
|
||||||
node::SetMethod(process, "log", Log);
|
node::SetMethod(process, "log", Log);
|
||||||
|
node::SetMethod(process, "getCurrentStackTrace", GetCurrentStackTrace);
|
||||||
|
|
||||||
process->Get(v8::String::New("versions"))->ToObject()->
|
process->Get(v8::String::New("versions"))->ToObject()->
|
||||||
Set(v8::String::New("atom-shell"), v8::String::New(ATOM_VERSION_STRING));
|
Set(v8::String::New("atom-shell"), v8::String::New(ATOM_VERSION_STRING));
|
||||||
|
@ -111,4 +130,23 @@ v8::Handle<v8::Value> AtomBindings::Log(const v8::Arguments& args) {
|
||||||
return v8::Undefined();
|
return v8::Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Handle<v8::Value> AtomBindings::GetCurrentStackTrace(
|
||||||
|
const v8::Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
int stack_limit = kMaxCallStackSize;
|
||||||
|
FromV8Arguments(args, &stack_limit);
|
||||||
|
|
||||||
|
v8::Local<v8::StackTrace> stack_trace = v8::StackTrace::CurrentStackTrace(
|
||||||
|
stack_limit, v8::StackTrace::kDetailed);
|
||||||
|
|
||||||
|
int frame_count = stack_trace->GetFrameCount();
|
||||||
|
v8::Local<v8::Array> result = v8::Array::New(frame_count);
|
||||||
|
for (int i = 0; i < frame_count; ++i)
|
||||||
|
result->Set(i, DumpStackFrame(stack_trace->GetFrame(i)));
|
||||||
|
|
||||||
|
return scope.Close(result);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -24,6 +24,7 @@ class AtomBindings {
|
||||||
static v8::Handle<v8::Value> Crash(const v8::Arguments& args);
|
static v8::Handle<v8::Value> Crash(const v8::Arguments& args);
|
||||||
static v8::Handle<v8::Value> ActivateUVLoop(const v8::Arguments& args);
|
static v8::Handle<v8::Value> ActivateUVLoop(const v8::Arguments& args);
|
||||||
static v8::Handle<v8::Value> Log(const v8::Arguments& args);
|
static v8::Handle<v8::Value> Log(const v8::Arguments& args);
|
||||||
|
static v8::Handle<v8::Value> GetCurrentStackTrace(const v8::Arguments& args);
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomBindings);
|
DISALLOW_COPY_AND_ASSIGN(AtomBindings);
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,6 +77,10 @@ inline v8::Handle<v8::Value> ToV8Value(bool b) {
|
||||||
return v8::Boolean::New(b);
|
return v8::Boolean::New(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline v8::Handle<v8::Value> ToV8Value(const char* s) {
|
||||||
|
return v8::String::New(s);
|
||||||
|
}
|
||||||
|
|
||||||
inline v8::Handle<v8::Value> ToV8Value(const std::string& s) {
|
inline v8::Handle<v8::Value> ToV8Value(const std::string& s) {
|
||||||
return v8::String::New(s.data(), s.size());
|
return v8::String::New(s.data(), s.size());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue