Bläddra i källkod

LibJS: Emit StringViews for ErrorType instances

This removes the need for calculating each string's length during
ErrorType use at the cost of storing it within the binary.
sin-ack 3 år sedan
förälder
incheckning
3d656ba600

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ErrorTypes.cpp

@@ -9,7 +9,7 @@
 namespace JS {
 
 #define __ENUMERATE_JS_ERROR(name, message) \
-    const ErrorType ErrorType::name = ErrorType(message);
+    const ErrorType ErrorType::name = ErrorType(message##sv);
 JS_ENUMERATE_ERROR_TYPES(__ENUMERATE_JS_ERROR)
 #undef __ENUMERATE_JS_ERROR
 

+ 5 - 3
Userland/Libraries/LibJS/Runtime/ErrorTypes.h

@@ -6,6 +6,8 @@
 
 #pragma once
 
+#include <AK/StringView.h>
+
 #define JS_ENUMERATE_ERROR_TYPES(M)                                                                                                     \
     M(ArrayMaxSize, "Maximum array size exceeded")                                                                                      \
     M(AccessorBadField, "Accessor descriptor's '{}' field must be a function or undefined")                                             \
@@ -306,18 +308,18 @@ public:
     JS_ENUMERATE_ERROR_TYPES(__ENUMERATE_JS_ERROR)
 #undef __ENUMERATE_JS_ERROR
 
-    char const* message() const
+    StringView message() const
     {
         return m_message;
     }
 
 private:
-    explicit ErrorType(char const* message)
+    explicit ErrorType(StringView message)
         : m_message(message)
     {
     }
 
-    char const* m_message;
+    StringView m_message;
 };
 
 }