Selaa lähdekoodia

LibJS: Make Value::typeof() return a StringView

Linus Groh 2 vuotta sitten
vanhempi
commit
2ff989914d

+ 12 - 12
Userland/Libraries/LibJS/Runtime/Value.cpp

@@ -1,6 +1,6 @@
 /*
 /*
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
  * Copyright (c) 2022, David Tuin <davidot@serenityos.org>
  * Copyright (c) 2022, David Tuin <davidot@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
@@ -314,42 +314,42 @@ ThrowCompletionOr<bool> Value::is_regexp(VM& vm) const
 }
 }
 
 
 // 13.5.3 The typeof Operator, https://tc39.es/ecma262/#sec-typeof-operator
 // 13.5.3 The typeof Operator, https://tc39.es/ecma262/#sec-typeof-operator
-DeprecatedString Value::typeof() const
+StringView Value::typeof() const
 {
 {
     // 9. If val is a Number, return "number".
     // 9. If val is a Number, return "number".
     if (is_number())
     if (is_number())
-        return "number";
+        return "number"sv;
 
 
     switch (m_value.tag) {
     switch (m_value.tag) {
     // 4. If val is undefined, return "undefined".
     // 4. If val is undefined, return "undefined".
     case UNDEFINED_TAG:
     case UNDEFINED_TAG:
-        return "undefined";
+        return "undefined"sv;
     // 5. If val is null, return "object".
     // 5. If val is null, return "object".
     case NULL_TAG:
     case NULL_TAG:
-        return "object";
+        return "object"sv;
     // 6. If val is a String, return "string".
     // 6. If val is a String, return "string".
     case STRING_TAG:
     case STRING_TAG:
-        return "string";
+        return "string"sv;
     // 7. If val is a Symbol, return "symbol".
     // 7. If val is a Symbol, return "symbol".
     case SYMBOL_TAG:
     case SYMBOL_TAG:
-        return "symbol";
+        return "symbol"sv;
     // 8. If val is a Boolean, return "boolean".
     // 8. If val is a Boolean, return "boolean".
     case BOOLEAN_TAG:
     case BOOLEAN_TAG:
-        return "boolean";
+        return "boolean"sv;
     // 10. If val is a BigInt, return "bigint".
     // 10. If val is a BigInt, return "bigint".
     case BIGINT_TAG:
     case BIGINT_TAG:
-        return "bigint";
+        return "bigint"sv;
     // 11. Assert: val is an Object.
     // 11. Assert: val is an Object.
     case OBJECT_TAG:
     case OBJECT_TAG:
         // B.3.6.3 Changes to the typeof Operator, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-typeof
         // B.3.6.3 Changes to the typeof Operator, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-typeof
         // 12. If val has an [[IsHTMLDDA]] internal slot, return "undefined".
         // 12. If val has an [[IsHTMLDDA]] internal slot, return "undefined".
         if (as_object().is_htmldda())
         if (as_object().is_htmldda())
-            return "undefined";
+            return "undefined"sv;
         // 13. If val has a [[Call]] internal slot, return "function".
         // 13. If val has a [[Call]] internal slot, return "function".
         if (is_function())
         if (is_function())
-            return "function";
+            return "function"sv;
         // 14. Return "object".
         // 14. Return "object".
-        return "object";
+        return "object"sv;
     default:
     default:
         VERIFY_NOT_REACHED();
         VERIFY_NOT_REACHED();
     }
     }

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Value.h

@@ -1,6 +1,6 @@
 /*
 /*
  * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2020-2023, Linus Groh <linusg@serenityos.org>
  * Copyright (c) 2022, David Tuin <davidot@serenityos.org>
  * Copyright (c) 2022, David Tuin <davidot@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
@@ -404,7 +404,7 @@ public:
         return *this;
         return *this;
     }
     }
 
 
-    DeprecatedString typeof() const;
+    StringView typeof() const;
 
 
     bool operator==(Value const&) const;
     bool operator==(Value const&) const;