mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 03:55:07 +00:00

This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this.
41 lines
1.2 KiB
C++
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/WindowConstructor.h>
|
|
#include <LibWeb/Bindings/WindowPrototype.h>
|
|
#include <LibWeb/HTML/Window.h>
|
|
|
|
namespace Web::Bindings {
|
|
|
|
WindowConstructor::WindowConstructor(JS::Realm& realm)
|
|
: NativeFunction(*realm.intrinsics().function_prototype())
|
|
{
|
|
}
|
|
|
|
WindowConstructor::~WindowConstructor() = default;
|
|
|
|
JS::ThrowCompletionOr<JS::Value> WindowConstructor::call()
|
|
{
|
|
return vm().throw_completion<JS::TypeError>(JS::ErrorType::ConstructorWithoutNew, "Window");
|
|
}
|
|
|
|
JS::ThrowCompletionOr<JS::Object*> WindowConstructor::construct(FunctionObject&)
|
|
{
|
|
return vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Window");
|
|
}
|
|
|
|
void WindowConstructor::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.ensure_web_prototype<WindowPrototype>("Window"), 0);
|
|
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
|
}
|
|
|
|
}
|