diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-18 00:54:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-18 09:39:55 +0200 |
commit | 4569e88bea5550b3cc82c31b8df906662fe77ae6 (patch) | |
tree | b3986ee40d94b368b8bc5bcc4d99e62e9589d7f1 /Libraries/LibJS | |
parent | 476094922b6dbbc252a076aecca9cc0d172e540e (diff) | |
download | serenity-4569e88bea5550b3cc82c31b8df906662fe77ae6.zip |
LibJS: Throw TypeError when coercing symbol to number
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r-- | Libraries/LibJS/Runtime/Value.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/Symbol.prototype.toString.js | 13 |
2 files changed, 8 insertions, 9 deletions
diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 7e7c9c054b..37a5d9e3a7 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -231,8 +231,8 @@ Value Value::to_number(Interpreter& interpreter) const return Value(parsed_double); } 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: auto primitive = m_value.as_object->to_primitive(Object::PreferredType::Number); if (interpreter.exception()) diff --git a/Libraries/LibJS/Tests/Symbol.prototype.toString.js b/Libraries/LibJS/Tests/Symbol.prototype.toString.js index cdbcae073e..02abeb2ba1 100644 --- a/Libraries/LibJS/Tests/Symbol.prototype.toString.js +++ b/Libraries/LibJS/Tests/Symbol.prototype.toString.js @@ -14,13 +14,12 @@ try { 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"); } catch (e) { |