Skip to content

Instantly share code, notes, and snippets.

@luk-
Created December 17, 2013 20:21
Show Gist options
  • Save luk-/8011914 to your computer and use it in GitHub Desktop.
Save luk-/8011914 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2013, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
void LogStackTrace(Handle<Object> obj) {
try {
Local<Value> args[] = {};
Local<Value> frameCount = obj->Get(String::New("frameCount"));
Local<Function> frameCountFunc = Local<Function>::Cast(frameCount);
Local<Value> frameCountVal = frameCountFunc->Call(obj, 0, args);
Local<Number> frameCountNum = frameCountVal->ToNumber();
cout << "Stack Trace:" << endl;
int totalFrames = frameCountNum->Value();
for(int i = 0; i < totalFrames; i++) {
Local<Value> frameNumber[] = {Number::New(i)};
Local<Value> setSelectedFrame = obj->Get(String::New("setSelectedFrame"));
Local<Function> setSelectedFrameFunc = Local<Function>::Cast(setSelectedFrame);
setSelectedFrameFunc->Call(obj, 1, frameNumber);
Local<Value> frame = obj->Get(String::New("frame"));
Local<Function> frameFunc = Local<Function>::Cast(frame);
Local<Value> frameVal = frameFunc->Call(obj, 0, args);
Local<Object> frameObj = frameVal->ToObject();
Local<Value> frameToText = frameObj->Get(String::New("toText"));
Local<Function> frameToTextFunc = Local<Function>::Cast(frameToText);
Local<Value> frameToTextVal = frameToTextFunc->Call(frameObj, 0, args);
String::Utf8Value frameText(frameToTextVal);
cout << *frameText << endl;
}
} catch(exception e) {
cerr << "Error occured while logging stack trace:" << e.what() << endl;
}
}
@luk-
Copy link
Author

luk- commented Dec 17, 2013

This builds fine on Linux. For some reason OS X doesn't like e.what() in the catch block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment