ConsoleObject.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <LibJS/Console.h>
  29. #include <LibJS/Runtime/ConsoleObject.h>
  30. #include <LibJS/Runtime/GlobalObject.h>
  31. namespace JS {
  32. ConsoleObject::ConsoleObject(GlobalObject& global_object)
  33. : Object(*global_object.object_prototype())
  34. {
  35. }
  36. void ConsoleObject::initialize(GlobalObject& global_object)
  37. {
  38. auto& vm = this->vm();
  39. Object::initialize(global_object);
  40. define_native_function(vm.names.log, log);
  41. define_native_function(vm.names.debug, debug);
  42. define_native_function(vm.names.info, info);
  43. define_native_function(vm.names.warn, warn);
  44. define_native_function(vm.names.error, error);
  45. define_native_function(vm.names.trace, trace);
  46. define_native_function(vm.names.count, count);
  47. define_native_function(vm.names.countReset, count_reset);
  48. define_native_function(vm.names.clear, clear);
  49. }
  50. ConsoleObject::~ConsoleObject()
  51. {
  52. }
  53. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log)
  54. {
  55. return global_object.console().log();
  56. }
  57. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug)
  58. {
  59. return global_object.console().debug();
  60. }
  61. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info)
  62. {
  63. return global_object.console().info();
  64. }
  65. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn)
  66. {
  67. return global_object.console().warn();
  68. }
  69. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error)
  70. {
  71. return global_object.console().error();
  72. }
  73. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace)
  74. {
  75. return global_object.console().trace();
  76. }
  77. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count)
  78. {
  79. return global_object.console().count();
  80. }
  81. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset)
  82. {
  83. return global_object.console().count_reset();
  84. }
  85. JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear)
  86. {
  87. return global_object.console().clear();
  88. }
  89. }