mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibJS: Make the default constructed reference invalid
Since we have the to_reference method on every expression class we must somehow communicate it did not actually return a reference. This (ab)uses the fact that property name is only invalid with the default constructor and already has is_valid().
This commit is contained in:
parent
ce3f29a135
commit
7081fb4eb0
2 changed files with 8 additions and 1 deletions
|
@ -16,6 +16,11 @@ void Reference::put_value(GlobalObject& global_object, Value value)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
|
if (!is_valid_reference()) {
|
||||||
|
vm.throw_exception<ReferenceError>(global_object, ErrorType::InvalidLeftHandAssignment);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_unresolvable()) {
|
if (is_unresolvable()) {
|
||||||
if (m_strict) {
|
if (m_strict) {
|
||||||
throw_reference_error(global_object);
|
throw_reference_error(global_object);
|
||||||
|
@ -88,7 +93,7 @@ void Reference::throw_reference_error(GlobalObject& global_object) const
|
||||||
// 6.2.4.5 GetValue ( V ), https://tc39.es/ecma262/#sec-getvalue
|
// 6.2.4.5 GetValue ( V ), https://tc39.es/ecma262/#sec-getvalue
|
||||||
Value Reference::get_value(GlobalObject& global_object, bool throw_if_undefined) const
|
Value Reference::get_value(GlobalObject& global_object, bool throw_if_undefined) const
|
||||||
{
|
{
|
||||||
if (is_unresolvable()) {
|
if (!is_valid_reference() || is_unresolvable()) {
|
||||||
throw_reference_error(global_object);
|
throw_reference_error(global_object);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,8 @@ public:
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
|
|
||||||
|
bool is_valid_reference() const { return m_name.is_valid(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void throw_reference_error(GlobalObject&) const;
|
void throw_reference_error(GlobalObject&) const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue