From 3766efba1e0fcc5ea90de8aaf9dda30ad4aa6d3c Mon Sep 17 00:00:00 2001 From: Sanggyu Lee Date: Fri, 30 Jun 2017 16:32:40 +0900 Subject: [PATCH] Throw SyntaxError for identifier with supplementary character Fix assertion failure issue #1871 on github. Don't allow supplementary character as identifier start or part. JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee sg5.lee@samsung.com --- jerry-core/lit/lit-char-helpers.c | 16 ++++++++++++++++ tests/jerry/fail/regression-test-issue-1871-1.js | 15 +++++++++++++++ tests/jerry/fail/regression-test-issue-1871-2.js | 15 +++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/jerry/fail/regression-test-issue-1871-1.js create mode 100644 tests/jerry/fail/regression-test-issue-1871-2.js diff --git a/jerry-core/lit/lit-char-helpers.c b/jerry-core/lit/lit-char-helpers.c index 11d13df87b..108992343c 100644 --- a/jerry-core/lit/lit-char-helpers.c +++ b/jerry-core/lit/lit-char-helpers.c @@ -226,6 +226,14 @@ lit_char_is_identifier_start (const uint8_t *src_p) /**< pointer to a vaild UTF8 return lit_char_is_identifier_start_character (*src_p); } + /* ECMAScript 2015 specification allows some code points in supplementary plane. + * However, we don't permit characters in supplementary characters as start of identifier. + */ + if ((*src_p & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER) + { + return false; + } + return lit_char_is_identifier_start_character (lit_utf8_peek_next (src_p)); } /* lit_char_is_identifier_start */ @@ -262,6 +270,14 @@ lit_char_is_identifier_part (const uint8_t *src_p) /**< pointer to a vaild UTF8 return lit_char_is_identifier_part_character (*src_p); } + /* ECMAScript 2015 specification allows some code points in supplementary plane. + * However, we don't permit characters in supplementary characters as part of identifier. + */ + if ((*src_p & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER) + { + return false; + } + return lit_char_is_identifier_part_character (lit_utf8_peek_next (src_p)); } /* lit_char_is_identifier_part */ diff --git a/tests/jerry/fail/regression-test-issue-1871-1.js b/tests/jerry/fail/regression-test-issue-1871-1.js new file mode 100644 index 0000000000..654d118137 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-1871-1.js @@ -0,0 +1,15 @@ +// 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. + +š„ž diff --git a/tests/jerry/fail/regression-test-issue-1871-2.js b/tests/jerry/fail/regression-test-issue-1871-2.js new file mode 100644 index 0000000000..dce6286df7 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-1871-2.js @@ -0,0 +1,15 @@ +// 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. + +gš„ž