[parser] better error message for generator constructors

BUG=
LOG=N
R=arv@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27051}
This commit is contained in:
caitpotter88 2015-03-06 08:54:34 -08:00 committed by Commit bot
parent 6f946d6c02
commit 9e482baf81
6 changed files with 39 additions and 2 deletions

View 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"],

View 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;
}

View File

@ -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() {}
}

View File

@ -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

View File

@ -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() {}
}

View File

@ -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