LocationConstructor.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/LocationConstructor.h>
  8. #include <LibWeb/Bindings/LocationPrototype.h>
  9. #include <LibWeb/Bindings/WindowObject.h>
  10. namespace Web::Bindings {
  11. LocationConstructor::LocationConstructor(JS::GlobalObject& global_object)
  12. : NativeFunction(*global_object.function_prototype())
  13. {
  14. }
  15. LocationConstructor::~LocationConstructor() = default;
  16. JS::ThrowCompletionOr<JS::Value> LocationConstructor::call()
  17. {
  18. return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "Location");
  19. }
  20. JS::ThrowCompletionOr<JS::Object*> LocationConstructor::construct(FunctionObject&)
  21. {
  22. return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Location");
  23. }
  24. void LocationConstructor::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<LocationPrototype>("Location"), 0);
  30. define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
  31. }
  32. }