[parser] better error message for generator constructors
authorcaitpotter88 <caitpotter88@gmail.com>
Fri, 6 Mar 2015 16:54:34 +0000 (08:54 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 6 Mar 2015 16:54:39 +0000 (16:54 +0000)
BUG=
LOG=N
R=arv@chromium.org

Review URL: https://codereview.chromium.org/982153003

Cr-Commit-Position: refs/heads/master@{#27051}

src/messages.js
src/preparser.h
test/message/class-constructor-accessor.js [new file with mode: 0644]
test/message/class-constructor-accessor.out [new file with mode: 0644]
test/message/class-constructor-generator.js [new file with mode: 0644]
test/message/class-constructor-generator.out [new file with mode: 0644]

index ba739987897417c7917901659d68f892cc8fe0ac..f0e71d9578db50cdd27eb56e3ab9db3b4d3653aa 100644 (file)
@@ -8,7 +8,8 @@ var kMessages = {
   // Error
   cyclic_proto:                  ["Cyclic __proto__ value"],
   code_gen_from_strings:         ["%0"],
-  constructor_special_method:    ["Class constructor may not be an accessor"],
+  constructor_is_generator:      ["Class constructor may not be a generator"],
+  constructor_is_accessor:       ["Class constructor may not be an accessor"],
   // TypeError
   generator_running:             ["Generator is already running"],
   unexpected_token:              ["Unexpected token ", "%0"],
index 4a35cd59f52dfa71426abc71f58937ce3d783f86..7df271f6baad4152aa359f3377e6d5609b97bbe6 100644 (file)
@@ -3106,7 +3106,9 @@ void ParserBase<Traits>::ClassLiteralChecker::CheckProperty(
     }
   } else if (IsConstructor()) {
     if (is_generator || type == kAccessorProperty) {
-      this->parser()->ReportMessage("constructor_special_method");
+      const char* msg =
+          is_generator ? "constructor_is_generator" : "constructor_is_accessor";
+      this->parser()->ReportMessage(msg);
       *ok = false;
       return;
     }
diff --git a/test/message/class-constructor-accessor.js b/test/message/class-constructor-accessor.js
new file mode 100644 (file)
index 0000000..edc3c13
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Flags: --harmony-classes
+'use strict';
+
+class C {
+  get constructor() {}
+}
diff --git a/test/message/class-constructor-accessor.out b/test/message/class-constructor-accessor.out
new file mode 100644 (file)
index 0000000..8776f54
--- /dev/null
@@ -0,0 +1,7 @@
+# Copyright 2014 the V8 project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+*%(basename)s:9: SyntaxError: Class constructor may not be an accessor
+  get constructor() {}
+      ^^^^^^^^^^^
+SyntaxError: Class constructor may not be an accessor
diff --git a/test/message/class-constructor-generator.js b/test/message/class-constructor-generator.js
new file mode 100644 (file)
index 0000000..5d370f8
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Flags: --harmony-classes
+'use strict';
+
+class C {
+  *constructor() {}
+}
diff --git a/test/message/class-constructor-generator.out b/test/message/class-constructor-generator.out
new file mode 100644 (file)
index 0000000..5075e51
--- /dev/null
@@ -0,0 +1,7 @@
+# Copyright 2014 the V8 project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+*%(basename)s:9: SyntaxError: Class constructor may not be a generator
+  *constructor() {}
+   ^^^^^^^^^^^
+SyntaxError: Class constructor may not be a generator