mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
LibJS: Add console.trace()
This commit is contained in:
parent
eece424694
commit
3b21c4aa56
3 changed files with 17 additions and 0 deletions
|
@ -112,6 +112,7 @@ public:
|
||||||
}
|
}
|
||||||
void pop_call_frame() { m_call_stack.take_last(); }
|
void pop_call_frame() { m_call_stack.take_last(); }
|
||||||
const CallFrame& call_frame() { return m_call_stack.last(); }
|
const CallFrame& call_frame() { return m_call_stack.last(); }
|
||||||
|
const Vector<CallFrame> call_stack() { return m_call_stack; }
|
||||||
|
|
||||||
size_t argument_count() const
|
size_t argument_count() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace JS {
|
||||||
ConsoleObject::ConsoleObject()
|
ConsoleObject::ConsoleObject()
|
||||||
{
|
{
|
||||||
put_native_function("log", log);
|
put_native_function("log", log);
|
||||||
|
put_native_function("trace", trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleObject::~ConsoleObject()
|
ConsoleObject::~ConsoleObject()
|
||||||
|
@ -52,4 +53,18 @@ Value ConsoleObject::log(Interpreter& interpreter)
|
||||||
return js_undefined();
|
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"; }
|
virtual const char* class_name() const override { return "ConsoleObject"; }
|
||||||
|
|
||||||
static Value log(Interpreter&);
|
static Value log(Interpreter&);
|
||||||
|
static Value trace(Interpreter&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue