mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 02:29:21 +00:00
Ladybird+LibWeb: Add optional IDL call tracing
When launched with the new --enable-idl-tracing option, we now log every call to web platform APIs declared via IDL, along with the arguments passed. This can be very helpful when trying to figure out what a site is doing, especially if it's not doing what you'd expect.
This commit is contained in:
parent
5f9a905793
commit
f4f4f7781d
Notes:
sideshowbarker
2024-07-17 17:06:59 +09:00
Author: https://github.com/awesomekling
Commit: f4f4f7781d
Pull-request: https://github.com/SerenityOS/serenity/pull/23980
8 changed files with 110 additions and 1 deletions
42
Userland/Libraries/LibWeb/WebIDL/Tracing.cpp
Normal file
42
Userland/Libraries/LibWeb/WebIDL/Tracing.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/WebIDL/Tracing.h>
|
||||
|
||||
namespace Web::WebIDL {
|
||||
|
||||
bool g_enable_idl_tracing = false;
|
||||
|
||||
void log_trace_impl(JS::VM& vm, char const* function)
|
||||
{
|
||||
if (!g_enable_idl_tracing)
|
||||
return;
|
||||
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i) {
|
||||
if (i != 0)
|
||||
builder.append(", "sv);
|
||||
auto argument = vm.argument(i);
|
||||
if (argument.is_string())
|
||||
builder.append_code_point('"');
|
||||
auto string = argument.to_string_without_side_effects();
|
||||
for (auto code_point : string.code_points()) {
|
||||
if (code_point < 0x20) {
|
||||
builder.appendff("\\u{:04x}", code_point);
|
||||
continue;
|
||||
}
|
||||
builder.append_code_point(code_point);
|
||||
}
|
||||
if (argument.is_string())
|
||||
builder.append_code_point('"');
|
||||
}
|
||||
dbgln("{}({})", function, builder.string_view());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue