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

LibJS+LibWeb: Implement resizable ArrayBuffer support for DataView

This is (part of) a normative change in the ECMA-262 spec. See:
a9ae96e
This commit is contained in:
Timothy Flynn 2023-10-15 09:46:09 -04:00 committed by Andreas Kling
parent 29ac6e3689
commit c7fec9424c
12 changed files with 377 additions and 94 deletions

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <AK/Variant.h>
namespace JS {
class ByteLength {
public:
static ByteLength auto_() { return { Auto {} }; }
static ByteLength detached() { return { Detached {} }; }
ByteLength(u32 length)
: m_length(length)
{
}
bool is_auto() const { return m_length.has<Auto>(); }
bool is_detached() const { return m_length.has<Detached>(); }
u32 length() const
{
VERIFY(m_length.has<u32>());
return m_length.get<u32>();
}
private:
struct Auto { };
struct Detached { };
using Length = Variant<Auto, Detached, u32>;
ByteLength(Length length)
: m_length(move(length))
{
}
Length m_length;
};
}