Title: [278510] trunk
Revision
278510
Author
ysuz...@apple.com
Date
2021-06-04 16:44:21 -0700 (Fri, 04 Jun 2021)

Log Message

[JSC] Private static method should define privateClassBrandIdentifier in class-scope
https://bugs.webkit.org/show_bug.cgi?id=226656
rdar://78313139

Reviewed by Keith Miller.

JSTests:

* stress/private-in-error.js: Added.
(shouldThrow):
(x):
(prototype.foo):
* stress/private-static-method-declaration-error.js: Added.
(shouldThrow):
(prototype.get x):
(prototype.foo.D.a):
(prototype.foo.D.prototype.b):
(prototype.foo.D):
(prototype.foo):

Source/_javascript_Core:

We accidentally made `declaresStaticPrivateMethod` always `false`.
This patch fixes that so that we properly define privateClassBrandIdentifier field in the class-scope if static-private-method is defined.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseClass):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (278509 => 278510)


--- trunk/JSTests/ChangeLog	2021-06-04 22:45:52 UTC (rev 278509)
+++ trunk/JSTests/ChangeLog	2021-06-04 23:44:21 UTC (rev 278510)
@@ -1,3 +1,23 @@
+2021-06-04  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] Private static method should define privateClassBrandIdentifier in class-scope
+        https://bugs.webkit.org/show_bug.cgi?id=226656
+        rdar://78313139
+
+        Reviewed by Keith Miller.
+
+        * stress/private-in-error.js: Added.
+        (shouldThrow):
+        (x):
+        (prototype.foo):
+        * stress/private-static-method-declaration-error.js: Added.
+        (shouldThrow):
+        (prototype.get x):
+        (prototype.foo.D.a):
+        (prototype.foo.D.prototype.b):
+        (prototype.foo.D):
+        (prototype.foo):
+
 2021-06-04  Mark Lam  <mark....@apple.com>
 
         Placate exception checker validation in objectPrototypeHasOwnProperty.

Added: trunk/JSTests/stress/private-in-error.js (0 => 278510)


--- trunk/JSTests/stress/private-in-error.js	                        (rev 0)
+++ trunk/JSTests/stress/private-in-error.js	2021-06-04 23:44:21 UTC (rev 278510)
@@ -0,0 +1,28 @@
+//@ requireOptions("--usePrivateIn=1")
+function shouldThrow(func, errorMessage) {
+    var errorThrown = false;
+    var error = null;
+    try {
+        func();
+    } catch (e) {
+        errorThrown = true;
+        error = e;
+    }
+    if (!errorThrown)
+        throw new Error('not thrown');
+    if (String(error) !== errorMessage)
+        throw new Error(`bad error: ${String(error)}`);
+}
+
+class C {
+  static #x() {}
+
+  foo() {
+      return #x in 42;
+  }
+}
+
+shouldThrow(() => {
+    let c = new C();
+    c.foo();
+}, `TypeError: Cannot access static private method or accessor of a non-Object`);

Added: trunk/JSTests/stress/private-static-method-declaration-error.js (0 => 278510)


--- trunk/JSTests/stress/private-static-method-declaration-error.js	                        (rev 0)
+++ trunk/JSTests/stress/private-static-method-declaration-error.js	2021-06-04 23:44:21 UTC (rev 278510)
@@ -0,0 +1,34 @@
+function shouldThrow(func, errorMessage) {
+    var errorThrown = false;
+    var error = null;
+    try {
+        func();
+    } catch (e) {
+        errorThrown = true;
+        error = e;
+    }
+    if (!errorThrown)
+        throw new Error('not thrown');
+    if (String(error) !== errorMessage)
+        throw new Error(`bad error: ${String(error)}`);
+}
+
+class C {
+  get #x() {}
+
+  foo() {
+    class D {
+      static #a() {}
+      b() {
+        return ''.#a;
+      }
+    }
+    let d = new D();
+    d.b();
+  }
+}
+
+shouldThrow(() => {
+    let c = new C();
+    c.foo();
+}, `TypeError: Cannot access static private method or accessor`);

Modified: trunk/Source/_javascript_Core/ChangeLog (278509 => 278510)


--- trunk/Source/_javascript_Core/ChangeLog	2021-06-04 22:45:52 UTC (rev 278509)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-06-04 23:44:21 UTC (rev 278510)
@@ -1,3 +1,17 @@
+2021-06-04  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] Private static method should define privateClassBrandIdentifier in class-scope
+        https://bugs.webkit.org/show_bug.cgi?id=226656
+        rdar://78313139
+
+        Reviewed by Keith Miller.
+
+        We accidentally made `declaresStaticPrivateMethod` always `false`.
+        This patch fixes that so that we properly define privateClassBrandIdentifier field in the class-scope if static-private-method is defined.
+
+        * parser/Parser.cpp:
+        (JSC::Parser<LexerType>::parseClass):
+
 2021-06-04  Filip Pizlo  <fpi...@apple.com>
 
         Don't emit the NotDouble checks if we're already NotDouble.

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (278509 => 278510)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2021-06-04 22:45:52 UTC (rev 278509)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2021-06-04 23:44:21 UTC (rev 278510)
@@ -3033,7 +3033,7 @@
                 semanticFailIfTrue(*ident == propertyNames.constructorPrivateField, "Cannot declare a private method named '#constructor'");
 
                 if (tag == ClassElementTag::Static)
-                    declaresStaticPrivateAccessor = true;
+                    declaresStaticPrivateMethod = true;
                 else
                     declaresPrivateMethod = true;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to