Support get/set function declarations in classes in the pre-scanner. (#3098)
Fixes #3094 Fixes #3095 Fixes #3096 JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Robert Fancsik
parent
fc30f003ba
commit
57de923770
@@ -2457,7 +2457,8 @@ lexer_scan_identifier (parser_context_t *context_p, /**< context */
|
||||
|| context_p->token.type == LEXER_LEFT_SQUARE
|
||||
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
|
||||
|| context_p->token.type == LEXER_RIGHT_BRACE
|
||||
|| context_p->token.type == LEXER_SEMICOLON)
|
||||
|| context_p->token.type == LEXER_SEMICOLON
|
||||
|| ((ident_opts & LEXER_SCAN_CLASS_LEFT_PAREN) && context_p->token.type == LEXER_LEFT_PAREN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -265,6 +265,7 @@ typedef enum
|
||||
LEXER_SCAN_IDENT_NO_KEYW = (1u << 2), /**< don't scan keywords (e.g. get/set) */
|
||||
#if ENABLED (JERRY_ES2015_CLASS)
|
||||
LEXER_SCAN_CLASS_PROPERTY = (1u << 3), /**< scan valid class property names */
|
||||
LEXER_SCAN_CLASS_LEFT_PAREN = (1u << 4), /**< also parse left parenthesis */
|
||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
||||
} lexer_scan_ident_opts_t;
|
||||
|
||||
|
||||
@@ -1390,13 +1390,19 @@ scanner_scan_all (parser_context_t *context_p) /**< context */
|
||||
lexer_scan_identifier (context_p, LEXER_SCAN_CLASS_PROPERTY);
|
||||
}
|
||||
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_FUNCTION);
|
||||
scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS;
|
||||
|
||||
if (lexer_compare_literal_to_identifier (context_p, "get", 3)
|
||||
|| lexer_compare_literal_to_identifier (context_p, "set", 3))
|
||||
{
|
||||
lexer_scan_identifier (context_p, LEXER_SCAN_CLASS_PROPERTY);
|
||||
}
|
||||
lexer_scan_identifier (context_p, LEXER_SCAN_CLASS_PROPERTY | LEXER_SCAN_CLASS_LEFT_PAREN);
|
||||
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_FUNCTION);
|
||||
if (context_p->token.type == LEXER_LEFT_PAREN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
|
||||
if (context_p->token.type == LEXER_LEFT_SQUARE)
|
||||
@@ -1408,7 +1414,6 @@ scanner_scan_all (parser_context_t *context_p) /**< context */
|
||||
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
|
||||
|
||||
lexer_next_token (context_p);
|
||||
scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS;
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
||||
|
||||
@@ -125,11 +125,21 @@ class E {
|
||||
set e(e) {
|
||||
this._e = e;
|
||||
}
|
||||
|
||||
get () {
|
||||
return 11;
|
||||
}
|
||||
|
||||
set () {
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
var e = new E (5);
|
||||
assert (e.e === 5);
|
||||
e.e = 10;
|
||||
assert (e.e === 10);
|
||||
assert (e.get() === 11);
|
||||
assert (e.set() === 12);
|
||||
assert (e.constructor === E);
|
||||
|
||||
var F = class ClassF {
|
||||
@@ -193,6 +203,14 @@ var G = class {
|
||||
return this._a;
|
||||
}
|
||||
|
||||
static get() {
|
||||
return 11;
|
||||
}
|
||||
|
||||
static set() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
static set constructor(a) {
|
||||
this._a = a;
|
||||
}
|
||||
@@ -214,6 +232,8 @@ assert (G.a === 10);
|
||||
assert (G.g1() === 10);
|
||||
G["1"] = 20;
|
||||
assert (G["1"] === 20);
|
||||
assert (G.get() == 11);
|
||||
assert (G.set() == 12);
|
||||
G.constructor = 30;
|
||||
assert (G.constructor === 30);
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
class $ {
|
||||
set ( ) {
|
||||
switch ( $ ) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
class $ {
|
||||
set ( ) {}
|
||||
}
|
||||
for ( ; 10 ; i )
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
class $ {
|
||||
set ( ) {
|
||||
while ( done )
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user