mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibJS: Add console.trace()
This commit is contained in:
parent
eece424694
commit
3b21c4aa56
Notes:
sideshowbarker
2024-07-19 07:43:18 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/3b21c4aa567 Pull-request: https://github.com/SerenityOS/serenity/pull/1742
3 changed files with 17 additions and 0 deletions
|
@ -112,6 +112,7 @@ public:
|
|||
}
|
||||
void pop_call_frame() { m_call_stack.take_last(); }
|
||||
const CallFrame& call_frame() { return m_call_stack.last(); }
|
||||
const Vector<CallFrame> call_stack() { return m_call_stack; }
|
||||
|
||||
size_t argument_count() const
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ private:
|
|||
virtual const char* class_name() const override { return "ConsoleObject"; }
|
||||
|
||||
static Value log(Interpreter&);
|
||||
static Value trace(Interpreter&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue