1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2026-01-12 22:30:59 +00:00
serenity/Libraries
Emanuele Torre be1a5bf3f7 LibJS: Add ConsoleMessage concept
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-02 11:41:35 +02:00
..
LibAudio LibAudio: Use NumericLimits<T> 2020-04-15 16:58:46 +02:00
LibBareMetal AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macros 2020-04-30 11:43:25 +02:00
LibC AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macros 2020-04-30 11:43:25 +02:00
LibCore LibCore: Do not assert that NonnullRefPtr is non-null 2020-04-30 11:30:27 +02:00
LibDebug LibDebug: Add remove_breakpoint 2020-04-25 13:16:46 +02:00
LibELF LibELF: Make ELF::Loader RefCounted 2020-04-20 17:25:50 +02:00
LibGfx LibGfx: Decode paletted and grayscale images with 1/2/4 bit depth 2020-05-02 01:28:18 +02:00
LibGUI WindowServer+LibGUI: Automatically close child windows with parent 2020-05-02 01:29:55 +02:00
LibIPC AK: Stop allowing implicit downcast with OwnPtr and NonnullOwnPtr 2020-04-05 11:32:30 +02:00
LibJS LibJS: Add ConsoleMessage concept 2020-05-02 11:41:35 +02:00
LibLine LibLine: Reset inline_search_cursor along with cursor 2020-04-30 22:14:59 +02:00
LibM LibM: Implement fmodf() 2020-05-02 01:23:30 +02:00
LibMarkdown LibMarkdown: Add support for images :^) 2020-04-30 11:30:27 +02:00
LibPCIDB Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
LibProtocol ProtocolServer+LibProtocol: Reject unhandled URLs instead of asserting 2020-04-04 20:01:36 +02:00
LibPthread LibPthread: Hookup abstime argument to pthread_cond_timedwait 2020-04-26 21:31:52 +02:00
LibThread AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macros 2020-04-30 11:43:25 +02:00
LibVT LibVT: Handle ctrl+arrow keys 2020-04-20 20:23:26 +02:00
LibWeb LibJS: Pass JS::Function around by reference more 2020-04-29 13:43:57 +02:00
LibX86 LibX86: Disassemble BSWAP 2020-04-30 22:15:16 +02:00
Makefile Build: Only look at SUBDIRS with Makefiles 2020-02-25 19:56:48 +01:00