summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Console.cpp
AgeCommit message (Collapse)Author
2020-06-02LibJS: Move Interpreter::get_trace() to ConsoleClientLinus Groh
Having it globally on the interpreter is confusing as the last call frame is skipped, which is specific to console.trace().
2020-06-02LibJS: Remove dummy implementations from Console methodsLinus Groh
Having these duplicated is not really useful, either we want console output to go somewhere then implementing a console client is the way to go, or we don't care about console output - in that case we don't need to dbg() either.
2020-05-15LibJS: Add side-effect-free version of Value::to_string()Andreas Kling
There are now two API's on Value: - Value::to_string(Interpreter&) -- may throw. - Value::to_string_without_side_effects() -- will never throw. These are some pretty big sweeping changes, so it's possible that I did some part the wrong way. We'll work it out as we go. :^) Fixes #2123.
2020-05-05LibJS: Implement ConsoleClientEmanuele Torre
Now, you can optionally specify a ConsoleClient, to customise the behaviour of the LibJS Console. To customise the console, create a new ConsoleClient class that inherits from JS::ConsoleClient and override all the abstract methods. When Console::log() is called, if Console has a ConsoleClient, ConsoleClient::log() is called instead. These abstract methods are Value(void) functions: you can return a Value which will be returned by the JavaScript function which calls that method, in JavaScript.
2020-05-05LibJS: Add some helpers and use them to re-implement Console functionsEmanuele Torre
Also add const overloads for some getters. Also const-qualify Interpreter::join_arguments().
2020-05-05LibJS: Re-implement console functions as wrappers around Console methodsEmanuele Torre
Console methods are now Value(void) functions. JavaScript functions in the JavaScript ConsoleObject are now implemented as simple wrappers around Console methods. This will make it possible for LibJS users to easily override the default behaviour of JS console functions (even their return value!) once we add a way to override Console behaviour.
2020-05-05LibJS: Remove ConsoleMessage from LibJSEmanuele Torre
We don't need to store the past messages in LibJS. We'll implement a way to let LibJS users expand the vanilla Console.
2020-05-02LibJS: Add ConsoleMessage conceptEmanuele Torre
A ConsoleMessage is a struct cointaining: * AK::String text; represents the text of the message sent to the console. * ConsoleMessageKind kind; represents the kind of JS `console` function from which the message was sent. Now, Javascript `console` functions only send a ConsoleMessage to the Interpreter's Console instead of printing text directly to stdout. The Console then stores the recived ConsoleMessage in Console::m_messages; the Console does not print to stdout by default. You can set Console::on_new_message to a void(ConsoleMessage&); this function will get call everytime a new message is added to the Console's messages and can be used, for example, to print ConsoleMessages to stdout or to color the output based on the kind of ConsoleMessage. In this patch, I also: * Re-implement all the previously implemented functions in the JavaScript ConsoleObject, as wrappers around Console functions that add new message to the Console. * Implement console.clear() like so: - m_messages get cleared; - a new_message with kind set ConsoleMessageKind::Clear gets added to m_messages, its text is an empty AK::String; * Give credit to linusg in Console.cpp since I used his console.trace() algorithm in Console::trace(). I think that having this abstration will help us in the implementation of a browser console or a JS debugger. We could also add more MetaData to ConsoleMessage, e.g. Object IDs of the arguments passed to console functions in order to make hyperlinks, Timestamps, ecc.; which could be interesting to see. This will also help in implementing a `/bin/js` option to make, for example, return a ConsoleMessageWrapper to console functions instead of undefined. This will be useful to make tests for functions like console.count() and console.countClear(). :^)
2020-05-02LibJS: Implement ConsoleObject::count() as a Console::count() wrapperEmanuele Torre
Also implement ConsoleObject::count_clear() as a wrapper for Console::count_clear()
2020-05-02LibJS: Start implementing a Console class for the interpreterEmanuele Torre
The goal is to start factoring out core ConsoleObject functionality and to make ConsoleObject only a JS wrapper around Console.