1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:37:35 +00:00

LibWeb: Make MediaList GC-allocated

This commit is contained in:
Andreas Kling 2022-08-08 15:32:27 +02:00
parent 0176d42f49
commit cfdb8f2a8e
9 changed files with 58 additions and 35 deletions

View file

@ -1,16 +1,25 @@
/*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/MediaListPrototype.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/CSS/MediaList.h>
#include <LibWeb/CSS/Parser/Parser.h>
namespace Web::CSS {
MediaList::MediaList(NonnullRefPtrVector<MediaQuery>&& media)
: m_media(move(media))
MediaList* MediaList::create(Bindings::WindowObject& window_object, NonnullRefPtrVector<MediaQuery>&& media)
{
return window_object.heap().allocate<MediaList>(window_object.realm(), window_object, move(media));
}
MediaList::MediaList(Bindings::WindowObject& window_object, NonnullRefPtrVector<MediaQuery>&& media)
: Bindings::LegacyPlatformObject(window_object.ensure_web_prototype<Bindings::MediaListPrototype>("MediaList"))
, m_media(move(media))
{
}
@ -83,4 +92,11 @@ bool MediaList::matches() const
return false;
}
JS::Value MediaList::item_value(size_t index) const
{
if (index >= m_media.size())
return JS::js_undefined();
return JS::js_string(vm(), m_media[index].to_string());
}
}