mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 22:30:31 +00:00
LibJS: Throw TypeError when coercing symbol to number
This commit is contained in:
parent
476094922b
commit
4569e88bea
Notes:
sideshowbarker
2024-07-19 06:32:18 +09:00
Author: https://github.com/linusg
Commit: 4569e88bea
Pull-request: https://github.com/SerenityOS/serenity/pull/2270
Issue: https://github.com/SerenityOS/serenity/issues/2267
2 changed files with 8 additions and 9 deletions
|
@ -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
|
interpreter.throw_exception<TypeError>("Can't convert symbol to number");
|
||||||
ASSERT_NOT_REACHED();
|
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())
|
||||||
|
|
|
@ -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(() => {
|
||||||
// assertThrowsError(() => {
|
s1 + 1;
|
||||||
// s1 + 1;
|
}, {
|
||||||
// }, {
|
error: TypeError,
|
||||||
// error: TypeError,
|
message: "Can't convert symbol to number",
|
||||||
// message: "Can't convert symbol to number",
|
});
|
||||||
// });
|
|
||||||
|
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue