mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Optimize number literals.
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
parent
e763280761
commit
d132c37f0a
@ -1520,19 +1520,22 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */
|
||||
int push_number_allowed, /**< push number support is allowed */
|
||||
int is_negative_number) /**< sign is negative */
|
||||
{
|
||||
parser_list_iterator_t literal_iterator;
|
||||
lexer_literal_t *literal_p;
|
||||
lit_cpointer_t lit_cp;
|
||||
ecma_number_t num;
|
||||
uint16_t literal_count = context_p->literal_count;
|
||||
uint32_t literal_index = 0;
|
||||
uint16_t length = context_p->token.lit_location.length;
|
||||
|
||||
if (context_p->token.extra_value != LEXER_NUMBER_OCTAL)
|
||||
{
|
||||
num = ecma_utf8_string_to_number (context_p->token.lit_location.char_p,
|
||||
context_p->token.lit_location.length);
|
||||
length);
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint8_t *src_p = context_p->token.lit_location.char_p;
|
||||
const uint8_t *src_end_p = src_p + context_p->token.lit_location.length - 1;
|
||||
const uint8_t *src_end_p = src_p + length - 1;
|
||||
|
||||
num = 0;
|
||||
do
|
||||
@ -1563,7 +1566,25 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */
|
||||
num = -num;
|
||||
}
|
||||
|
||||
if (literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
lit_cp = rcs_cpointer_compress (lit_find_or_create_literal_from_num (num));
|
||||
parser_list_iterator_init (&context_p->literal_pool, &literal_iterator);
|
||||
|
||||
while ((literal_p = (lexer_literal_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
|
||||
{
|
||||
if (literal_p->type == LEXER_NUMBER_LITERAL
|
||||
&& literal_p->u.value.value.base_cp == lit_cp.value.base_cp)
|
||||
{
|
||||
context_p->lit_object.literal_p = literal_p;
|
||||
context_p->lit_object.index = (uint16_t) literal_index;
|
||||
return PARSER_FALSE;
|
||||
}
|
||||
|
||||
literal_index++;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (literal_index == context_p->literal_count);
|
||||
|
||||
if (literal_index >= PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED);
|
||||
}
|
||||
@ -1575,11 +1596,11 @@ lexer_construct_number_object (parser_context_t *context_p, /**< context */
|
||||
|
||||
context_p->literal_count++;
|
||||
|
||||
literal_p->u.value = rcs_cpointer_compress (lit_find_or_create_literal_from_num (num));
|
||||
literal_p->u.value = lit_cp;
|
||||
literal_p->type = LEXER_NUMBER_LITERAL;
|
||||
|
||||
context_p->lit_object.literal_p = literal_p;
|
||||
context_p->lit_object.index = literal_count;
|
||||
context_p->lit_object.index = (uint16_t) literal_index;
|
||||
context_p->lit_object.type = LEXER_LITERAL_OBJECT_ANY;
|
||||
|
||||
return PARSER_FALSE;
|
||||
|
||||
@ -520,7 +520,7 @@ parser_generate_initializers (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
#ifdef PARSER_DUMP_BYTE_CODE
|
||||
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string (literal_p->u.char_p,
|
||||
literal_p->prop.length);
|
||||
literal_p->prop.length);
|
||||
literal_pool_p[literal_p->prop.index] = rcs_cpointer_compress (lit);
|
||||
|
||||
if (!context_p->is_show_opcodes
|
||||
|
||||
25
tests/jerry/object-literal-3.js
Normal file
25
tests/jerry/object-literal-3.js
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2016 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2016 University of Szeged.
|
||||
//
|
||||
// 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.
|
||||
|
||||
try
|
||||
{
|
||||
// This should be failed in ECMA-262 v5.1
|
||||
eval("({ get 1() {}, 1:1 })");
|
||||
assert (false);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
assert (e instanceof SyntaxError);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user