2024-07-15 14:59:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-08-31 13:05:40 +00:00
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/StringView.h>
|
2024-11-14 15:01:23 +00:00
|
|
|
#include <LibGC/Ptr.h>
|
2024-07-15 14:59:29 +00:00
|
|
|
#include <LibJS/Forward.h>
|
2024-08-31 13:05:40 +00:00
|
|
|
#include <LibJS/Runtime/Completion.h>
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
2024-07-15 14:59:29 +00:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2024-08-31 13:05:40 +00:00
|
|
|
class Uint8ArrayConstructorHelpers {
|
|
|
|
public:
|
|
|
|
static void initialize(Realm&, Object& constructor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(from_base64);
|
2024-09-01 22:37:12 +00:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(from_hex);
|
2024-08-31 13:05:40 +00:00
|
|
|
};
|
|
|
|
|
2024-07-15 14:59:29 +00:00
|
|
|
class Uint8ArrayPrototypeHelpers {
|
|
|
|
public:
|
|
|
|
static void initialize(Realm&, Object& prototype);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(to_base64);
|
2024-07-15 16:30:26 +00:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(to_hex);
|
2024-08-31 14:24:01 +00:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(set_from_base64);
|
2024-09-01 22:44:39 +00:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(set_from_hex);
|
2024-07-15 14:59:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class Alphabet {
|
|
|
|
Base64,
|
|
|
|
Base64URL,
|
|
|
|
};
|
|
|
|
|
2024-08-31 13:05:40 +00:00
|
|
|
enum class LastChunkHandling {
|
|
|
|
Loose,
|
|
|
|
Strict,
|
|
|
|
StopBeforePartial,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DecodeResult {
|
|
|
|
size_t read { 0 }; // [[Read]]
|
|
|
|
ByteBuffer bytes; // [[Bytes]]
|
|
|
|
Optional<Completion> error; // [[Error]]
|
|
|
|
};
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
ThrowCompletionOr<GC::Ref<TypedArrayBase>> validate_uint8_array(VM&);
|
2024-07-15 14:59:29 +00:00
|
|
|
ThrowCompletionOr<ByteBuffer> get_uint8_array_bytes(VM&, TypedArrayBase const&);
|
2024-08-31 14:24:01 +00:00
|
|
|
void set_uint8_array_bytes(TypedArrayBase&, ReadonlyBytes);
|
2024-08-31 13:05:40 +00:00
|
|
|
DecodeResult from_base64(VM&, StringView string, Alphabet alphabet, LastChunkHandling last_chunk_handling, Optional<size_t> max_length = {});
|
2024-09-01 22:37:12 +00:00
|
|
|
DecodeResult from_hex(VM&, StringView string, Optional<size_t> max_length = {});
|
2024-07-15 14:59:29 +00:00
|
|
|
|
|
|
|
}
|