ConsoleObject.cpp 3.1 KB

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