From 8cbd25f553d19a69370947d7a02eaade35cf0c8d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 1 May 2022 01:38:21 +0200 Subject: LibJS: Simplify Is{Accessor,Data,Generic}Descriptor AOs This is an editorial change in the ECMA-262 spec. See: https://github.com/tc39/ecma262/commit/1c7ae4b --- .../Libraries/LibJS/Runtime/PropertyDescriptor.cpp | 42 ++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp index 270420aebc..1a93267bdc 100644 --- a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp @@ -18,12 +18,16 @@ bool PropertyDescriptor::is_accessor_descriptor() const { // 1. If Desc is undefined, return false. - // 2. If Desc does not have a [[Get]] field and Desc does not have a [[Set]] field, return false. - if (!get.has_value() && !set.has_value()) - return false; + // 2. If Desc has a [[Get]] field, return true. + if (get.has_value()) + return true; - // 3. Return true. - return true; + // 3. If Desc has a [[Set]] field, return true. + if (set.has_value()) + return true; + + // 4. Return false. + return false; } // 6.2.5.2 IsDataDescriptor ( Desc ), https://tc39.es/ecma262/#sec-isdatadescriptor @@ -31,12 +35,16 @@ bool PropertyDescriptor::is_data_descriptor() const { // 1. If Desc is undefined, return false. - // 2. If Desc does not have a [[Value]] field and Desc does not have a [[Writable]] field, return false. - if (!value.has_value() && !writable.has_value()) - return false; + // 2. If Desc has a [[Value]] field, return true. + if (value.has_value()) + return true; - // 3. Return true. - return true; + // 3. If Desc has a [[Writable]] field, return true. + if (writable.has_value()) + return true; + + // 4. Return false. + return false; } // 6.2.5.3 IsGenericDescriptor ( Desc ), https://tc39.es/ecma262/#sec-isgenericdescriptor @@ -44,12 +52,16 @@ bool PropertyDescriptor::is_generic_descriptor() const { // 1. If Desc is undefined, return false. - // 2. If IsAccessorDescriptor(Desc) and IsDataDescriptor(Desc) are both false, return true. - if (!is_accessor_descriptor() && !is_data_descriptor()) - return true; + // 2. If IsAccessorDescriptor(Desc) is true, return false. + if (is_accessor_descriptor()) + return false; - // 3. Return false. - return false; + // 3. If IsDataDescriptor(Desc) is true, return false. + if (is_data_descriptor()) + return false; + + // 4. Return true. + return true; } // 6.2.5.4 FromPropertyDescriptor ( Desc ), https://tc39.es/ecma262/#sec-frompropertydescriptor -- cgit v1.2.3