Created
December 17, 2013 20:21
-
-
Save luk-/8011914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This builds fine on Linux. For some reason OS X doesn't like
e.what()
in the catch block.