mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 03:37:53 +00:00
LibJS: Add console.trace()
This commit is contained in:
committed by
Andreas Kling
parent
eece424694
commit
3b21c4aa56
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user