ConsoleObject.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #include <LibJS/Console.h>
  9. #include <LibJS/Runtime/ConsoleObject.h>
  10. #include <LibJS/Runtime/GlobalObject.h>
  11. namespace JS {
  12. ConsoleObject::ConsoleObject(GlobalObject& global_object)
  13. : Object(*global_object.object_prototype())
  14. {
  15. }
  16. void ConsoleObject::initialize(GlobalObject& global_object)
  17. {
  18. auto& vm = this->vm();
  19. Object::initialize(global_object);
  20. u8 attr = Attribute::Writable | Attribute::Enumerable | Attribute::Configurable;
  21. define_native_function(vm.names.log, log, 0, attr);
  22. define_native_function(vm.names.debug, debug, 0, attr);
  23. define_native_function(vm.names.info, info, 0, attr);
  24. define_native_function(vm.names.warn, warn, 0, attr);
  25. define_native_function(vm.names.error, error, 0, attr);
  26. define_native_function(vm.names.trace, trace, 0, attr);
  27. define_native_function(vm.names.count, count, 0, attr);
  28. define_native_function(vm.names.countReset, count_reset, 0, attr);
  29. define_native_function(vm.names.clear, clear, 0, attr);
  30. define_native_function(vm.names.assert, assert_, 0, attr);
  31. define_native_function(vm.names.group, group, 0, attr);
  32. define_native_function(vm.names.groupCollapsed, group_collapsed, 0, attr);
  33. define_native_function(vm.names.groupEnd, group_end, 0, attr);
  34. define_native_function(vm.names.time, time, 0, attr);
  35. define_native_function(vm.names.timeLog, time_log, 0, attr);
  36. define_native_function(vm.names.timeEnd, time_end, 0, attr);
  37. }
  38. ConsoleObject::~ConsoleObject()
  39. {
  40. }
  41. // 1.1.6. log(...data), https://console.spec.whatwg.org/#log
  42. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log)
  43. {
  44. return global_object.console().log();
  45. }
  46. // 1.1.3. debug(...data), https://console.spec.whatwg.org/#debug
  47. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug)
  48. {
  49. return global_object.console().debug();
  50. }
  51. // 1.1.5. info(...data), https://console.spec.whatwg.org/#info
  52. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info)
  53. {
  54. return global_object.console().info();
  55. }
  56. // 1.1.9. warn(...data), https://console.spec.whatwg.org/#warn
  57. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn)
  58. {
  59. return global_object.console().warn();
  60. }
  61. // 1.1.4. error(...data), https://console.spec.whatwg.org/#error
  62. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error)
  63. {
  64. return global_object.console().error();
  65. }
  66. // 1.1.8. trace(...data), https://console.spec.whatwg.org/#trace
  67. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace)
  68. {
  69. return global_object.console().trace();
  70. }
  71. // 1.2.1. count(label), https://console.spec.whatwg.org/#count
  72. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count)
  73. {
  74. return global_object.console().count();
  75. }
  76. // 1.2.2. countReset(label), https://console.spec.whatwg.org/#countreset
  77. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset)
  78. {
  79. return global_object.console().count_reset();
  80. }
  81. // 1.1.2. clear(), https://console.spec.whatwg.org/#clear
  82. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear)
  83. {
  84. return global_object.console().clear();
  85. }
  86. // 1.1.1. assert(condition, ...data), https://console.spec.whatwg.org/#assert
  87. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::assert_)
  88. {
  89. return global_object.console().assert_();
  90. }
  91. // 1.3.1. group(...data), https://console.spec.whatwg.org/#group
  92. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group)
  93. {
  94. return global_object.console().group();
  95. }
  96. // 1.3.2. groupCollapsed(...data), https://console.spec.whatwg.org/#groupcollapsed
  97. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_collapsed)
  98. {
  99. return global_object.console().group_collapsed();
  100. }
  101. // 1.3.3. groupEnd(), https://console.spec.whatwg.org/#groupend
  102. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_end)
  103. {
  104. return global_object.console().group_end();
  105. }
  106. // 1.4.1. time(label), https://console.spec.whatwg.org/#time
  107. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time)
  108. {
  109. return global_object.console().time();
  110. }
  111. // 1.4.2. timeLog(label, ...data), https://console.spec.whatwg.org/#timelog
  112. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_log)
  113. {
  114. return global_object.console().time_log();
  115. }
  116. // 1.4.3. timeEnd(label), https://console.spec.whatwg.org/#timeend
  117. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_end)
  118. {
  119. return global_object.console().time_end();
  120. }
  121. }