/src/serenity/Userland/Libraries/LibWeb/WebIDL/Tracing.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <AK/Format.h> |
8 | | #include <AK/StringBuilder.h> |
9 | | #include <LibJS/Runtime/VM.h> |
10 | | #include <LibWeb/WebIDL/Tracing.h> |
11 | | |
12 | | namespace Web::WebIDL { |
13 | | |
14 | | bool g_enable_idl_tracing = false; |
15 | | |
16 | | void log_trace_impl(JS::VM& vm, char const* function) |
17 | 0 | { |
18 | 0 | if (!g_enable_idl_tracing) |
19 | 0 | return; |
20 | | |
21 | 0 | StringBuilder builder; |
22 | 0 | for (size_t i = 0; i < vm.argument_count(); ++i) { |
23 | 0 | if (i != 0) |
24 | 0 | builder.append(", "sv); |
25 | 0 | auto argument = vm.argument(i); |
26 | 0 | if (argument.is_string()) |
27 | 0 | builder.append_code_point('"'); |
28 | 0 | auto string = argument.to_string_without_side_effects(); |
29 | 0 | for (auto code_point : string.code_points()) { |
30 | 0 | if (code_point < 0x20) { |
31 | 0 | builder.appendff("\\u{:04x}", code_point); |
32 | 0 | continue; |
33 | 0 | } |
34 | 0 | builder.append_code_point(code_point); |
35 | 0 | } |
36 | 0 | if (argument.is_string()) |
37 | 0 | builder.append_code_point('"'); |
38 | 0 | } |
39 | 0 | dbgln("{}({})", function, builder.string_view()); |
40 | 0 | } |
41 | | |
42 | | } |