NavigatorConstructor.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/GlobalObject.h>
  7. #include <LibWeb/Bindings/NavigatorConstructor.h>
  8. #include <LibWeb/Bindings/NavigatorPrototype.h>
  9. #include <LibWeb/Bindings/WindowObject.h>
  10. namespace Web::Bindings {
  11. NavigatorConstructor::NavigatorConstructor(JS::GlobalObject& global_object)
  12. : NativeFunction(*global_object.function_prototype())
  13. {
  14. }
  15. NavigatorConstructor::~NavigatorConstructor() = default;
  16. JS::ThrowCompletionOr<JS::Value> NavigatorConstructor::call()
  17. {
  18. return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Navigator");
  19. }
  20. JS::ThrowCompletionOr<JS::Object*> NavigatorConstructor::construct(FunctionObject&)
  21. {
  22. return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Navigator");
  23. }
  24. void NavigatorConstructor::initialize(JS::GlobalObject& global_object)
  25. {
  26. auto& vm = this->vm();
  27. auto& window = static_cast<WindowObject&>(global_object);
  28. NativeFunction::initialize(global_object);
  29. define_direct_property(vm.names.prototype, &window.ensure_web_prototype<NavigatorPrototype>("Navigator"), 0);
  30. define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
  31. }
  32. }