mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Fix allocation problems when using import and export (#2919)
Construct ecma_string only when there is no parser error using lit_object's index in parser_module_parse_export_caluse and parser_module_parse_import_clause Fixes #2908 Co-authored-by: Tibor Dusnoki tdusnoki@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
parent
b707c3f8da
commit
7b65167e81
@ -327,11 +327,8 @@ parser_module_parse_export_clause (parser_context_t *context_p) /**< parser cont
|
||||
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL);
|
||||
|
||||
local_name_p = ecma_new_ecma_string_from_utf8 (context_p->lit_object.literal_p->u.char_p,
|
||||
context_p->lit_object.literal_p->prop.length);
|
||||
|
||||
ecma_ref_ecma_string (local_name_p);
|
||||
export_name_p = local_name_p;
|
||||
uint16_t local_name_index = context_p->lit_object.index;
|
||||
uint16_t export_name_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
if (context_p->token.type == LEXER_LITERAL
|
||||
@ -342,20 +339,30 @@ parser_module_parse_export_clause (parser_context_t *context_p) /**< parser cont
|
||||
if (context_p->token.type != LEXER_LITERAL
|
||||
|| context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
|
||||
{
|
||||
ecma_deref_ecma_string (local_name_p);
|
||||
ecma_deref_ecma_string (export_name_p);
|
||||
parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED);
|
||||
}
|
||||
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL);
|
||||
|
||||
ecma_deref_ecma_string (local_name_p);
|
||||
export_name_p = ecma_new_ecma_string_from_utf8 (context_p->lit_object.literal_p->u.char_p,
|
||||
context_p->lit_object.literal_p->prop.length);
|
||||
export_name_index = context_p->lit_object.index;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
}
|
||||
|
||||
lexer_literal_t *literal_p = PARSER_GET_LITERAL (local_name_index);
|
||||
local_name_p = ecma_new_ecma_string_from_utf8 (literal_p->u.char_p, literal_p->prop.length);
|
||||
|
||||
if (export_name_index != PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
{
|
||||
lexer_literal_t *as_literal_p = PARSER_GET_LITERAL (export_name_index);
|
||||
export_name_p = ecma_new_ecma_string_from_utf8 (as_literal_p->u.char_p, as_literal_p->prop.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
export_name_p = local_name_p;
|
||||
ecma_ref_ecma_string (local_name_p);
|
||||
}
|
||||
|
||||
if (parser_module_check_duplicate_export (context_p, export_name_p))
|
||||
{
|
||||
ecma_deref_ecma_string (local_name_p);
|
||||
@ -413,10 +420,8 @@ parser_module_parse_import_clause (parser_context_t *context_p) /**< parser cont
|
||||
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL);
|
||||
|
||||
local_name_p = ecma_new_ecma_string_from_utf8 (context_p->lit_object.literal_p->u.char_p,
|
||||
context_p->lit_object.literal_p->prop.length);
|
||||
ecma_ref_ecma_string (local_name_p);
|
||||
import_name_p = local_name_p;
|
||||
uint16_t import_name_index = context_p->lit_object.index;
|
||||
uint16_t local_name_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
if (context_p->token.type == LEXER_LITERAL
|
||||
@ -427,19 +432,30 @@ parser_module_parse_import_clause (parser_context_t *context_p) /**< parser cont
|
||||
if (context_p->token.type != LEXER_LITERAL
|
||||
|| context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
|
||||
{
|
||||
ecma_deref_ecma_string (local_name_p);
|
||||
ecma_deref_ecma_string (import_name_p);
|
||||
parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED);
|
||||
}
|
||||
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_IDENT_LITERAL);
|
||||
|
||||
ecma_deref_ecma_string (local_name_p);
|
||||
local_name_p = ecma_new_ecma_string_from_utf8 (context_p->lit_object.literal_p->u.char_p,
|
||||
context_p->lit_object.literal_p->prop.length);
|
||||
local_name_index = context_p->lit_object.index;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
}
|
||||
|
||||
lexer_literal_t *literal_p = PARSER_GET_LITERAL (import_name_index);
|
||||
import_name_p = ecma_new_ecma_string_from_utf8 (literal_p->u.char_p, literal_p->prop.length);
|
||||
|
||||
if (local_name_index != PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
{
|
||||
lexer_literal_t *as_literal_p = PARSER_GET_LITERAL (local_name_index);
|
||||
local_name_p = ecma_new_ecma_string_from_utf8 (as_literal_p->u.char_p, as_literal_p->prop.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
local_name_p = import_name_p;
|
||||
ecma_ref_ecma_string (local_name_p);
|
||||
}
|
||||
|
||||
if (parser_module_check_duplicate_import (context_p, local_name_p))
|
||||
{
|
||||
ecma_deref_ecma_string (local_name_p);
|
||||
|
||||
16
tests/jerry/fail/regression-test-issue-2908-1.js
Normal file
16
tests/jerry/fail/regression-test-issue-2908-1.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
import{p0hc"=
|
||||
16
tests/jerry/fail/regression-test-issue-2908-2.js
Normal file
16
tests/jerry/fail/regression-test-issue-2908-2.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
import{a as p0hc"=
|
||||
16
tests/jerry/fail/regression-test-issue-2908-3.js
Normal file
16
tests/jerry/fail/regression-test-issue-2908-3.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
export{p0hc"=
|
||||
16
tests/jerry/fail/regression-test-issue-2908-4.js
Normal file
16
tests/jerry/fail/regression-test-issue-2908-4.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
export{a as p0hc"=
|
||||
Loading…
x
Reference in New Issue
Block a user