Pārlūkot izejas kodu

LibJS: Throw TypeError when coercing symbol to number

Linus Groh 5 gadi atpakaļ
vecāks
revīzija
4569e88bea

+ 2 - 2
Libraries/LibJS/Runtime/Value.cpp

@@ -231,8 +231,8 @@ Value Value::to_number(Interpreter& interpreter) const
         return Value(parsed_double);
         return Value(parsed_double);
     }
     }
     case Type::Symbol:
     case Type::Symbol:
-        // FIXME: Get access to the interpreter and throw a TypeError
-        ASSERT_NOT_REACHED();
+        interpreter.throw_exception<TypeError>("Can't convert symbol to number");
+        return {};
     case Type::Object:
     case Type::Object:
         auto primitive = m_value.as_object->to_primitive(Object::PreferredType::Number);
         auto primitive = m_value.as_object->to_primitive(Object::PreferredType::Number);
         if (interpreter.exception())
         if (interpreter.exception())

+ 6 - 7
Libraries/LibJS/Tests/Symbol.prototype.toString.js

@@ -14,13 +14,12 @@ try {
         message: "Can't convert symbol to string",
         message: "Can't convert symbol to string",
     });
     });
     
     
-    // FIXME: Uncomment when this doesn't assert
-    // assertThrowsError(() => {
-    //     s1 + 1;
-    // }, {
-    //     error: TypeError,
-    //     message: "Can't convert symbol to number",
-    // });
+    assertThrowsError(() => {
+        s1 + 1;
+    }, {
+        error: TypeError,
+        message: "Can't convert symbol to number",
+    });
     
     
     console.log("PASS");
     console.log("PASS");
 } catch (e) {
 } catch (e) {