test-js.cpp 794 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibTest/JavaScriptTestRunner.h>
  8. TEST_ROOT("Userland/Libraries/LibJS/Tests");
  9. TESTJS_GLOBAL_FUNCTION(is_strict_mode, isStrictMode, 0)
  10. {
  11. return JS::Value(vm.in_strict_mode());
  12. }
  13. TESTJS_GLOBAL_FUNCTION(can_parse_source, canParseSource)
  14. {
  15. auto source = vm.argument(0).to_string(global_object);
  16. if (vm.exception())
  17. return {};
  18. auto parser = JS::Parser(JS::Lexer(source));
  19. parser.parse_program();
  20. return JS::Value(!parser.has_errors());
  21. }
  22. TESTJS_GLOBAL_FUNCTION(run_queued_promise_jobs, runQueuedPromiseJobs)
  23. {
  24. vm.run_queued_promise_jobs();
  25. return JS::js_undefined();
  26. }