Bladeren bron

LibJS: Do not coerce nullish references to unresolvable references

These are not strictly unresolvable references. Treating them as such
fails an assertion in the `delete UnaryExpression` semantic (which is
Reference::delete_ in our implementation) - we enter the unresolvable,
branch, which then asserts that the [[Strict]] slot of the reference is
false.
Timothy Flynn 2 jaren geleden
bovenliggende
commit
2b19d1b5ab

+ 0 - 6
Userland/Libraries/LibJS/Runtime/Reference.h

@@ -38,12 +38,6 @@ public:
         , m_this_value(this_value)
         , m_strict(strict)
     {
-        if (base.is_nullish()) {
-            m_base_type = BaseType::Unresolvable;
-            m_base_value = {};
-            m_this_value = {};
-            m_name = {};
-        }
     }
 
     Reference(Environment& base, DeprecatedFlyString referenced_name, bool strict = false, Optional<EnvironmentCoordinate> environment_coordinate = {})

+ 11 - 0
Userland/Libraries/LibJS/Tests/operators/delete-basic.js

@@ -87,6 +87,12 @@ test("deleting super property", () => {
         }
     }
 
+    class C {
+        static foo() {
+            delete super.bar;
+        }
+    }
+
     const obj = new B();
     expect(() => {
         obj.bar();
@@ -95,6 +101,11 @@ test("deleting super property", () => {
     expect(() => {
         obj.baz();
     }).toThrowWithMessage(ReferenceError, "Can't delete a property on 'super'");
+
+    Object.setPrototypeOf(C, null);
+    expect(() => {
+        C.foo();
+    }).toThrowWithMessage(ReferenceError, "Can't delete a property on 'super'");
 });
 
 test("deleting an object computed property coerces the object to a property key", () => {