Remove the restriction that the external magic strings must be ascii strings. (#1469)

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
Robert Sipka 2016-12-03 10:20:46 +01:00 committed by GitHub
parent 23cf7fd177
commit 4c1fc7d789
2 changed files with 36 additions and 11 deletions

View File

@ -554,7 +554,7 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
utf8_string1_p = lit_get_magic_string_ex_utf8 (string1_p->u.magic_string_id);
utf8_string1_size = lit_get_magic_string_ex_size (string1_p->u.magic_string_id);
utf8_string1_length = utf8_string1_size;
utf8_string1_length = lit_utf8_string_length (utf8_string1_p, utf8_string1_size);
string1_rehash_needed = true;
break;
}
@ -600,7 +600,7 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
utf8_string2_p = lit_get_magic_string_ex_utf8 (string2_p->u.magic_string_id);
utf8_string2_size = lit_get_magic_string_ex_size (string2_p->u.magic_string_id);
utf8_string2_length = utf8_string2_size;
utf8_string2_length = lit_utf8_string_length (utf8_string2_p, utf8_string2_size);
break;
}
}
@ -1035,12 +1035,10 @@ ecma_string_raw_chars (const ecma_string_t *string_p, /**< ecma-string */
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX);
size = lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id);
length = size;
length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id),
lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id));
result_p = lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id);
/* All extended magic strings must be ascii strings. */
JERRY_ASSERT (ECMA_STRING_IS_ASCII (result_p, size));
break;
}
}
@ -1472,9 +1470,8 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
{
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX);
JERRY_ASSERT (ECMA_STRING_IS_ASCII (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id),
lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id)));
return lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id);
return lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id),
lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id));
}
}
} /* ecma_string_get_length */

View File

@ -151,8 +151,8 @@ handler_construct (const jerry_value_t func_obj_val, /**< function object */
*/
#define JERRY_MAGIC_STRING_ITEMS \
JERRY_MAGIC_STRING_DEF (GLOBAL, global) \
JERRY_MAGIC_STRING_DEF (CONSOLE, console)
JERRY_MAGIC_STRING_DEF (CONSOLE, console) \
JERRY_MAGIC_STRING_DEF (GREEK_ZERO_SIGN, \xed\xa0\x80\xed\xb6\x8a)
#define JERRY_MAGIC_STRING_DEF(NAME, STRING) \
static const char jerry_magic_string_ex_ ## NAME[] = # STRING;
@ -832,6 +832,34 @@ main (void)
jerry_release_value (res);
jerry_release_value (parsed_code_val);
/* call jerry_create_string functions which will returns with the registered external magic strings */
args[0] = jerry_create_string ((jerry_char_t *) "console");
args[1] = jerry_create_string ((jerry_char_t *) "\xed\xa0\x80\xed\xb6\x8a"); /**< greek zero sign */
cesu8_length = jerry_get_string_length (args[0]);
cesu8_sz = jerry_get_string_size (args[0]);
char string_console[cesu8_sz];
jerry_string_to_char_buffer (args[0], (jerry_char_t *) string_console, cesu8_sz);
TEST_ASSERT (!strncmp (string_console, "console", cesu8_sz));
TEST_ASSERT (cesu8_length == 7);
TEST_ASSERT (cesu8_length == cesu8_sz);
jerry_release_value (args[0]);
cesu8_length = jerry_get_string_length (args[1]);
cesu8_sz = jerry_get_string_size (args[1]);
char string_greek_zero_sign[cesu8_sz];
jerry_string_to_char_buffer (args[1], (jerry_char_t *) string_greek_zero_sign, cesu8_sz);
TEST_ASSERT (!strncmp (string_greek_zero_sign, "\xed\xa0\x80\xed\xb6\x8a", cesu8_sz));
TEST_ASSERT (cesu8_length == 2);
TEST_ASSERT (cesu8_sz == 6);
jerry_release_value (args[1]);
jerry_cleanup ();
/* Dump / execute snapshot */