mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 02:08:11 +00:00
DevTools+LibJS+LibWeb: Change class_name to use StringView
This helps make the overall codebase consistent. `class_name()` in `Kernel` is always `StringView`, but not elsewhere. Additionally, this results in the `strlen` (which needs to be done when printing or other operations) always being computed at compile-time.
This commit is contained in:
parent
5b7a5b3c01
commit
a0367aa43b
17 changed files with 37 additions and 20 deletions
|
@ -9,6 +9,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "DebuggerGlobalJSObject.h"
|
||||
#include <AK/StringView.h>
|
||||
#include <LibDebug/DebugInfo.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
@ -24,7 +25,7 @@ public:
|
|||
DebuggerVariableJSObject(const Debug::DebugInfo::VariableInfo& variable_info, JS::Object& prototype);
|
||||
virtual ~DebuggerVariableJSObject() override = default;
|
||||
|
||||
virtual const char* class_name() const override { return m_variable_info.type_name.characters(); }
|
||||
virtual StringView class_name() const override { return m_variable_info.type_name; }
|
||||
|
||||
JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Format.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -32,7 +33,7 @@ public:
|
|||
State state() const { return m_state; }
|
||||
void set_state(State state) { m_state = state; }
|
||||
|
||||
virtual const char* class_name() const = 0;
|
||||
virtual StringView class_name() const = 0;
|
||||
|
||||
class Visitor {
|
||||
public:
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <AK/Platform.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
@ -98,7 +99,7 @@ private:
|
|||
struct FreelistEntry final : public Cell {
|
||||
FreelistEntry* next { nullptr };
|
||||
|
||||
virtual const char* class_name() const override { return "FreelistEntry"; }
|
||||
virtual StringView class_name() const override { return "FreelistEntry"sv; }
|
||||
};
|
||||
|
||||
Cell* cell(size_t index)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/FunctionObject.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
|
||||
|
@ -38,7 +39,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
const char* class_name() const override { return "Accessor"; };
|
||||
StringView class_name() const override { return "Accessor"sv; };
|
||||
|
||||
FunctionObject* m_getter { nullptr };
|
||||
FunctionObject* m_setter { nullptr };
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
||||
|
@ -20,7 +21,7 @@ public:
|
|||
const String to_string() const { return String::formatted("{}n", m_big_integer.to_base(10)); }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "BigInt"; }
|
||||
virtual StringView class_name() const override { return "BigInt"sv; }
|
||||
|
||||
Crypto::SignedBigInteger m_big_integer;
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
|
@ -19,7 +20,7 @@ struct Variable {
|
|||
#define JS_ENVIRONMENT(class_, base_class) \
|
||||
public: \
|
||||
using Base = base_class; \
|
||||
virtual char const* class_name() const override { return #class_; }
|
||||
virtual StringView class_name() const override { return #class_; }
|
||||
|
||||
class Environment : public Cell {
|
||||
public:
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
template<typename T>
|
||||
bool fast_is() const = delete;
|
||||
|
||||
virtual char const* class_name() const override { return "Environment"; }
|
||||
virtual StringView class_name() const override { return "Environment"sv; }
|
||||
|
||||
// This flag is set on the entire variable environment chain when direct eval() is performed.
|
||||
// It is used to disable non-local variable access caching.
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/Badge.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Heap/MarkedVector.h>
|
||||
|
@ -27,7 +28,7 @@ namespace JS {
|
|||
#define JS_OBJECT(class_, base_class) \
|
||||
public: \
|
||||
using Base = base_class; \
|
||||
virtual const char* class_name() const override { return #class_; }
|
||||
virtual StringView class_name() const override { return #class_; }
|
||||
|
||||
struct PrivateElement {
|
||||
enum class Kind {
|
||||
|
@ -166,7 +167,7 @@ public:
|
|||
bool has_parameter_map() const { return m_has_parameter_map; }
|
||||
void set_has_parameter_map() { m_has_parameter_map = true; }
|
||||
|
||||
virtual const char* class_name() const override { return "Object"; }
|
||||
virtual StringView class_name() const override { return "Object"sv; }
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Value get_direct(size_t index) const { return m_storage[index]; }
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Runtime/Utf16String.h>
|
||||
|
@ -33,7 +34,7 @@ public:
|
|||
Optional<Value> get(GlobalObject&, PropertyKey const&) const;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "PrimitiveString"; }
|
||||
virtual StringView class_name() const override { return "PrimitiveString"sv; }
|
||||
|
||||
mutable String m_utf8_string;
|
||||
mutable bool m_has_utf8_string { false };
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
void add_private_name(Badge<ClassExpression>, FlyString description);
|
||||
|
||||
private:
|
||||
virtual char const* class_name() const override { return "PrivateEnvironment"; }
|
||||
virtual StringView class_name() const override { return "PrivateEnvironment"sv; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
auto find_private_name(FlyString const& description) const
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/JobCallback.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
|
@ -79,7 +80,7 @@ public:
|
|||
const Optional<JobCallback>& handler() const { return m_handler; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "PromiseReaction"; }
|
||||
virtual StringView class_name() const override { return "PromiseReaction"sv; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
Type m_type;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
#include <LibJS/Runtime/PromiseReaction.h>
|
||||
|
||||
|
@ -19,7 +20,7 @@ struct RemainingElements final : public Cell {
|
|||
{
|
||||
}
|
||||
|
||||
virtual const char* class_name() const override { return "RemainingElements"; }
|
||||
virtual StringView class_name() const override { return "RemainingElements"sv; }
|
||||
|
||||
u64 value { 0 };
|
||||
};
|
||||
|
@ -34,7 +35,7 @@ public:
|
|||
Vector<Value> const& values() const { return m_values; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "PromiseValueList"; }
|
||||
virtual StringView class_name() const override { return "PromiseValueList"sv; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
Vector<Value> m_values;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -13,7 +14,7 @@ namespace JS {
|
|||
struct AlreadyResolved final : public Cell {
|
||||
bool value { false };
|
||||
|
||||
virtual const char* class_name() const override { return "AlreadyResolved"; }
|
||||
virtual StringView class_name() const override { return "AlreadyResolved"sv; }
|
||||
|
||||
protected:
|
||||
// Allocated cells must be >= sizeof(FreelistEntry), which is 24 bytes -
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
void set_host_defined(OwnPtr<HostDefined> host_defined) { m_host_defined = move(host_defined); }
|
||||
|
||||
private:
|
||||
virtual char const* class_name() const override { return "Realm"; }
|
||||
virtual StringView class_name() const override { return "Realm"sv; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
GlobalObject* m_global_object { nullptr }; // [[GlobalObject]]
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
@ -86,7 +87,7 @@ public:
|
|||
void reconfigure_property_in_unique_shape(const StringOrSymbol& property_key, PropertyAttributes attributes);
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "Shape"; }
|
||||
virtual StringView class_name() const override { return "Shape"sv; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
Shape* get_or_prune_cached_forward_transition(TransitionKey const&);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -25,7 +26,7 @@ public:
|
|||
String to_string() const { return String::formatted("Symbol({})", description()); }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "Symbol"; }
|
||||
virtual StringView class_name() const override { return "Symbol"sv; }
|
||||
|
||||
Optional<String> m_description;
|
||||
bool m_is_global;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
@ -21,7 +22,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
virtual const char* class_name() const override { return "AudioConstructor"; }
|
||||
virtual StringView class_name() const override { return "AudioConstructor"sv; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
@ -21,7 +22,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual bool has_constructor() const override { return true; }
|
||||
virtual const char* class_name() const override { return "ImageConstructor"; }
|
||||
virtual StringView class_name() const override { return "ImageConstructor"sv; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue