Tracing.cpp 1.1 KB

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