mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:58:11 +00:00
LibJS: Add and begin using a completion-compatible string builder
ThrowableStringBuilder is a thin wrapper around StringBuilder to map results from the try_* methods to a throw completion. This will let us try to throw on OOM conditions rather than just blowing up.
This commit is contained in:
parent
fab8ef3dfc
commit
76b9d06b19
4 changed files with 107 additions and 30 deletions
31
Userland/Libraries/LibJS/Runtime/ThrowableStringBuilder.h
Normal file
31
Userland/Libraries/LibJS/Runtime/ThrowableStringBuilder.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/ErrorTypes.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class ThrowableStringBuilder : public AK::StringBuilder {
|
||||
public:
|
||||
explicit ThrowableStringBuilder(VM&);
|
||||
|
||||
ThrowCompletionOr<void> append(char);
|
||||
ThrowCompletionOr<void> append(StringView);
|
||||
ThrowCompletionOr<void> append(Utf16View const&);
|
||||
ThrowCompletionOr<void> append_code_point(u32 value);
|
||||
|
||||
private:
|
||||
VM& m_vm;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue