ConsoleObject.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
  4. * Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include <AK/FlyString.h>
  29. #include <AK/Function.h>
  30. #include <LibJS/Console.h>
  31. #include <LibJS/Runtime/ConsoleObject.h>
  32. #include <LibJS/Runtime/GlobalObject.h>
  33. namespace JS {
  34. ConsoleObject::ConsoleObject(GlobalObject& global_object)
  35. : Object(*global_object.object_prototype())
  36. {
  37. }
  38. void ConsoleObject::initialize(GlobalObject& global_object)
  39. {
  40. Object::initialize(global_object);
  41. define_native_function("log", log);
  42. define_native_function("debug", debug);
  43. define_native_function("info", info);
  44. define_native_function("warn", warn);
  45. define_native_function("error", error);
  46. define_native_function("trace", trace);
  47. define_native_function("count", count);
  48. define_native_function("countReset", count_reset);
  49. define_native_function("clear", clear);
  50. }
  51. ConsoleObject::~ConsoleObject()
  52. {
  53. }
  54. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log)
  55. {
  56. return global_object.console().log();
  57. }
  58. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug)
  59. {
  60. return global_object.console().debug();
  61. }
  62. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info)
  63. {
  64. return global_object.console().info();
  65. }
  66. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn)
  67. {
  68. return global_object.console().warn();
  69. }
  70. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error)
  71. {
  72. return global_object.console().error();
  73. }
  74. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace)
  75. {
  76. return global_object.console().trace();
  77. }
  78. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count)
  79. {
  80. return global_object.console().count();
  81. }
  82. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset)
  83. {
  84. return global_object.console().count_reset();
  85. }
  86. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear)
  87. {
  88. return global_object.console().clear();
  89. }
  90. }