1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 21:35:06 +00:00
serenity/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp
Andreas Kling ffad902c07 LibWeb: Use cached_web_prototype() as much as possible
Unlike ensure_web_prototype<T>(), the cached version doesn't require the
prototype type to be fully formed, so we can use it without including
the FooPrototype.h header. It's also a bit less verbose. :^)
2022-09-06 00:27:09 +02:00

41 lines
1.2 KiB
C++

/*
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/GlobalObject.h>
#include <LibWeb/Bindings/LocationConstructor.h>
#include <LibWeb/Bindings/LocationPrototype.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Bindings {
LocationConstructor::LocationConstructor(JS::Realm& realm)
: NativeFunction(*realm.intrinsics().function_prototype())
{
}
LocationConstructor::~LocationConstructor() = default;
JS::ThrowCompletionOr<JS::Value> LocationConstructor::call()
{
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Location");
}
JS::ThrowCompletionOr<JS::Object*> LocationConstructor::construct(FunctionObject&)
{
return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Location");
}
void LocationConstructor::initialize(JS::Realm& realm)
{
auto& vm = this->vm();
auto& window = verify_cast<HTML::Window>(realm.global_object());
NativeFunction::initialize(realm);
define_direct_property(vm.names.prototype, &window.cached_web_prototype("Location"), 0);
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
}
}