ladybird/Libraries/LibJS/Runtime/ErrorData.h
Shannon Booth 57130908b3 LibJS+LibWeb: Make DOMException hold an [[ErrorData]] slot
Split JS::ErrorData out of JS::Error so that it can be used both
by JS::Error and WebIDL::DOMException. This adds support for
Error.isError to DOMException, also letting us report DOMException
stack information to the console.
2026-04-08 20:33:53 +02:00

53 lines
1.2 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <AK/Utf16String.h>
#include <AK/Vector.h>
#include <LibGC/Ptr.h>
#include <LibJS/Export.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/SourceRange.h>
namespace JS {
struct JS_API TracebackFrame {
Utf16String function_name;
[[nodiscard]] SourceRange const& source_range() const;
Optional<SourceRange> cached_source_range;
};
enum CompactTraceback {
No,
Yes,
};
class JS_API ErrorData {
public:
explicit ErrorData(VM&);
[[nodiscard]] Utf16String stack_string(CompactTraceback compact = CompactTraceback::No) const;
[[nodiscard]] Vector<TracebackFrame, 32> const& traceback() const { return m_traceback; }
void set_cached_string(GC::Ref<PrimitiveString> string) { m_cached_string = string; }
[[nodiscard]] GC::Ptr<PrimitiveString> cached_string() const { return m_cached_string; }
protected:
void visit_edges(Cell::Visitor&);
private:
void populate_stack(VM&);
Vector<TracebackFrame, 32> m_traceback;
GC::Ptr<PrimitiveString> m_cached_string;
};
}