WindowConstructor.cpp 1.1 KB

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