mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:58:10 +00:00
LibJS: Add console.trace()
This commit is contained in:
parent
eece424694
commit
3b21c4aa56
3 changed files with 17 additions and 0 deletions
|
@ -35,6 +35,7 @@ namespace JS {
|
|||
ConsoleObject::ConsoleObject()
|
||||
{
|
||||
put_native_function("log", log);
|
||||
put_native_function("trace", trace);
|
||||
}
|
||||
|
||||
ConsoleObject::~ConsoleObject()
|
||||
|
@ -52,4 +53,18 @@ Value ConsoleObject::log(Interpreter& interpreter)
|
|||
return js_undefined();
|
||||
}
|
||||
|
||||
Value ConsoleObject::trace(Interpreter& interpreter)
|
||||
{
|
||||
log(interpreter);
|
||||
auto call_stack = interpreter.call_stack();
|
||||
// -2 to skip the console.trace() call frame
|
||||
for (ssize_t i = call_stack.size() - 2; i >= 0; --i) {
|
||||
auto function_name = call_stack[i].function_name;
|
||||
if (String(function_name).is_empty())
|
||||
function_name = "<anonymous>";
|
||||
printf("%s\n", function_name.characters());
|
||||
}
|
||||
return js_undefined();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue