[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:
parent
6f946d6c02
commit
9e482baf81
@ -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"],
|
||||
|
@ -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;
|
||||
}
|
||||
|
10
test/message/class-constructor-accessor.js
Normal file
10
test/message/class-constructor-accessor.js
Normal 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() {}
|
||||
}
|
7
test/message/class-constructor-accessor.out
Normal file
7
test/message/class-constructor-accessor.out
Normal 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
|
10
test/message/class-constructor-generator.js
Normal file
10
test/message/class-constructor-generator.js
Normal 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() {}
|
||||
}
|
7
test/message/class-constructor-generator.out
Normal file
7
test/message/class-constructor-generator.out
Normal 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
|
Loading…
Reference in New Issue
Block a user