mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 09:50:27 +00:00
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.
53 lines
1.2 KiB
C++
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;
|
|
};
|
|
|
|
}
|