Title: [273846] trunk
- Revision
- 273846
- Author
- ticaiol...@gmail.com
- Date
- 2021-03-03 15:00:09 -0800 (Wed, 03 Mar 2021)
Log Message
[ESNext] Private methods can't be named as '#constructor'
https://bugs.webkit.org/show_bug.cgi?id=222680
Reviewed by Yusuke Suzuki.
JSTests:
* stress/private-method-and-field-named-constructor.js: Added.
Source/_javascript_Core:
It's a `SyntaxError` when we try to use `#constructor` as private name
for methods, accessors, and fields. This patch is fixing such bug for
methods and accessors.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseClass):
(JSC::Parser<LexerType>::parseGetterSetter):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (273845 => 273846)
--- trunk/JSTests/ChangeLog 2021-03-03 22:57:13 UTC (rev 273845)
+++ trunk/JSTests/ChangeLog 2021-03-03 23:00:09 UTC (rev 273846)
@@ -1,3 +1,12 @@
+2021-03-03 Caio Lima <ticaiol...@gmail.com>
+
+ [ESNext] Private methods can't be named as '#constructor'
+ https://bugs.webkit.org/show_bug.cgi?id=222680
+
+ Reviewed by Yusuke Suzuki.
+
+ * stress/private-method-and-field-named-constructor.js: Added.
+
2021-03-03 Alexey Shvayka <shvaikal...@gmail.com>
Add JSModuleNamespaceObject::deletePropertyByIndex() method
Added: trunk/JSTests/stress/private-method-and-field-named-constructor.js (0 => 273846)
--- trunk/JSTests/stress/private-method-and-field-named-constructor.js (rev 0)
+++ trunk/JSTests/stress/private-method-and-field-named-constructor.js 2021-03-03 23:00:09 UTC (rev 273846)
@@ -0,0 +1,32 @@
+//@ requireOptions("--usePrivateMethods=true")
+
+function assertSyntaxError(code) {
+ try {
+ eval(code);
+ throw new Error("Should throw SyntaxError, but executed code without throwing");
+ } catch(e) {
+ if (!e instanceof SyntaxError)
+ throw new Error("Should throw SyntaxError, but threw " + e);
+ }
+}
+
+assertSyntaxError("let C = class { #constructor() {} }");
+assertSyntaxError("let C = class { static #constructor() {} }");
+assertSyntaxError("class C { #constructor() {} }");
+assertSyntaxError("class C { static #constructor() {} }");
+
+assertSyntaxError("let C = class { get #constructor() {} }");
+assertSyntaxError("let C = class { static get #constructor() {} }");
+assertSyntaxError("class C { get #constructor() {} }");
+assertSyntaxError("class C { static get #constructor() {} }");
+
+assertSyntaxError("let C = class { set #constructor(v) {} }");
+assertSyntaxError("let C = class { static set #constructor(v) {} }");
+assertSyntaxError("class C { set #constructor(v) {} }");
+assertSyntaxError("class C { static set #constructor(v) {} }");
+
+assertSyntaxError("let C = class { #constructor; }");
+assertSyntaxError("let C = class { static #constructor; }");
+assertSyntaxError("class C { #constructor; }");
+assertSyntaxError("class C { static #constructor; }");
+
Modified: trunk/Source/_javascript_Core/ChangeLog (273845 => 273846)
--- trunk/Source/_javascript_Core/ChangeLog 2021-03-03 22:57:13 UTC (rev 273845)
+++ trunk/Source/_javascript_Core/ChangeLog 2021-03-03 23:00:09 UTC (rev 273846)
@@ -1,3 +1,18 @@
+2021-03-03 Caio Lima <ticaiol...@gmail.com>
+
+ [ESNext] Private methods can't be named as '#constructor'
+ https://bugs.webkit.org/show_bug.cgi?id=222680
+
+ Reviewed by Yusuke Suzuki.
+
+ It's a `SyntaxError` when we try to use `#constructor` as private name
+ for methods, accessors, and fields. This patch is fixing such bug for
+ methods and accessors.
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseClass):
+ (JSC::Parser<LexerType>::parseGetterSetter):
+
2021-03-03 Commit Queue <commit-qu...@webkit.org>
Unreviewed, reverting r273814.
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (273845 => 273846)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2021-03-03 22:57:13 UTC (rev 273845)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2021-03-03 23:00:09 UTC (rev 273846)
@@ -3015,7 +3015,7 @@
next();
if (Options::usePrivateMethods() && match(OPENPAREN)) {
semanticFailIfTrue(classScope->declarePrivateMethod(*ident, tag) & DeclarationResult::InvalidDuplicateDeclaration, "Cannot declare private method twice");
- semanticFailIfTrue(tag == ClassElementTag::Static && *ident == propertyNames.constructorPrivateField, "Cannot declare a static private method named 'constructor'");
+ semanticFailIfTrue(*ident == propertyNames.constructorPrivateField, "Cannot declare a private method named '#constructor'");
if (tag == ClassElementTag::Static)
declaresStaticPrivateAccessor = true;
@@ -4482,6 +4482,7 @@
"Cannot declare a static method named 'prototype'");
semanticFailIfTrue(tag == ClassElementTag::Instance && *stringPropertyName == m_vm.propertyNames->constructor,
"Cannot declare a getter or setter named 'constructor'");
+ semanticFailIfTrue(*stringPropertyName == m_vm.propertyNames->constructorPrivateField, "Cannot declare a private accessor named '#constructor'");
if (match(PRIVATENAME))
semanticFailIfTrue(tag == ClassElementTag::No, "Cannot declare a private setter or getter outside a class");
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes