Add core unicode functionality.

Add utf-8 processing routines.
Change ecma_char_t from char/uint16_t to uint16_t.
Apply all utf-8 processing routines.
Change char to jerry_api_char in API functions' declarations.

JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
Andrey Shitov
2015-06-29 19:17:17 +03:00
parent c4b0cd2196
commit fd9ff8e3bd
56 changed files with 2468 additions and 1480 deletions
+1 -1
View File
@@ -715,7 +715,7 @@ typedef struct
mem_cpointer_t next_chunk_cp;
/** Characters */
uint8_t data[ sizeof (uint64_t) - sizeof (mem_cpointer_t) ];
lit_utf8_byte_t data[ sizeof (uint64_t) - sizeof (mem_cpointer_t) ];
} ecma_collection_chunk_t;
/**
@@ -23,6 +23,7 @@
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "jrt-libc-includes.h"
#include "lit-magic-strings.h"
/*
* \addtogroup ecmahelpersbigintegers Helpers for operations intermediate 128-bit integers
@@ -325,7 +326,7 @@
*/
/**
* ECMA-defined conversion of string (zero-terminated) to Number.
* ECMA-defined conversion of string to Number.
*
* See also:
* ECMA-262 v5, 9.3.1
@@ -333,28 +334,28 @@
* @return ecma-number
*/
ecma_number_t
ecma_zt_string_to_number (const ecma_char_t *str_p) /**< zero-terminated string */
ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, /**< utf-8 string */
lit_utf8_size_t str_size) /**< string size */
{
TODO (Check license issues);
const ecma_char_t dec_digits_range[10] = { '0', '9' };
const ecma_char_t hex_lower_digits_range[10] = { 'a', 'f' };
const ecma_char_t hex_upper_digits_range[10] = { 'A', 'F' };
const ecma_char_t hex_x_chars[2] = { 'x', 'X' };
const ecma_char_t white_space[2] = { ' ', '\n' };
const ecma_char_t e_chars[2] = { 'e', 'E' };
const ecma_char_t plus_char = '+';
const ecma_char_t minus_char = '-';
const ecma_char_t dot_char = '.';
const lit_utf8_byte_t dec_digits_range[10] = { '0', '9' };
const lit_utf8_byte_t hex_lower_digits_range[10] = { 'a', 'f' };
const lit_utf8_byte_t hex_upper_digits_range[10] = { 'A', 'F' };
const lit_utf8_byte_t hex_x_chars[2] = { 'x', 'X' };
const lit_utf8_byte_t white_space[2] = { ' ', '\n' };
const lit_utf8_byte_t e_chars[2] = { 'e', 'E' };
const lit_utf8_byte_t plus_char = '+';
const lit_utf8_byte_t minus_char = '-';
const lit_utf8_byte_t dot_char = '.';
const ecma_char_t *begin_p = str_p;
const ecma_char_t *end_p = begin_p;
while (*end_p != ECMA_CHAR_NULL)
if (str_size == 0)
{
end_p++;
return ECMA_NUMBER_ZERO;
}
end_p--;
const lit_utf8_byte_t *begin_p = str_p;
const lit_utf8_byte_t *end_p = begin_p + str_size - 1;
while (begin_p <= end_p
&& (*begin_p == white_space[0]
@@ -387,7 +388,7 @@ ecma_zt_string_to_number (const ecma_char_t *str_p) /**< zero-terminated string
ecma_number_t num = 0;
for (const ecma_char_t* iter_p = begin_p;
for (const lit_utf8_byte_t * iter_p = begin_p;
iter_p <= end_p;
iter_p++)
{
@@ -438,9 +439,9 @@ ecma_zt_string_to_number (const ecma_char_t *str_p) /**< zero-terminated string
}
/* Checking if significant part of parse string is equal to "Infinity" */
const ecma_char_t *infinity_zt_str_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_INFINITY_UL);
const lit_utf8_byte_t *infinity_zt_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
for (const ecma_char_t *iter_p = begin_p, *iter_infinity_p = infinity_zt_str_p;
for (const lit_utf8_byte_t *iter_p = begin_p, *iter_infinity_p = infinity_zt_str_p;
;
iter_infinity_p++, iter_p++)
{
@@ -750,7 +751,7 @@ ecma_zt_string_to_number (const ecma_char_t *str_p) /**< zero-terminated string
return num;
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32 */
} /* ecma_zt_string_to_number */
} /* ecma_utf8_string_to_number */
/**
* ECMA-defined conversion of UInt32 to String (zero-terminated).
@@ -761,16 +762,14 @@ ecma_zt_string_to_number (const ecma_char_t *str_p) /**< zero-terminated string
* @return number of bytes copied to buffer
*/
ssize_t
ecma_uint32_to_string (uint32_t value, /**< value to convert */
ecma_char_t *out_buffer_p, /**< buffer for zero-terminated string */
ssize_t buffer_size) /**< size of buffer */
ecma_uint32_to_utf8_string (uint32_t value, /**< value to convert */
lit_utf8_byte_t *out_buffer_p, /**< buffer for string */
ssize_t buffer_size) /**< size of buffer */
{
const ecma_char_t digits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
const lit_utf8_byte_t digits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
ecma_char_t *p = (ecma_char_t*) ((uint8_t*) out_buffer_p + buffer_size) - 1;
*p-- = ECMA_CHAR_NULL;
size_t bytes_copied = sizeof (ecma_char_t);
lit_utf8_byte_t *p = out_buffer_p + buffer_size - 1;
size_t bytes_copied = 0;
do
{
@@ -779,7 +778,7 @@ ecma_uint32_to_string (uint32_t value, /**< value to convert */
*p-- = digits[value % 10];
value /= 10;
bytes_copied += sizeof (ecma_char_t);
bytes_copied ++;
}
while (value != 0);
@@ -789,12 +788,12 @@ ecma_uint32_to_string (uint32_t value, /**< value to convert */
if (likely (p != out_buffer_p))
{
ssize_t bytes_to_move = ((uint8_t*) out_buffer_p + buffer_size) - (uint8_t*) p;
ssize_t bytes_to_move = out_buffer_p + buffer_size - p;
memmove (out_buffer_p, p, (size_t) bytes_to_move);
}
return (ssize_t) bytes_copied;
} /* ecma_uint32_to_string */
} /* ecma_uint32_to_utf8_string */
/**
* ECMA-defined conversion of UInt32 value to Number value
@@ -1299,51 +1298,50 @@ ecma_number_to_decimal (ecma_number_t num, /**< ecma-number */
* ECMA-262 v5, 9.8.1
*
*
* @return length of zt-string
* @return size of utf-8 string
*/
ecma_length_t
ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
ecma_char_t *buffer_p, /**< buffer for zt-string */
ssize_t buffer_size) /**< size of buffer */
lit_utf8_size_t
ecma_number_to_utf8_string (ecma_number_t num, /**< ecma-number */
lit_utf8_byte_t *buffer_p, /**< buffer for utf-8 string */
ssize_t buffer_size) /**< size of buffer */
{
const ecma_char_t digits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
const ecma_char_t e_chars[2] = { 'e', 'E' };
const ecma_char_t plus_char = '+';
const ecma_char_t minus_char = '-';
const ecma_char_t dot_char = '.';
const lit_utf8_byte_t digits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
const lit_utf8_byte_t e_chars[2] = { 'e', 'E' };
const lit_utf8_byte_t plus_char = '+';
const lit_utf8_byte_t minus_char = '-';
const lit_utf8_byte_t dot_char = '.';
lit_utf8_size_t size;
if (ecma_number_is_nan (num))
{
// 1.
ecma_copy_zt_string_to_buffer (lit_get_magic_string_zt (LIT_MAGIC_STRING_NAN),
buffer_p,
buffer_size);
lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_NAN, buffer_p, buffer_size);
size = lit_get_magic_string_size (LIT_MAGIC_STRING_NAN);
}
else
{
ecma_char_t *dst_p = buffer_p;
lit_utf8_byte_t *dst_p = buffer_p;
if (ecma_number_is_zero (num))
{
// 2.
*dst_p++ = digits[0];
*dst_p++ = ECMA_CHAR_NULL;
JERRY_ASSERT ((uint8_t*)dst_p - (uint8_t*)buffer_p <= (ssize_t) buffer_size);
JERRY_ASSERT (dst_p - buffer_p <= (ssize_t) buffer_size);
size = (lit_utf8_size_t) (dst_p - buffer_p);
}
else if (ecma_number_is_negative (num))
{
// 3.
*dst_p++ = minus_char;
ssize_t new_buffer_size = (buffer_size - ((uint8_t*)dst_p - (uint8_t*)buffer_p));
ecma_number_to_zt_string (ecma_number_negate (num), dst_p, new_buffer_size);
ssize_t new_buffer_size = (buffer_size - (dst_p - buffer_p));
size = 1 + ecma_number_to_utf8_string (ecma_number_negate (num), dst_p, new_buffer_size);
}
else if (ecma_number_is_infinity (num))
{
// 4.
ecma_copy_zt_string_to_buffer (lit_get_magic_string_zt (LIT_MAGIC_STRING_INFINITY_UL),
buffer_p,
buffer_size);
dst_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_INFINITY_UL, buffer_p, buffer_size);
size = (lit_utf8_size_t) (dst_p - buffer_p);
}
else
{
@@ -1355,7 +1353,7 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
uint32_t num_uint32 = ecma_number_to_uint32 (num);
if (ecma_uint32_to_number (num_uint32) == num)
{
ecma_uint32_to_string (num_uint32, dst_p, buffer_size);
size = (lit_utf8_size_t) ecma_uint32_to_utf8_string (num_uint32, dst_p, buffer_size);
}
else
{
@@ -1372,9 +1370,9 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
if (k <= n && n <= 21)
{
dst_p += n;
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * ((dst_p - buffer_p) + 1) <= buffer_size);
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p) <= buffer_size);
*dst_p = ECMA_CHAR_NULL;
size = (lit_utf8_size_t) (dst_p - buffer_p);
for (int32_t i = 0; i < n - k; i++)
{
@@ -1391,9 +1389,9 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
{
// 7.
dst_p += k + 1;
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * ((dst_p - buffer_p) + 1) <= buffer_size);
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p) <= buffer_size);
*dst_p = ECMA_CHAR_NULL;
size = (lit_utf8_size_t) (dst_p - buffer_p);
for (int32_t i = 0; i < k - n; i++)
{
@@ -1413,9 +1411,9 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
{
// 8.
dst_p += k - n + 1 + 1;
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * ((dst_p - buffer_p) + 1) <= buffer_size);
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p) <= buffer_size);
*dst_p = ECMA_CHAR_NULL;
size = (lit_utf8_size_t) (dst_p - buffer_p);
for (int32_t i = 0; i < k; i++)
{
@@ -1436,7 +1434,9 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
if (k == 1)
{
// 9.
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) <= buffer_size);
JERRY_ASSERT (1 <= buffer_size);
size = 1;
*dst_p++ = digits[s % 10];
s /= 10;
@@ -1445,7 +1445,7 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
{
// 10.
dst_p += k + 1;
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * (dst_p - buffer_p) <= buffer_size);
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p) <= buffer_size);
for (int32_t i = 0; i < k - 1; i++)
{
@@ -1461,14 +1461,14 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
}
// 9., 10.
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * (dst_p - buffer_p + 2) <= buffer_size);
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p + 2) <= buffer_size);
*dst_p++ = e_chars[0];
*dst_p++ = (n >= 1) ? plus_char : minus_char;
int32_t t = (n >= 1) ? (n - 1) : -(n - 1);
if (t == 0)
{
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * (dst_p - buffer_p + 1) <= buffer_size);
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p) <= buffer_size);
*dst_p++ = digits[0];
}
else
@@ -1484,7 +1484,7 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
while (t_mod != 0)
{
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * (dst_p - buffer_p + 1) <= buffer_size);
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p + 1) <= buffer_size);
*dst_p++ = digits[t / t_mod];
t -= (t / t_mod) * t_mod;
@@ -1492,8 +1492,8 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
}
}
JERRY_ASSERT ((ssize_t) sizeof (ecma_char_t) * (dst_p - buffer_p + 1) <= buffer_size);
*dst_p++ = ECMA_CHAR_NULL;
JERRY_ASSERT ((ssize_t) (dst_p - buffer_p) <= buffer_size);
size = (lit_utf8_size_t) (dst_p - buffer_p);
}
JERRY_ASSERT (s == 0);
@@ -1501,10 +1501,8 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
}
}
ecma_length_t length = ecma_zt_string_length (buffer_p);
return length;
} /* ecma_number_to_zt_string */
return size;
} /* ecma_number_to_utf8_string */
/**
* @}
File diff suppressed because it is too large Load Diff
@@ -194,6 +194,7 @@ ecma_collection_iterator_next (ecma_collection_iterator_t *iterator_p) /**< cont
}
else
{
if (iterator_p->current_index + 1 == iterator_p->header_p->unit_number)
{
return false;
+15 -18
View File
@@ -25,6 +25,7 @@
#define JERRY_ECMA_HELPERS_H
#include "ecma-globals.h"
#include "lit-strings.h"
#include "mem-allocator.h"
#include "opcodes.h"
@@ -107,9 +108,9 @@ extern bool ecma_is_completion_value_normal_true (ecma_completion_value_t value)
extern bool ecma_is_completion_value_normal_false (ecma_completion_value_t value);
extern bool ecma_is_completion_value_empty (ecma_completion_value_t value);
/* ecma-helpers-string.cpp */
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p, const ecma_length_t length);
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p);
/* ecma-helpers-string.c */
extern ecma_string_t* ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *, lit_utf8_size_t);
extern ecma_string_t* ecma_new_ecma_string_from_code_unit (ecma_char_t);
extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number);
extern ecma_string_t* ecma_new_ecma_string_from_number (ecma_number_t number);
extern void ecma_new_ecma_string_on_stack_from_lit_cp (ecma_string_t *string_p,
@@ -124,9 +125,9 @@ extern ecma_string_t* ecma_copy_or_ref_ecma_string (ecma_string_t *string_desc_p
extern void ecma_deref_ecma_string (ecma_string_t *string_p);
extern void ecma_check_that_ecma_string_need_not_be_freed (const ecma_string_t *string_p);
extern ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
extern ssize_t ecma_string_to_zt_string (const ecma_string_t *string_desc_p,
ecma_char_t *buffer_p,
ssize_t buffer_size);
extern ssize_t ecma_string_to_utf8_string (const ecma_string_t *string_desc_p,
lit_utf8_byte_t *buffer_p,
ssize_t buffer_size);
extern bool ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *string1_p,
const ecma_string_t *string2_p);
extern bool ecma_compare_ecma_strings (const ecma_string_t *string1_p,
@@ -134,21 +135,17 @@ extern bool ecma_compare_ecma_strings (const ecma_string_t *string1_p,
extern bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p,
const ecma_string_t *string2_p);
extern ecma_length_t ecma_string_get_length (const ecma_string_t *string_p);
extern ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, uint32_t index);
extern bool ecma_compare_zt_strings (const ecma_char_t *string1_p, const ecma_char_t *string2_p);
extern bool ecma_compare_zt_strings_relational (const ecma_char_t *string1_p, const ecma_char_t *string2_p);
extern ecma_char_t*
ecma_copy_zt_string_to_buffer (const ecma_char_t *string_p,
ecma_char_t *buffer_p,
ssize_t buffer_size);
extern ecma_length_t ecma_zt_string_length (const ecma_char_t *string_p);
extern lit_utf8_size_t ecma_string_get_size (const ecma_string_t *string_p);
extern ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, ecma_length_t index);
extern lit_utf8_byte_t ecma_string_get_byte_at_pos (const ecma_string_t *string_p, lit_utf8_size_t index);
extern ecma_string_t* ecma_get_magic_string (lit_magic_string_id_t id);
extern ecma_string_t* ecma_get_magic_string_ex (lit_magic_string_ex_id_t id);
extern bool ecma_is_string_magic (const ecma_string_t *string_p, lit_magic_string_id_t *out_id_p);
extern bool ecma_is_ex_string_magic (const ecma_string_t *string_p, lit_magic_string_ex_id_t *out_id_p);
extern lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
extern lit_string_hash_t ecma_chars_buffer_calc_hash_last_chars (const ecma_char_t *chars, ecma_length_t length);
extern ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, ecma_length_t, ecma_length_t);
/* ecma-helpers-number.cpp */
extern const ecma_number_t ecma_number_relative_eps;
@@ -310,13 +307,13 @@ extern void
ecma_free_external_pointer_in_property (ecma_property_t *prop_p);
/* ecma-helpers-conversion.cpp */
extern ecma_number_t ecma_zt_string_to_number (const ecma_char_t *str_p);
extern ssize_t ecma_uint32_to_string (uint32_t value, ecma_char_t *out_buffer_p, ssize_t buffer_size);
extern ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size);
extern ssize_t ecma_uint32_to_utf8_string (uint32_t value, lit_utf8_byte_t *out_buffer_p, ssize_t buffer_size);
extern uint32_t ecma_number_to_uint32 (ecma_number_t value);
extern int32_t ecma_number_to_int32 (ecma_number_t value);
extern ecma_number_t ecma_int32_to_number (int32_t value);
extern ecma_number_t ecma_uint32_to_number (uint32_t value);
extern ecma_length_t ecma_number_to_zt_string (ecma_number_t num, ecma_char_t *buffer_p, ssize_t buffer_size);
extern lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t, lit_utf8_byte_t *, ssize_t);
/* ecma-helpers-char.cpp */
extern bool ecma_char_is_new_line (ecma_char_t c);
+1 -1
View File
@@ -50,7 +50,7 @@ JERRY_STATIC_ASSERT (sizeof (ecma_lcache_hash_entry_t) == sizeof (uint64_t));
/**
* LCache hash value length, in bits
*/
#define ECMA_LCACHE_HASH_BITS (LIT_STRING_HASH_BITS)
#define ECMA_LCACHE_HASH_BITS (sizeof (lit_string_hash_t) * JERRY_BITSINBYTE)
/**
* Number of rows in LCache's hash table
@@ -24,6 +24,7 @@
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#include "lit-magic-strings.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
@@ -131,48 +132,43 @@ ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this
}
else
{
const ecma_char_t *colon_zt_magic_string_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_COLON_CHAR);
const ecma_char_t *space_zt_magic_string_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_SPACE_CHAR);
const lit_utf8_size_t size = (ecma_string_get_size (name_string_p) +
ecma_string_get_size (msg_string_p) +
lit_get_magic_string_size (LIT_MAGIC_STRING_COLON_CHAR) +
lit_get_magic_string_size (LIT_MAGIC_STRING_SPACE_CHAR));
const ecma_length_t len = (ecma_string_get_length (name_string_p) +
ecma_string_get_length (msg_string_p) +
ecma_zt_string_length (colon_zt_magic_string_p) +
ecma_zt_string_length (space_zt_magic_string_p));
const ssize_t buffer_size = (ssize_t) ((len + 1) * sizeof (ecma_char_t));
const ssize_t buffer_size = (ssize_t) size;
ssize_t buffer_size_left = buffer_size;
MEM_DEFINE_LOCAL_ARRAY (ret_str_buffer, buffer_size, ecma_char_t);
ecma_char_t *ret_str_buffer_p = ret_str_buffer;
MEM_DEFINE_LOCAL_ARRAY (ret_str_buffer, buffer_size, lit_utf8_byte_t);
lit_utf8_byte_t *ret_str_buffer_p = ret_str_buffer;
ssize_t bytes = ecma_string_to_zt_string (name_string_p, ret_str_buffer_p, buffer_size_left);
JERRY_ASSERT (bytes >= 1 && buffer_size_left - bytes >= 0);
ssize_t bytes = ecma_string_to_utf8_string (name_string_p, ret_str_buffer_p, buffer_size_left);
JERRY_ASSERT (bytes >= 0 && buffer_size_left - bytes >= 0);
buffer_size_left -= bytes - 1 /* null character */;
ret_str_buffer_p = (ecma_char_t*) ((uint8_t*) ret_str_buffer + (buffer_size - buffer_size_left));
buffer_size_left -= bytes;
ret_str_buffer_p = ret_str_buffer + buffer_size - buffer_size_left;
ret_str_buffer_p = ecma_copy_zt_string_to_buffer (colon_zt_magic_string_p,
ret_str_buffer_p,
buffer_size_left);
buffer_size_left = buffer_size - (ret_str_buffer_p - ret_str_buffer) * (ssize_t) sizeof (ecma_char_t);
ret_str_buffer_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_COLON_CHAR,
ret_str_buffer_p,
buffer_size_left);
buffer_size_left = buffer_size - (ret_str_buffer_p - ret_str_buffer);
JERRY_ASSERT (buffer_size_left >= 0);
ret_str_buffer_p = ecma_copy_zt_string_to_buffer (space_zt_magic_string_p,
ret_str_buffer_p,
buffer_size_left);
buffer_size_left = buffer_size - (ret_str_buffer_p - ret_str_buffer) * (ssize_t) sizeof (ecma_char_t);
ret_str_buffer_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_SPACE_CHAR,
ret_str_buffer_p,
buffer_size_left);
buffer_size_left = buffer_size - (ret_str_buffer_p - ret_str_buffer);
JERRY_ASSERT (buffer_size_left >= 0);
bytes = ecma_string_to_zt_string (msg_string_p, ret_str_buffer_p, buffer_size_left);
JERRY_ASSERT (bytes >= 1 && buffer_size_left - bytes >= 0);
bytes = ecma_string_to_utf8_string (msg_string_p, ret_str_buffer_p, buffer_size_left);
JERRY_ASSERT (bytes >= 0 && buffer_size_left - bytes >= 0);
buffer_size_left -= bytes - 1 /* null character */;
ret_str_buffer_p = (ecma_char_t*) ((uint8_t*) ret_str_buffer + (buffer_size - buffer_size_left));
buffer_size_left -= bytes;
JERRY_ASSERT (buffer_size_left >= 0);
JERRY_ASSERT (buffer_size_left >= (ssize_t) sizeof (ecma_char_t));
*ret_str_buffer_p = ECMA_CHAR_NULL;
ret_str_p = ecma_new_ecma_string (ret_str_buffer);
ret_str_p = ecma_new_ecma_string_from_utf8 (ret_str_buffer,
(jerry_api_size_t) (buffer_size - buffer_size_left));
MEM_FINALIZE_LOCAL_ARRAY (ret_str_buffer);
}
@@ -21,6 +21,7 @@
#include "ecma-lex-env.h"
#include "ecma-try-catch-macro.h"
#include "serializer.h"
#include "lit-magic-strings.h"
#include "parser.h"
#define ECMA_BUILTINS_INTERNAL
@@ -73,22 +74,22 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
/* Last string, if any, is the function's body, and the rest, if any - are the function's parameter names */
MEM_DEFINE_LOCAL_ARRAY (string_params_p,
arguments_list_len == 0 ? 1 : arguments_list_len,
ecma_string_t*);
ecma_string_t *);
uint32_t params_count;
size_t zt_strings_buffer_size;
size_t strings_buffer_size;
if (arguments_list_len == 0)
{
/* 3. */
string_params_p[0] = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING__EMPTY);
zt_strings_buffer_size = sizeof (ecma_char_t);
strings_buffer_size = lit_get_magic_string_size (LIT_MAGIC_STRING__EMPTY);
params_count = 1;
}
else
{
/* 4., 5., 6. */
zt_strings_buffer_size = 0;
strings_buffer_size = 0;
params_count = 0;
while (params_count < arguments_list_len
@@ -99,8 +100,7 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
ret_value);
string_params_p[params_count] = ecma_copy_or_ref_ecma_string (ecma_get_string_from_value (str_arg_value));
zt_strings_buffer_size += ((size_t) ecma_string_get_length (string_params_p[params_count]) +
sizeof (ecma_char_t));
strings_buffer_size += ecma_string_get_size (string_params_p[params_count]);
params_count++;
ECMA_FINALIZE (str_arg_value);
@@ -111,30 +111,35 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
{
JERRY_ASSERT (params_count >= 1);
MEM_DEFINE_LOCAL_ARRAY (zt_string_params_p,
MEM_DEFINE_LOCAL_ARRAY (utf8_string_params_p,
params_count,
ecma_char_t*);
MEM_DEFINE_LOCAL_ARRAY (zt_string_buffer_p,
zt_strings_buffer_size,
ecma_char_t);
lit_utf8_byte_t *);
MEM_DEFINE_LOCAL_ARRAY (utf8_string_params_size,
params_count,
size_t);
MEM_DEFINE_LOCAL_ARRAY (utf8_string_buffer_p,
strings_buffer_size,
lit_utf8_byte_t);
ssize_t zt_string_buffer_pos = 0;
ssize_t utf8_string_buffer_pos = 0;
for (uint32_t i = 0; i < params_count; i++)
{
ssize_t sz = ecma_string_to_zt_string (string_params_p[i],
&zt_string_buffer_p[zt_string_buffer_pos],
(ssize_t) zt_strings_buffer_size - zt_string_buffer_pos);
JERRY_ASSERT (sz > 0);
ssize_t sz = ecma_string_to_utf8_string (string_params_p[i],
&utf8_string_buffer_p[utf8_string_buffer_pos],
(ssize_t) strings_buffer_size - utf8_string_buffer_pos);
JERRY_ASSERT (sz >= 0);
zt_string_params_p[i] = zt_string_buffer_p + zt_string_buffer_pos;
utf8_string_params_p[i] = utf8_string_buffer_p + utf8_string_buffer_pos;
utf8_string_params_size[i] = (size_t) sz;
zt_string_buffer_pos += sz;
utf8_string_buffer_pos += sz;
}
const opcode_t* opcodes_p;
bool is_syntax_correct;
is_syntax_correct = parser_parse_new_function ((const char **) zt_string_params_p,
is_syntax_correct = parser_parse_new_function ((const jerry_api_char_t **) utf8_string_params_p,
utf8_string_params_size,
params_count,
&opcodes_p);
@@ -180,8 +185,9 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (func_obj_p));
}
MEM_FINALIZE_LOCAL_ARRAY (zt_string_buffer_p);
MEM_FINALIZE_LOCAL_ARRAY (zt_string_params_p);
MEM_FINALIZE_LOCAL_ARRAY (utf8_string_buffer_p);
MEM_FINALIZE_LOCAL_ARRAY (utf8_string_params_size);
MEM_FINALIZE_LOCAL_ARRAY (utf8_string_params_p);
}
for (uint32_t i = 0; i < params_count; i++)
@@ -24,6 +24,7 @@
#include "ecma-helpers.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#include "lit-magic-strings.h"
#include "vm.h"
#include "jrt-libc-includes.h"
@@ -108,22 +109,22 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value);
ecma_string_t *number_str_p = ecma_get_string_from_value (string_var);
ecma_length_t string_len = ecma_string_get_length (number_str_p);
ecma_length_t str_size = ecma_string_get_length (number_str_p);
MEM_DEFINE_LOCAL_ARRAY (zt_string_buff, string_len + 1, ecma_char_t);
MEM_DEFINE_LOCAL_ARRAY (utf8_string_buff, str_size + 1, lit_utf8_byte_t);
size_t string_buf_size = (size_t) (string_len + 1) * sizeof (ecma_char_t);
ssize_t bytes_copied = ecma_string_to_zt_string (number_str_p,
zt_string_buff,
(ssize_t) string_buf_size);
JERRY_ASSERT (bytes_copied > 0);
ssize_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
utf8_string_buff,
(ssize_t) str_size);
JERRY_ASSERT (bytes_copied >= 0);
utf8_string_buff[str_size] = LIT_BYTE_NULL;
/* 2. Remove leading whitespace. */
ecma_length_t start = string_len;
ecma_length_t end = string_len;
ecma_length_t start = str_size;
ecma_length_t end = str_size;
for (ecma_length_t i = 0; i < end; i++)
{
if (!(isspace (zt_string_buff[i])))
if (!(isspace (utf8_string_buff[i])))
{
start = i;
break;
@@ -134,13 +135,13 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
int sign = 1;
/* 4. */
if (zt_string_buff[start] == '-')
if (utf8_string_buff[start] == '-')
{
sign = -1;
}
/* 5. */
if (zt_string_buff[start] == '-' || zt_string_buff[start] == '+')
if (utf8_string_buff[start] == '-' || utf8_string_buff[start] == '+')
{
start++;
}
@@ -180,8 +181,8 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
if (strip_prefix)
{
if (end - start >= 2
&& zt_string_buff[start] == '0'
&& (zt_string_buff[start + 1] == 'x' || zt_string_buff[start + 1] == 'X'))
&& utf8_string_buff[start] == '0'
&& (utf8_string_buff[start + 1] == 'x' || utf8_string_buff[start + 1] == 'X'))
{
start += 2;
@@ -190,27 +191,27 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
}
/* 11. Check if characters are in [0, Radix - 1]. We also convert them to number values in the process. */
for (ecma_length_t i = start; i < end; i++)
for (lit_utf8_size_t i = start; i < end; i++)
{
if ((zt_string_buff[i]) >= 'a' && zt_string_buff[i] <= 'z')
if ((utf8_string_buff[i]) >= 'a' && utf8_string_buff[i] <= 'z')
{
zt_string_buff[i] = (ecma_char_t) (zt_string_buff[i] - 'a' + 10);
utf8_string_buff[i] = (lit_utf8_byte_t) (utf8_string_buff[i] - 'a' + 10);
}
else if (zt_string_buff[i] >= 'A' && zt_string_buff[i] <= 'Z')
else if (utf8_string_buff[i] >= 'A' && utf8_string_buff[i] <= 'Z')
{
zt_string_buff[i] = (ecma_char_t) (zt_string_buff[i] - 'A' + 10);
utf8_string_buff[i] = (lit_utf8_byte_t) (utf8_string_buff[i] - 'A' + 10);
}
else if (isdigit (zt_string_buff[i]))
else if (isdigit (utf8_string_buff[i]))
{
zt_string_buff[i] = (ecma_char_t) (zt_string_buff[i] - '0');
utf8_string_buff[i] = (lit_utf8_byte_t) (utf8_string_buff[i] - '0');
}
else
{
/* Not a valid number char, set value to radix so it fails to pass as a valid character. */
zt_string_buff[i] = (ecma_char_t) rad;
utf8_string_buff[i] = (lit_utf8_byte_t) rad;
}
if (!(zt_string_buff[i] < rad))
if (!(utf8_string_buff[i] < rad))
{
end = i;
break;
@@ -235,7 +236,7 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
/* 13. and 14. */
for (int32_t i = (int32_t) end - 1; i >= (int32_t) start; i--)
{
*value_p += (ecma_number_t) zt_string_buff[i] * multiplier;
*value_p += (ecma_number_t) utf8_string_buff[i] * multiplier;
multiplier *= (ecma_number_t) rad;
}
@@ -249,7 +250,7 @@ ecma_builtin_global_object_parse_int (ecma_value_t this_arg __attr_unused___, /*
}
ECMA_OP_TO_NUMBER_FINALIZE (radix_num);
MEM_FINALIZE_LOCAL_ARRAY (zt_string_buff);
MEM_FINALIZE_LOCAL_ARRAY (utf8_string_buff);
ECMA_FINALIZE (string_var);
return ret_value;
} /* ecma_builtin_global_object_parse_int */
@@ -273,21 +274,21 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
ECMA_TRY_CATCH (string_var, ecma_op_to_string (string), ret_value);
ecma_string_t *number_str_p = ecma_get_string_from_value (string_var);
ecma_length_t string_len = ecma_string_get_length (number_str_p);
lit_utf8_size_t str_size = ecma_string_get_size (number_str_p);
MEM_DEFINE_LOCAL_ARRAY (zt_string_buff, string_len + 1, ecma_char_t);
MEM_DEFINE_LOCAL_ARRAY (utf8_string_buff, str_size + 1, lit_utf8_byte_t);
size_t string_buf_size = (size_t) (string_len + 1) * sizeof (ecma_char_t);
ssize_t bytes_copied = ecma_string_to_zt_string (number_str_p,
zt_string_buff,
(ssize_t) string_buf_size);
JERRY_ASSERT (bytes_copied > 0);
ssize_t bytes_copied = ecma_string_to_utf8_string (number_str_p,
utf8_string_buff,
(ssize_t) str_size);
JERRY_ASSERT (bytes_copied >= 0);
utf8_string_buff[str_size] = LIT_BYTE_NULL;
/* 2. Find first non whitespace char. */
ecma_length_t start = 0;
for (ecma_length_t i = 0; i < string_len; i++)
lit_utf8_size_t start = 0;
for (lit_utf8_size_t i = 0; i < str_size; i++)
{
if (!isspace (zt_string_buff[i]))
if (!isspace (utf8_string_buff[i]))
{
start = i;
break;
@@ -297,12 +298,12 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
bool sign = false;
/* Check if sign is present. */
if (zt_string_buff[start] == '-')
if (utf8_string_buff[start] == '-')
{
sign = true;
start++;
}
else if (zt_string_buff[start] == '+')
else if (utf8_string_buff[start] == '+')
{
start++;
}
@@ -310,11 +311,11 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
ecma_number_t *ret_num_p = ecma_alloc_number ();
/* Check if string is equal to "Infinity". */
const ecma_char_t *infinity_zt_str_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_INFINITY_UL);
const lit_utf8_byte_t *infinity_utf8_str_p = lit_get_magic_string_utf8 (LIT_MAGIC_STRING_INFINITY_UL);
for (ecma_length_t i = 0; infinity_zt_str_p[i] == zt_string_buff[start + i]; i++)
for (lit_utf8_size_t i = 0; infinity_utf8_str_p[i] == utf8_string_buff[start + i]; i++)
{
if (infinity_zt_str_p[i + 1] == 0)
if (infinity_utf8_str_p[i + 1] == 0)
{
*ret_num_p = ecma_number_make_infinity (sign);
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
@@ -324,19 +325,19 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
if (ecma_is_completion_value_empty (ret_value))
{
ecma_length_t current = start;
ecma_length_t end = string_len;
lit_utf8_size_t current = start;
lit_utf8_size_t end = str_size;
bool has_whole_part = false;
bool has_fraction_part = false;
if (isdigit (zt_string_buff[current]))
if (isdigit (utf8_string_buff[current]))
{
has_whole_part = true;
/* Check digits of whole part. */
for (ecma_length_t i = current; i < string_len; i++, current++)
for (lit_utf8_size_t i = current; i < str_size; i++, current++)
{
if (!isdigit (zt_string_buff[current]))
if (!isdigit (utf8_string_buff[current]))
{
break;
}
@@ -346,18 +347,18 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
end = current;
/* Check decimal point. */
if (zt_string_buff[current] == '.')
if (utf8_string_buff[current] == '.')
{
current++;
if (isdigit (zt_string_buff[current]))
if (isdigit (utf8_string_buff[current]))
{
has_fraction_part = true;
/* Check digits of fractional part. */
for (ecma_length_t i = current; i < string_len; i++, current++)
for (lit_utf8_size_t i = current; i < str_size; i++, current++)
{
if (!isdigit (zt_string_buff[current]))
if (!isdigit (utf8_string_buff[current]))
{
break;
}
@@ -368,24 +369,24 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
}
/* Check exponent. */
if ((zt_string_buff[current] == 'e' || zt_string_buff[current] == 'E')
if ((utf8_string_buff[current] == 'e' || utf8_string_buff[current] == 'E')
&& (has_whole_part || has_fraction_part))
{
current++;
/* Check sign of exponent. */
if (zt_string_buff[current] == '-' || zt_string_buff[current] == '+')
if (utf8_string_buff[current] == '-' || utf8_string_buff[current] == '+')
{
current++;
}
if (isdigit (zt_string_buff[current]))
if (isdigit (utf8_string_buff[current]))
{
/* Check digits of exponent part. */
for (ecma_length_t i = current; i < string_len; i++, current++)
for (lit_utf8_size_t i = current; i < str_size; i++, current++)
{
if (!isdigit (zt_string_buff[current]))
if (!isdigit (utf8_string_buff[current]))
{
break;
}
@@ -402,14 +403,8 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
}
else
{
if (end < string_len)
{
/* 4. End of valid number, terminate the string. */
zt_string_buff[end] = '\0';
}
/* 5. */
*ret_num_p = ecma_zt_string_to_number (zt_string_buff + start);
*ret_num_p = ecma_utf8_string_to_number (utf8_string_buff + start, end - start);
if (sign)
{
@@ -420,8 +415,9 @@ ecma_builtin_global_object_parse_float (ecma_value_t this_arg __attr_unused___,
}
}
MEM_FINALIZE_LOCAL_ARRAY (zt_string_buff);
MEM_FINALIZE_LOCAL_ARRAY (utf8_string_buff);
ECMA_FINALIZE (string_var);
return ret_value;
} /* ecma_builtin_global_object_parse_float */
@@ -524,7 +520,7 @@ static uint8_t unescaped_uri_component_set[16] =
* It returns with ECMA_BUILTIN_HEX_TO_BYTE_ERROR if a parse error is occured.
*/
static uint32_t
ecma_builtin_global_object_hex_to_byte (ecma_char_t *source_p) /**< source string */
ecma_builtin_global_object_hex_to_byte (lit_utf8_byte_t *source_p) /**< source string */
{
uint32_t decoded_byte = 0;
@@ -536,7 +532,7 @@ ecma_builtin_global_object_hex_to_byte (ecma_char_t *source_p) /**< source strin
return ECMA_BUILTIN_HEX_TO_BYTE_ERROR;
}
for (int i = 0; i < 2; i++)
for (lit_utf8_size_t i = 0; i < 2; i++)
{
source_p++;
decoded_byte <<= 4;
@@ -581,19 +577,19 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
JERRY_ASSERT (ecma_is_value_string (string));
ecma_string_t *input_string_p = ecma_get_string_from_value (string);
uint32_t input_length = (uint32_t) ecma_string_get_length (input_string_p);
lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);
MEM_DEFINE_LOCAL_ARRAY (input_start_p,
input_length + 1,
ecma_char_t);
input_size,
lit_utf8_byte_t);
ecma_string_to_zt_string (input_string_p,
input_start_p,
(ssize_t) (input_length + 1) * (ssize_t) sizeof (ecma_char_t));
ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
ecma_char_t *input_char_p = input_start_p;
ecma_char_t *input_end_p = input_start_p + input_length;
uint32_t output_length = 1;
lit_utf8_byte_t *input_char_p = input_start_p;
lit_utf8_byte_t *input_end_p = input_start_p + input_size;
lit_utf8_size_t output_size = 0;
/*
* The URI decoding has two major phases: first we validate the input,
@@ -605,7 +601,7 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
/* Input validation. */
if (*input_char_p != '%')
{
output_length++;
output_size++;
input_char_p++;
continue;
}
@@ -628,11 +624,11 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
if (ecma_builtin_global_object_character_is_in (decoded_byte, reserved_uri_bitset)
&& !ecma_builtin_global_object_character_is_in (decoded_byte, unescaped_uri_component_set))
{
output_length += 3;
output_size += 3;
}
else
{
output_length++;
output_size++;
}
}
else if (decoded_byte < 0xc0 || decoded_byte >= 0xf8)
@@ -670,6 +666,8 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
character = decoded_byte & 0x07;
}
output_size += (count + 1);
do
{
decoded_byte = ecma_builtin_global_object_hex_to_byte (input_char_p);
@@ -701,19 +699,17 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
break;
}
output_length += (character <= 0xffff) ? 1 : 2;
}
}
if (ecma_is_completion_value_empty (ret_value))
{
MEM_DEFINE_LOCAL_ARRAY (output_start_p,
output_length,
ecma_char_t);
output_size,
lit_utf8_byte_t);
input_char_p = input_start_p;
ecma_char_t *output_char_p = output_start_p;
lit_utf8_byte_t *output_char_p = output_start_p;
while (input_char_p < input_end_p)
{
@@ -740,7 +736,7 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
}
else
{
*output_char_p = (ecma_char_t) decoded_byte;
*output_char_p = (lit_utf8_byte_t) decoded_byte;
output_char_p++;
}
}
@@ -778,26 +774,13 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
}
while (--count > 0);
if (character < 0x10000)
{
*output_char_p = (ecma_char_t) character;
output_char_p++;
}
else
{
character -= 0x10000;
*output_char_p = (ecma_char_t) (0xd800 | (character & 0x3ff));
output_char_p++;
*output_char_p = (ecma_char_t) (0xdc00 | (character >> 10));
output_char_p++;
}
output_char_p += lit_code_point_to_utf8 (character, output_char_p);
}
}
*output_char_p = '\0';
JERRY_ASSERT (output_start_p + output_length == output_char_p + 1);
JERRY_ASSERT (output_start_p + output_size == output_char_p);
ecma_string_t *output_string_p = ecma_new_ecma_string (output_start_p);
ecma_string_t *output_string_p = ecma_new_ecma_string_from_utf8 (output_start_p, output_size);
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (output_string_p));
@@ -847,16 +830,16 @@ ecma_builtin_global_object_decode_uri_component (ecma_value_t this_arg __attr_un
* Helper function to encode byte as hexadecimal values.
*/
static void
ecma_builtin_global_object_byte_to_hex (ecma_char_t *dest_p, /**< destination pointer */
ecma_builtin_global_object_byte_to_hex (lit_utf8_byte_t *dest_p, /**< destination pointer */
uint32_t byte) /**< value */
{
JERRY_ASSERT (byte < 256);
dest_p[0] = '%';
ecma_char_t hex_digit = (ecma_char_t) (byte >> 4);
dest_p[1] = (ecma_char_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
hex_digit = (ecma_char_t) (byte & 0xf);
dest_p[2] = (ecma_char_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
dest_p[1] = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
hex_digit = (lit_utf8_byte_t) (byte & 0xf);
dest_p[2] = (lit_utf8_byte_t) ((hex_digit > 9) ? (hex_digit + ('A' - 10)) : (hex_digit + '0'));
} /* ecma_builtin_global_object_byte_to_hex */
/**
@@ -878,27 +861,29 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
JERRY_ASSERT (ecma_is_value_string (string));
ecma_string_t *input_string_p = ecma_get_string_from_value (string);
uint32_t input_length = (uint32_t) ecma_string_get_length (input_string_p);
lit_utf8_size_t input_size = ecma_string_get_size (input_string_p);
MEM_DEFINE_LOCAL_ARRAY (input_start_p,
input_length + 1,
ecma_char_t);
input_size + 1,
lit_utf8_byte_t);
ecma_string_to_zt_string (input_string_p,
input_start_p,
(ssize_t) (input_length + 1) * (ssize_t) sizeof (ecma_char_t));
input_start_p[input_size] = LIT_BYTE_NULL;
ecma_string_to_utf8_string (input_string_p,
input_start_p,
(ssize_t) (input_size));
/*
* The URI encoding has two major phases: first we validate the input,
* and compute the length of the output, then we encode the input.
*/
ecma_char_t *input_char_p = input_start_p;
uint32_t output_length = 1;
for (uint32_t i = 0; i < input_length; i++)
lit_utf8_iterator_t iter = lit_utf8_iterator_create (input_start_p, input_size);
lit_utf8_size_t output_length = 1;
while (!lit_utf8_iterator_reached_buffer_end (&iter))
{
/* Input validation. */
uint32_t character = *input_char_p++;
lit_code_point_t character = lit_utf8_iterator_read_code_unit_and_increment (&iter);
if (character <= 0x7f)
{
@@ -942,20 +927,20 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
{
MEM_DEFINE_LOCAL_ARRAY (output_start_p,
output_length,
ecma_char_t);
lit_utf8_byte_t);
input_char_p = input_start_p;
ecma_char_t *output_char_p = output_start_p;
for (uint32_t i = 0; i < input_length; i++)
lit_utf8_iterator_t iter = lit_utf8_iterator_create (input_start_p, input_size);
lit_utf8_byte_t *output_char_p = output_start_p;
while (!lit_utf8_iterator_reached_buffer_end (&iter))
{
/* Input decode. */
uint32_t character = *input_char_p++;
lit_code_point_t character = lit_utf8_iterator_read_code_unit_and_increment (&iter);
if (character <= 0x7f)
{
if (ecma_builtin_global_object_character_is_in (character, unescaped_uri_bitset))
{
*output_char_p++ = (ecma_char_t) character;
*output_char_p++ = (lit_utf8_byte_t) character;
}
else
{
@@ -995,7 +980,7 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
*output_char_p = '\0';
JERRY_ASSERT (output_start_p + output_length == output_char_p + 1);
ecma_string_t *output_string_p = ecma_new_ecma_string (output_start_p);
ecma_string_t *output_string_p = ecma_new_ecma_string_from_utf8 (output_start_p, output_length - 1);
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (output_string_p));
@@ -24,6 +24,7 @@
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "lit-magic-strings.h"
/** \addtogroup ecma ECMA
* @{
@@ -83,40 +84,29 @@ ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this arg
'Null' or one of possible object's classes.
The string with null character is maximum 19 characters long. */
const ssize_t buffer_size = 19;
MEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, ecma_char_t);
MEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, lit_utf8_byte_t);
const ecma_char_t *left_square_zt_str_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_LEFT_SQUARE_CHAR);
const ecma_char_t *object_zt_str_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_OBJECT);
const ecma_char_t *space_zt_str_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_SPACE_CHAR);
const ecma_char_t *type_name_zt_str_p = lit_get_magic_string_zt (type_string);
const ecma_char_t *right_square_zt_str_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_RIGHT_SQUARE_CHAR);
ecma_char_t *buffer_ptr = str_buffer;
lit_utf8_byte_t *buffer_ptr = str_buffer;
ssize_t buffer_size_left = buffer_size;
buffer_ptr = ecma_copy_zt_string_to_buffer (left_square_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (object_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (space_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (type_name_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (right_square_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
const lit_magic_string_id_t magic_string_ids[] =
{
LIT_MAGIC_STRING_LEFT_SQUARE_CHAR,
LIT_MAGIC_STRING_OBJECT,
LIT_MAGIC_STRING_SPACE_CHAR,
type_string,
LIT_MAGIC_STRING_RIGHT_SQUARE_CHAR
};
for (uint32_t i = 0; i < sizeof (magic_string_ids) / sizeof (lit_magic_string_id_t); ++i)
{
buffer_ptr = lit_copy_magic_string_to_buffer (magic_string_ids[i], buffer_ptr, buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer);
}
JERRY_ASSERT (buffer_size_left >= 0);
ret_string_p = ecma_new_ecma_string (str_buffer);
ret_string_p = ecma_new_ecma_string_from_utf8 (str_buffer, (lit_utf8_size_t) (buffer_size - buffer_size_left));
MEM_FINALIZE_LOCAL_ARRAY (str_buffer);
@@ -234,7 +234,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
if (is_negative)
{
ecma_string_t *neg_str_p = ecma_new_ecma_string ((const ecma_char_t *) "-");
ecma_string_t *neg_str_p = ecma_new_ecma_string_from_utf8 ((const lit_utf8_byte_t *) "-", 1);
ecma_string_t *neg_inf_str_p = ecma_concat_ecma_strings (neg_str_p, infinity_str_p);
ecma_deref_ecma_string (infinity_str_p);
ecma_deref_ecma_string (neg_str_p);
@@ -276,9 +276,9 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
}
JERRY_ASSERT (buffer_size > 0);
MEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, ecma_char_t);
MEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, lit_utf8_byte_t);
ecma_char_t* p = buff;
lit_utf8_byte_t *p = buff;
if (is_negative)
{
@@ -321,7 +321,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
digit++;
}
*p = (ecma_char_t) ((ecma_char_t) digit + '0');
*p = (lit_utf8_byte_t) ((lit_utf8_byte_t) digit + '0');
p++;
}
}
@@ -339,7 +339,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
digit++;
}
*p = (ecma_char_t) ((ecma_char_t) digit + '0');
*p = (lit_utf8_byte_t) ((lit_utf8_byte_t) digit + '0');
p++;
}
@@ -361,7 +361,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
digit++;
}
*p = (ecma_char_t) ((ecma_char_t) digit + '0');
*p = (lit_utf8_byte_t) ((lit_utf8_byte_t) digit + '0');
p++;
}
}
@@ -369,7 +369,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
JERRY_ASSERT (p - buff < buffer_size);
/* String terminator. */
*p = 0;
ecma_string_t* str = ecma_new_ecma_string ((ecma_char_t *) buff);
ecma_string_t* str = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) (p - buff));
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (str));
MEM_FINALIZE_LOCAL_ARRAY (buff);
@@ -60,7 +60,7 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
{
ret_value = ecma_raise_type_error ((const ecma_char_t *) "Incomplete RegExp type");
ret_value = ecma_raise_type_error ("Incomplete RegExp type");
}
else
{
@@ -77,16 +77,18 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
ecma_string_t *input_str_p = ecma_get_string_from_value (input_str_value);
/* Convert ecma_String_t *to regexp_bytecode_t* */
ecma_length_t input_str_len = ecma_string_get_length (input_str_p);
lit_utf8_size_t input_str_size = ecma_string_get_size (input_str_p);
MEM_DEFINE_LOCAL_ARRAY (input_zt_str_p, input_str_len + 1, ecma_char_t);
MEM_DEFINE_LOCAL_ARRAY (input_utf8_buffer_p, input_str_size + 1, lit_utf8_byte_t);
ssize_t zt_str_size = (ssize_t) (sizeof (ecma_char_t) * (input_str_len + 1));
ecma_string_to_zt_string (input_str_p, input_zt_str_p, zt_str_size);
ecma_string_to_utf8_string (input_str_p, input_utf8_buffer_p, (ssize_t) input_str_size);
ret_value = ecma_regexp_exec_helper (obj_p, bytecode_p, input_zt_str_p);
FIXME ("Update ecma_regexp_exec_helper so that zero symbol is not needed.");
input_utf8_buffer_p[input_str_size] = LIT_BYTE_NULL;
MEM_FINALIZE_LOCAL_ARRAY (input_zt_str_p);
ret_value = ecma_regexp_exec_helper (obj_p, bytecode_p, input_utf8_buffer_p, input_str_size);
MEM_FINALIZE_LOCAL_ARRAY (input_utf8_buffer_p);
ECMA_FINALIZE (input_str_value);
@@ -145,7 +147,7 @@ ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argume
if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
{
ret_value = ecma_raise_type_error ((const ecma_char_t *) "Incomplete RegExp type");
ret_value = ecma_raise_type_error ("Incomplete RegExp type");
}
else
{
@@ -94,7 +94,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
}
else
{
ret_value = ecma_raise_type_error ((const ecma_char_t *) "Invalid argument of RegExp call.");
ret_value = ecma_raise_type_error ("Invalid argument of RegExp call.");
}
}
else
@@ -327,10 +327,10 @@ ecma_builtin_string_prototype_object_slice (ecma_value_t this_arg, /**< this arg
/* 3. */
ecma_string_t *get_string_val = ecma_get_string_from_value (to_string_val);
const uint32_t len = (uint32_t) ecma_string_get_length (get_string_val);
const ecma_length_t len = ecma_string_get_length (get_string_val);
/* 4. 6. */
uint32_t start = 0, end = len;
/* 4. */
ecma_length_t start = 0, end = len;
ECMA_OP_TO_NUMBER_TRY_CATCH (start_num,
arg1,
@@ -360,24 +360,9 @@ ecma_builtin_string_prototype_object_slice (ecma_value_t this_arg, /**< this arg
if (ecma_is_completion_value_empty (ret_value))
{
/* 8. */
const uint32_t span = (start > end) ? 0 : end - start;
const uint32_t new_str_size = (uint32_t) sizeof (ecma_char_t) * (span + 1);
MEM_DEFINE_LOCAL_ARRAY (new_str_buffer, new_str_size, ecma_char_t);
/* 9. */
for (uint32_t idx = 0; idx < span; idx++)
{
new_str_buffer[idx] = ecma_string_get_char_at_pos (get_string_val, start + idx);
}
new_str_buffer[span] = '\0';
ecma_string_t* new_str = ecma_new_ecma_string ((ecma_char_t *) new_str_buffer);
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (new_str));
MEM_FINALIZE_LOCAL_ARRAY (new_str_buffer);
/* 8-9. */
ecma_string_t *new_str_p = ecma_string_substr (get_string_val, start, end);
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (new_str_p));
}
ECMA_FINALIZE (to_string_val);
@@ -507,45 +492,37 @@ ecma_builtin_string_prototype_object_trim (ecma_value_t this_arg) /**< this argu
ecma_string_t *original_string_p = ecma_get_string_from_value (to_string_val);
/* 3 */
const uint32_t len = (uint32_t) ecma_string_get_length (original_string_p);
const lit_utf8_size_t size = ecma_string_get_size (original_string_p);
const ecma_length_t length = ecma_string_get_size (original_string_p);
/* Workaround: avoid repeated call of ecma_string_get_char_at_pos() because its overhead */
uint32_t zt_str_size = (uint32_t) sizeof (ecma_char_t) * (len + 1);
ecma_char_t *original_zt_str_p = (ecma_char_t*) mem_heap_alloc_block (zt_str_size,
MEM_HEAP_ALLOC_SHORT_TERM);
ecma_string_to_zt_string (original_string_p, original_zt_str_p, (ssize_t) zt_str_size);
lit_utf8_byte_t *original_utf8_str_p = (lit_utf8_byte_t *) mem_heap_alloc_block (size + 1,
MEM_HEAP_ALLOC_SHORT_TERM);
ecma_string_to_utf8_string (original_string_p, original_utf8_str_p, (ssize_t) size);
uint32_t prefix = 0, postfix = 0;
uint32_t new_len = 0;
while (prefix < len && isspace (original_zt_str_p[prefix]))
while (prefix < length && isspace (lit_utf8_string_code_unit_at (original_utf8_str_p, size, prefix)))
{
prefix++;
}
while (postfix < len - prefix && isspace (original_zt_str_p[len - postfix - 1]))
while (postfix < length - prefix && isspace (lit_utf8_string_code_unit_at (original_utf8_str_p,
size,
length - postfix - 1)))
{
postfix++;
}
new_len = prefix < len ? len - prefix - postfix : 0;
new_len = prefix < size ? size - prefix - postfix : 0;
MEM_DEFINE_LOCAL_ARRAY (new_str_buffer, new_len + 1, ecma_char_t);
for (uint32_t idx = 0; idx < new_len; ++idx)
{
new_str_buffer[idx] = original_zt_str_p[idx + prefix];
}
new_str_buffer[new_len] = '\0';
ecma_string_t *new_str_p = ecma_new_ecma_string ((ecma_char_t *) new_str_buffer);
ecma_string_t *new_str_p = ecma_string_substr (original_string_p, prefix, prefix + new_len);
/* 4 */
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (new_str_p));
MEM_FINALIZE_LOCAL_ARRAY (new_str_buffer);
mem_heap_free_block (original_zt_str_p);
mem_heap_free_block (original_utf8_str_p);
ECMA_FINALIZE (to_string_val);
ECMA_FINALIZE (check_coercible_val);
@@ -60,12 +60,19 @@ ecma_builtin_string_object_from_char_code (ecma_value_t this_arg __attr_unused__
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
size_t zt_str_buffer_size = sizeof (ecma_char_t) * (args_number + 1u);
if (args_number == 0)
{
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_utf8 (NULL, 0);
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
}
ecma_char_t *ret_zt_str_p = (ecma_char_t*) mem_heap_alloc_block (zt_str_buffer_size,
MEM_HEAP_ALLOC_SHORT_TERM);
ret_zt_str_p[args_number] = ECMA_CHAR_NULL;
lit_utf8_size_t utf8_buf_size = args_number * LIT_UTF8_MAX_BYTES_IN_CODE_UNIT;
ecma_string_t *ret_str_p;
MEM_DEFINE_LOCAL_ARRAY (utf8_buf_p, utf8_buf_size, lit_utf8_byte_t);
lit_utf8_size_t utf8_buf_used = 0;
FIXME ("Support surrogate pairs");
for (ecma_length_t arg_index = 0;
arg_index < args_number;
arg_index++)
@@ -73,26 +80,17 @@ ecma_builtin_string_object_from_char_code (ecma_value_t this_arg __attr_unused__
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
uint32_t uint32_char_code = ecma_number_to_uint32 (arg_num);
uint16_t uint16_char_code = (uint16_t) uint32_char_code;
ecma_char_t code_unit = (uint16_t) uint32_char_code;
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
if ((uint16_char_code >> JERRY_BITSINBYTE) != 0)
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
ret_zt_str_p[arg_index] = (ecma_char_t) uint16_char_code;
}
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
ret_zt_str_p[arg_index] = (ecma_char_t) uint16_char_code;
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
JERRY_ASSERT (utf8_buf_used <= utf8_buf_size - LIT_UTF8_MAX_BYTES_IN_CODE_UNIT);
utf8_buf_used += lit_code_unit_to_utf8 (code_unit, utf8_buf_p + utf8_buf_used);
JERRY_ASSERT (utf8_buf_used <= utf8_buf_size);
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
if (ecma_is_completion_value_throw (ret_value))
{
mem_heap_free_block (ret_zt_str_p);
mem_heap_free_block (utf8_buf_p);
return ret_value;
}
@@ -100,9 +98,9 @@ ecma_builtin_string_object_from_char_code (ecma_value_t this_arg __attr_unused__
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
}
ecma_string_t *ret_str_p = ecma_new_ecma_string (ret_zt_str_p);
ret_str_p = ecma_new_ecma_string_from_utf8 (utf8_buf_p, utf8_buf_used);
mem_heap_free_block (ret_zt_str_p);
MEM_FINALIZE_LOCAL_ARRAY (utf8_buf_p);
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
} /* ecma_builtin_string_object_from_char_code */
@@ -609,7 +609,7 @@ ecma_builtin_bin_search_for_magic_string_id_in_array (const lit_magic_string_id_
if (ids[mid] == key)
{
return mid;
return (int32_t) mid;
}
else if (ids[mid] > key)
{
+12 -12
View File
@@ -46,23 +46,23 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */
{
ecma_completion_value_t ret_value;
ecma_length_t chars_num = ecma_string_get_length (code_p);
MEM_DEFINE_LOCAL_ARRAY (code_zt_buffer_p,
chars_num + 1,
ecma_char_t);
lit_utf8_size_t chars_num = ecma_string_get_size (code_p);
MEM_DEFINE_LOCAL_ARRAY (code_utf8_buffer_p,
chars_num,
lit_utf8_byte_t);
const ssize_t buf_size = (ssize_t) (sizeof (ecma_char_t) * (chars_num + 1));
ssize_t buffer_size_req = ecma_string_to_zt_string (code_p,
code_zt_buffer_p,
buf_size);
const ssize_t buf_size = (ssize_t) chars_num;
ssize_t buffer_size_req = ecma_string_to_utf8_string (code_p,
code_utf8_buffer_p,
buf_size);
JERRY_ASSERT (buffer_size_req == buf_size);
ret_value = ecma_op_eval_chars_buffer (code_zt_buffer_p,
ret_value = ecma_op_eval_chars_buffer ((jerry_api_char_t *) code_utf8_buffer_p,
(size_t) buf_size,
is_direct,
is_called_from_strict_mode_code);
MEM_FINALIZE_LOCAL_ARRAY (code_zt_buffer_p);
MEM_FINALIZE_LOCAL_ARRAY (code_utf8_buffer_p);
return ret_value;
} /* ecma_op_eval */
@@ -77,7 +77,7 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */
* @return completion value
*/
ecma_completion_value_t
ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffer */
ecma_op_eval_chars_buffer (const jerry_api_char_t *code_p, /**< code characters buffer */
size_t code_buffer_size, /**< size of the buffer */
bool is_direct, /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */
bool is_called_from_strict_mode_code) /**< is eval is called from strict mode code */
@@ -91,7 +91,7 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe
bool is_strict_call = (is_direct && is_called_from_strict_mode_code);
is_syntax_correct = parser_parse_eval ((const char *) code_p,
is_syntax_correct = parser_parse_eval (code_p,
code_buffer_size,
is_strict_call,
&opcodes_p);
+1 -1
View File
@@ -30,7 +30,7 @@ ecma_op_eval (ecma_string_t *code_p,
bool is_called_from_strict_mode_code);
extern ecma_completion_value_t
ecma_op_eval_chars_buffer (const ecma_char_t *code_p,
ecma_op_eval_chars_buffer (const jerry_api_char_t *code_p,
size_t code_buffer_size,
bool is_direct,
bool is_called_from_strict_mode_code);
+17 -16
View File
@@ -138,9 +138,10 @@ ecma_new_standard_error_with_message (ecma_standard_error_t error_type, /**< nat
*/
ecma_completion_value_t
ecma_raise_standard_error (ecma_standard_error_t error_type, /**< error type */
const ecma_char_t *msg_p) /**< error message */
const lit_utf8_byte_t *msg_p) /**< error message */
{
ecma_string_t *error_msg_p = ecma_new_ecma_string (msg_p);
ecma_string_t *error_msg_p = ecma_new_ecma_string_from_utf8 (msg_p,
lit_zt_utf8_string_size (msg_p));
ecma_object_t *error_obj_p = ecma_new_standard_error_with_message (error_type, error_msg_p);
ecma_deref_ecma_string (error_msg_p);
return ecma_make_throw_obj_completion_value (error_obj_p);
@@ -153,9 +154,9 @@ ecma_raise_standard_error (ecma_standard_error_t error_type, /**< error type */
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_common_error (const ecma_char_t *msg_p) /**< error message */
ecma_raise_common_error (const char *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_COMMON, msg_p);
return ecma_raise_standard_error (ECMA_ERROR_COMMON, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_common_error */
/**
@@ -167,9 +168,9 @@ ecma_raise_common_error (const ecma_char_t *msg_p) /**< error message */
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_eval_error (const ecma_char_t *msg_p) /**< error message */
ecma_raise_eval_error (const char *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_EVAL, msg_p);
return ecma_raise_standard_error (ECMA_ERROR_EVAL, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_eval_error */
/**
@@ -181,9 +182,9 @@ ecma_raise_eval_error (const ecma_char_t *msg_p) /**< error message */
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_range_error (const ecma_char_t *msg_p) /**< error message */
ecma_raise_range_error (const char *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_RANGE, msg_p);
return ecma_raise_standard_error (ECMA_ERROR_RANGE, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_range_error */
/**
@@ -195,9 +196,9 @@ ecma_raise_range_error (const ecma_char_t *msg_p) /**< error message */
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_reference_error (const ecma_char_t *msg_p) /**< error message */
ecma_raise_reference_error (const char *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_REFERENCE, msg_p);
return ecma_raise_standard_error (ECMA_ERROR_REFERENCE, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_reference_error */
/**
@@ -209,9 +210,9 @@ ecma_raise_reference_error (const ecma_char_t *msg_p) /**< error message */
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_syntax_error (const ecma_char_t *msg_p) /**< error message */
ecma_raise_syntax_error (const char *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_SYNTAX, msg_p);
return ecma_raise_standard_error (ECMA_ERROR_SYNTAX, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_syntax_error */
/**
@@ -223,9 +224,9 @@ ecma_raise_syntax_error (const ecma_char_t *msg_p) /**< error message */
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_type_error (const ecma_char_t *msg_p) /**< error message */
ecma_raise_type_error (const char *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_TYPE, msg_p);
return ecma_raise_standard_error (ECMA_ERROR_TYPE, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_type_error */
/**
@@ -237,9 +238,9 @@ ecma_raise_type_error (const ecma_char_t *msg_p) /**< error message */
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_raise_uri_error (const ecma_char_t *msg_p) /**< error message */
ecma_raise_uri_error (const char *msg_p) /**< error message */
{
return ecma_raise_standard_error (ECMA_ERROR_URI, msg_p);
return ecma_raise_standard_error (ECMA_ERROR_URI, (const lit_utf8_byte_t *) msg_p);
} /* ecma_raise_uri_error */
/**
+8 -8
View File
@@ -48,14 +48,14 @@ extern ecma_object_t *ecma_new_standard_error (ecma_standard_error_t error_type)
extern ecma_object_t *ecma_new_standard_error_with_message (ecma_standard_error_t error_type,
ecma_string_t *message_string_p);
extern ecma_completion_value_t ecma_raise_standard_error (ecma_standard_error_t error_type,
const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_common_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_eval_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_range_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_reference_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_syntax_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_type_error (const ecma_char_t *msg_p);
extern ecma_completion_value_t ecma_raise_uri_error (const ecma_char_t *msg_p);
const lit_utf8_byte_t *msg_p);
extern ecma_completion_value_t ecma_raise_common_error (const char *msg_p);
extern ecma_completion_value_t ecma_raise_eval_error (const char *msg_p);
extern ecma_completion_value_t ecma_raise_range_error (const char *msg_p);
extern ecma_completion_value_t ecma_raise_reference_error (const char *msg_p);
extern ecma_completion_value_t ecma_raise_syntax_error (const char *msg_p);
extern ecma_completion_value_t ecma_raise_type_error (const char *msg_p);
extern ecma_completion_value_t ecma_raise_uri_error (const char *msg_p);
/**
* @}
@@ -72,15 +72,15 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_length_t flags_str_len = ecma_string_get_length (flags_str_p);
MEM_DEFINE_LOCAL_ARRAY (flags_start_p, flags_str_len + 1, ecma_char_t);
ssize_t zt_str_size = (ssize_t) (sizeof (ecma_char_t) * (flags_str_len + 1));
ecma_string_to_zt_string (flags_str_p, flags_start_p, zt_str_size);
FIXME ("Unicode: properly process non-ascii characters.");
lit_utf8_size_t flags_str_size = ecma_string_get_size (flags_str_p);
MEM_DEFINE_LOCAL_ARRAY (flags_start_p, flags_str_size, lit_utf8_byte_t);
ecma_char_t *flags_char_p = flags_start_p;
for (int ch_cnt = 1; flags_char_p
&& ch_cnt < zt_str_size
&& ecma_is_completion_value_empty (ret_value); ch_cnt++)
ecma_string_to_utf8_string (flags_str_p, flags_start_p, (ssize_t) flags_str_size);
lit_utf8_byte_t *flags_char_p = flags_start_p;
while (flags_char_p < flags_start_p + flags_str_size
&& ecma_is_completion_value_empty (ret_value))
{
switch (*flags_char_p)
{
@@ -88,7 +88,7 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
{
if (*flags_p & RE_FLAG_GLOBAL)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Invalid RegExp flags.");
ret_value = ecma_raise_syntax_error ("Invalid RegExp flags.");
}
*flags_p |= RE_FLAG_GLOBAL;
break;
@@ -97,7 +97,7 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
{
if (*flags_p & RE_FLAG_IGNORE_CASE)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Invalid RegExp flags.");
ret_value = ecma_raise_syntax_error ("Invalid RegExp flags.");
}
*flags_p |= RE_FLAG_IGNORE_CASE;
break;
@@ -106,14 +106,14 @@ re_parse_regexp_flags (ecma_string_t *flags_str_p, /**< Input string with flags
{
if (*flags_p & RE_FLAG_MULTILINE)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Invalid RegExp flags.");
ret_value = ecma_raise_syntax_error ("Invalid RegExp flags.");
}
*flags_p |= RE_FLAG_MULTILINE;
break;
}
default:
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Invalid RegExp flags.");
ret_value = ecma_raise_syntax_error ("Invalid RegExp flags.");
break;
}
}
@@ -231,8 +231,8 @@ ecma_op_create_regexp_object (ecma_string_t *pattern_p, /**< input pattern */
/**
* Backtrack a unicode character
*/
static const ecma_char_t *
utf8_backtrack (const ecma_char_t *str_p)
static const lit_utf8_byte_t *
utf8_backtrack (const lit_utf8_byte_t *str_p)
{
/* FIXME: change to string iterator with unicode support, when it would be implemented */
return --str_p;
@@ -242,10 +242,10 @@ utf8_backtrack (const ecma_char_t *str_p)
* Helper to get an input character and increase string pointer.
*/
static ecma_char_t
get_input_char (const ecma_char_t** char_p)
get_input_char (const lit_utf8_byte_t **char_p)
{
/* FIXME: change to string iterator with unicode support, when it would be implemented */
const ecma_char_t ch = **char_p;
const lit_utf8_byte_t ch = **char_p;
(*char_p)++;
return ch;
} /* get_input_char */
@@ -254,7 +254,7 @@ get_input_char (const ecma_char_t** char_p)
* Helper to get current input character, won't increase string pointer.
*/
static ecma_char_t
lookup_input_char (const ecma_char_t *str_p)
lookup_input_char (const lit_utf8_byte_t *str_p)
{
/* FIXME: change to string iterator with unicode support, when it would be implemented */
return *str_p;
@@ -264,7 +264,7 @@ lookup_input_char (const ecma_char_t *str_p)
* Helper to get previous input character, won't decrease string pointer.
*/
static ecma_char_t
lookup_prev_char (const ecma_char_t *str_p)
lookup_prev_char (const lit_utf8_byte_t *str_p)
{
/* FIXME: change to string iterator with unicode support, when it would be implemented */
return *(--str_p);
@@ -283,15 +283,15 @@ lookup_prev_char (const ecma_char_t *str_p)
static ecma_completion_value_t
re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
re_bytecode_t *bc_p, /**< pointer to the current RegExp bytecode */
const ecma_char_t *str_p, /**< pointer to the current input character */
const ecma_char_t **res_p) /**< pointer to the matching substring */
const lit_utf8_byte_t *str_p, /**< pointer to the current input character */
const lit_utf8_byte_t **res_p) /**< pointer to the matching substring */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
re_opcode_t op;
if (re_ctx_p->recursion_depth >= RE_EXECUTE_RECURSION_LIMIT)
{
ret_value = ecma_raise_range_error ((const ecma_char_t *) "RegExp executor recursion limit is exceeded.");
ret_value = ecma_raise_range_error ("RegExp executor recursion limit is exceeded.");
return ret_value;
}
re_ctx_p->recursion_depth++;
@@ -300,7 +300,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
{
if (re_ctx_p->match_limit >= RE_EXECUTE_MATCH_LIMIT)
{
ret_value = ecma_raise_range_error ((const ecma_char_t *) "RegExp executor steps limit is exceeded.");
ret_value = ecma_raise_range_error ("RegExp executor steps limit is exceeded.");
return ret_value;
}
re_ctx_p->match_limit++;
@@ -450,10 +450,10 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
case RE_OP_LOOKAHEAD_NEG:
{
ecma_completion_value_t match_value = ecma_make_empty_completion_value ();
const ecma_char_t *sub_str_p = NULL;
const lit_utf8_byte_t *sub_str_p = NULL;
MEM_DEFINE_LOCAL_ARRAY (saved_bck_p, re_ctx_p->num_of_captures, ecma_char_t *);
size_t size = (size_t) (re_ctx_p->num_of_captures) * sizeof (const ecma_char_t *);
MEM_DEFINE_LOCAL_ARRAY (saved_bck_p, re_ctx_p->num_of_captures, lit_utf8_byte_t *);
size_t size = (size_t) (re_ctx_p->num_of_captures) * sizeof (const lit_utf8_byte_t *);
memcpy (saved_bck_p, re_ctx_p->saved_p, size);
do
@@ -566,7 +566,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
case RE_OP_BACKREFERENCE:
{
uint32_t backref_idx;
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *sub_str_p;
backref_idx = re_get_value (&bc_p);
JERRY_DDLOG ("Execute RE_OP_BACKREFERENCE (idx: %d): ", backref_idx);
@@ -606,7 +606,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
}
case RE_OP_SAVE_AT_START:
{
const ecma_char_t *old_start_p;
const lit_utf8_byte_t *old_start_p;
re_bytecode_t *old_bc_p;
JERRY_DDLOG ("Execute RE_OP_SAVE_AT_START\n");
@@ -615,7 +615,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
do
{
uint32_t offset = re_get_value (&bc_p);
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *sub_str_p;
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_p, &sub_str_p);
if (ecma_is_value_true (match_value))
{
@@ -671,8 +671,8 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
* after the group first, if zero iteration is allowed.
*/
uint32_t start_idx, iter_idx, offset;
const ecma_char_t *old_start_p;
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *old_start_p;
const lit_utf8_byte_t *sub_str_p;
re_bytecode_t *old_bc_p;
old_bc_p = bc_p; /* save the bytecode start position of the group start */
@@ -725,8 +725,8 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
case RE_OP_NON_CAPTURE_GREEDY_ZERO_GROUP_START:
{
uint32_t start_idx, iter_idx, old_iteration_cnt, offset;
const ecma_char_t *old_start_p;
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *old_start_p;
const lit_utf8_byte_t *sub_str_p;
re_bytecode_t *old_bc_p;
re_bytecode_t *end_bc_p = NULL;
@@ -802,7 +802,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
case RE_OP_NON_CAPTURE_NON_GREEDY_GROUP_END:
{
uint32_t end_idx, iter_idx, min, max;
const ecma_char_t *old_end_p;
const lit_utf8_byte_t *old_end_p;
re_bytecode_t *old_bc_p;
/*
@@ -835,7 +835,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
old_end_p = re_ctx_p->saved_p[end_idx];
re_ctx_p->saved_p[end_idx] = str_p;
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *sub_str_p;
ecma_completion_value_t match_value = re_match_regexp (re_ctx_p, bc_p, str_p, &sub_str_p);
if (ecma_is_value_true (match_value))
{
@@ -860,9 +860,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
case RE_OP_NON_CAPTURE_GREEDY_GROUP_END:
{
uint32_t start_idx, end_idx, iter_idx, min, max, offset;
const ecma_char_t *old_start_p;
const ecma_char_t *old_end_p;
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *old_start_p;
const lit_utf8_byte_t *old_end_p;
const lit_utf8_byte_t *sub_str_p;
re_bytecode_t *old_bc_p;
end_idx = re_get_value (&bc_p);
@@ -972,7 +972,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
case RE_OP_NON_GREEDY_ITERATOR:
{
uint32_t min, max, offset, num_of_iter;
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *sub_str_p;
min = re_get_value (&bc_p);
max = re_get_value (&bc_p);
@@ -1017,7 +1017,7 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
case RE_OP_GREEDY_ITERATOR:
{
uint32_t min, max, offset, num_of_iter;
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *sub_str_p;
min = re_get_value (&bc_p);
max = re_get_value (&bc_p);
@@ -1122,7 +1122,9 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
ecma_property_descriptor_t array_item_prop_desc = ecma_make_empty_property_descriptor ();
array_item_prop_desc.is_value_defined = true;
ecma_string_t *input_str_p = ecma_new_ecma_string (re_ctx_p->input_start_p);
ecma_string_t *input_str_p = ecma_new_ecma_string_from_utf8 (re_ctx_p->input_start_p,
(lit_utf8_size_t) (re_ctx_p->input_end_p -
re_ctx_p->input_start_p));
array_item_prop_desc.value = ecma_make_string_value (input_str_p);
array_item_prop_desc.is_writable_defined = true;
@@ -1178,13 +1180,14 @@ re_set_result_array_properties (ecma_object_t *array_obj_p, /**< result array */
ecma_completion_value_t
ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
re_bytecode_t *bc_p, /**< start of the RegExp bytecode */
const ecma_char_t *str_p) /**< start of the input string */
const lit_utf8_byte_t *str_p, /**< start of the input string */
lit_utf8_size_t str_size) /**< size of the input string */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_length_t input_length = ecma_zt_string_length (str_p);
lit_utf8_size_t input_size = str_size;
re_matcher_ctx_t re_ctx;
re_ctx.input_start_p = str_p;
re_ctx.input_end_p = str_p + strlen ((char *) str_p);
re_ctx.input_end_p = str_p + str_size;
re_ctx.match_limit = 0;
re_ctx.recursion_depth = 0;
@@ -1199,7 +1202,7 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
JERRY_ASSERT (re_ctx.num_of_captures % 2 == 0);
re_ctx.num_of_non_captures = re_get_value (&bc_p);
MEM_DEFINE_LOCAL_ARRAY (saved_p, re_ctx.num_of_captures + re_ctx.num_of_non_captures, const ecma_char_t*);
MEM_DEFINE_LOCAL_ARRAY (saved_p, re_ctx.num_of_captures + re_ctx.num_of_non_captures, const lit_utf8_byte_t *);
for (uint32_t i = 0; i < re_ctx.num_of_captures + re_ctx.num_of_non_captures; i++)
{
saved_p[i] = NULL;
@@ -1229,10 +1232,10 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
}
/* 2. Try to match */
const ecma_char_t *sub_str_p;
const lit_utf8_byte_t *sub_str_p;
while (str_p && str_p <= re_ctx.input_end_p && ecma_is_completion_value_empty (ret_value))
{
if (index < 0 || index > (int32_t) input_length)
if (index < 0 || index > (int32_t) input_size)
{
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL);
ecma_number_t *lastindex_num_p = ecma_alloc_number ();
@@ -1290,7 +1293,7 @@ ecma_regexp_exec_helper (ecma_object_t *obj_p, /**< RegExp object */
if (capture_str_len > 0)
{
capture_str_p = ecma_new_ecma_string (re_ctx.saved_p[i], capture_str_len);
capture_str_p = ecma_new_ecma_string_from_utf8 (re_ctx.saved_p[i], capture_str_len);
}
else
{
@@ -40,9 +40,9 @@
*/
typedef struct
{
const ecma_char_t **saved_p;
const ecma_char_t *input_start_p;
const ecma_char_t *input_end_p;
const lit_utf8_byte_t **saved_p;
const lit_utf8_byte_t *input_start_p;
const lit_utf8_byte_t *input_end_p;
uint32_t match_limit;
uint32_t recursion_depth;
uint32_t num_of_captures;
@@ -55,7 +55,10 @@ extern ecma_completion_value_t
ecma_op_create_regexp_object (ecma_string_t *pattern_p, ecma_string_t *flags_str_p);
extern ecma_completion_value_t
ecma_regexp_exec_helper (ecma_object_t *obj_p, re_bytecode_t *bc_p, const ecma_char_t *str_p);
ecma_regexp_exec_helper (ecma_object_t *obj_p,
re_bytecode_t *bc_p,
const lit_utf8_byte_t *str_p,
lit_utf8_size_t str_size);
/**
* @}
@@ -71,7 +71,6 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of
prim_prop_str_value_p = ecma_get_string_from_completion_value (to_str_arg_value);
ecma_length_t string_len = ecma_string_get_length (prim_prop_str_value_p);
length_value = ecma_uint32_to_number ((uint32_t) string_len);
}
}
@@ -188,8 +187,7 @@ ecma_op_string_object_get_own_property (ecma_object_t *obj_p, /**< the string ob
ecma_char_t c = ecma_string_get_char_at_pos (prim_value_str_p, uint32_index);
// 9.
ecma_char_t new_prop_zt_str_p[2] = { c, ECMA_CHAR_NULL };
ecma_string_t *new_prop_str_value_p = ecma_new_ecma_string (new_prop_zt_str_p);
ecma_string_t *new_prop_str_value_p = ecma_new_ecma_string_from_code_unit (c);
new_prop_p = ecma_create_named_data_property (obj_p,
new_prop_name_p,
+35 -12
View File
@@ -73,17 +73,18 @@ typedef enum
/**
* Jerry's char value
*/
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
typedef uint8_t jerry_api_char_t;
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
typedef uint16_t jerry_api_char_t;
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
/**
* Pointer to an array of character values
*/
typedef jerry_api_char_t* jerry_api_char_ptr_t;
/**
* Jerry's size
*/
typedef uint32_t jerry_api_size_t;
/**
* Jerry's length
*/
@@ -139,7 +140,7 @@ typedef void (*jerry_object_free_callback_t) (const uintptr_t native_p);
extern EXTERN_C ssize_t
jerry_api_string_to_char_buffer (const jerry_api_string_t *string_p,
char *buffer_p,
jerry_api_char_t *buffer_p,
ssize_t buffer_size);
extern EXTERN_C
jerry_api_string_t* jerry_api_acquire_string (jerry_api_string_t *string_p);
@@ -155,11 +156,18 @@ extern EXTERN_C
void jerry_api_release_value (jerry_api_value_t *value_p);
extern EXTERN_C
jerry_api_string_t* jerry_api_create_string (const char *v);
jerry_api_string_t *jerry_api_create_string (const jerry_api_char_t *v);
extern EXTERN_C
jerry_api_string_t *jerry_api_create_string_sz (const jerry_api_char_t *, jerry_api_size_t);
extern EXTERN_C
jerry_api_object_t* jerry_api_create_object (void);
extern EXTERN_C
jerry_api_object_t* jerry_api_create_error (jerry_api_error_t error_type, const char *message_p);
jerry_api_object_t* jerry_api_create_error (jerry_api_error_t error_type,
const jerry_api_char_t *message_p);
extern EXTERN_C
jerry_api_object_t* jerry_api_create_error_sz (jerry_api_error_t error_type,
const jerry_api_char_t *message_p,
jerry_api_size_t message_size);
extern EXTERN_C
jerry_api_object_t* jerry_api_create_external_function (jerry_external_handler_t handler_p);
@@ -170,21 +178,36 @@ bool jerry_api_is_constructor (const jerry_api_object_t *object_p);
extern EXTERN_C
bool jerry_api_add_object_field (jerry_api_object_t *object_p,
const char *field_name_p,
const jerry_api_char_t *field_name_p,
jerry_api_size_t field_name_size,
const jerry_api_value_t *field_value_p,
bool is_writable);
extern EXTERN_C
bool jerry_api_delete_object_field (jerry_api_object_t *object_p,
const char *field_name_p);
const jerry_api_char_t *field_name_p,
jerry_api_size_t field_name_size);
extern EXTERN_C
bool jerry_api_get_object_field_value (jerry_api_object_t *object_p,
const char *field_name_p,
const jerry_api_char_t *field_name_p,
jerry_api_value_t *field_value_p);
extern EXTERN_C
bool jerry_api_get_object_field_value_sz (jerry_api_object_t *object_p,
const jerry_api_char_t *field_name_p,
jerry_api_size_t field_name_size,
jerry_api_value_t *field_value_p);
extern EXTERN_C
bool jerry_api_set_object_field_value (jerry_api_object_t *object_p,
const char *field_name_p,
const jerry_api_char_t *field_name_p,
const jerry_api_value_t *field_value_p);
extern EXTERN_C
bool jerry_api_set_object_field_value_sz (jerry_api_object_t *object_p,
const jerry_api_char_t *field_name_p,
jerry_api_size_t field_name_size,
const jerry_api_value_t *field_value_p);
extern EXTERN_C
bool jerry_api_get_object_native_handle (jerry_api_object_t *object_p, uintptr_t* out_handle_p);
@@ -207,7 +230,7 @@ bool jerry_api_construct_object (jerry_api_object_t *function_object_p,
uint16_t args_count);
extern EXTERN_C
jerry_completion_code_t jerry_api_eval (const char *source_p,
jerry_completion_code_t jerry_api_eval (const jerry_api_char_t *source_p,
size_t source_size,
bool is_direct,
bool is_strict,
+126 -24
View File
@@ -25,6 +25,7 @@
#include "ecma-init-finalize.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "lit-magic-strings.h"
#include "parser.h"
#include "serializer.h"
@@ -281,12 +282,27 @@ jerry_api_convert_api_value_to_ecma_value (ecma_value_t *out_value_p, /**< out:
*/
ssize_t
jerry_api_string_to_char_buffer (const jerry_api_string_t *string_p, /**< string descriptor */
char *buffer_p, /**< output characters buffer */
ssize_t buffer_size) /**< size of output buffer */
jerry_api_char_t *buffer_p, /**< output characters buffer */
ssize_t buffer_size) /**< size of output buffer */
{
jerry_assert_api_available ();
return ecma_string_to_zt_string (string_p, (ecma_char_t*) buffer_p, buffer_size);
if (buffer_size > 0)
{
buffer_size--;
}
ssize_t ret_val = ecma_string_to_utf8_string (string_p, (lit_utf8_byte_t *) buffer_p, buffer_size);
if (ret_val >= 0)
{
buffer_p[ret_val] = 0;
ret_val++;
}
else
{
ret_val--;
}
return ret_val;
} /* jerry_api_string_to_char_buffer */
/**
@@ -383,14 +399,32 @@ jerry_api_release_value (jerry_api_value_t *value_p) /**< API value */
*
* @return pointer to created string
*/
jerry_api_string_t*
jerry_api_create_string (const char *v) /**< string value */
jerry_api_string_t *
jerry_api_create_string (const jerry_api_char_t *v) /**< string value */
{
jerry_assert_api_available ();
return ecma_new_ecma_string ((const ecma_char_t*) v);
return ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) v, lit_zt_utf8_string_size ((lit_utf8_byte_t *) v));
} /* jerry_api_create_string */
/**
* Create a string
*
* Note:
* caller should release the string with jerry_api_release_string, just when the value becomes unnecessary.
*
* @return pointer to created string
*/
jerry_api_string_t *
jerry_api_create_string_sz (const jerry_api_char_t *v, /**< string value */
jerry_api_size_t v_size)
{
jerry_assert_api_available ();
return ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) v,
(lit_utf8_size_t) v_size);
} /* jerry_api_create_string_sz */
/**
* Create an object
*
@@ -417,8 +451,27 @@ jerry_api_create_object (void)
*/
jerry_api_object_t*
jerry_api_create_error (jerry_api_error_t error_type, /**< type of error */
const char *message_p) /**< value of 'message' property
* of constructed error object */
const jerry_api_char_t *message_p) /**< value of 'message' property
* of constructed error object */
{
return jerry_api_create_error_sz (error_type,
(lit_utf8_byte_t *) message_p,
lit_zt_utf8_string_size (message_p));
}
/**
* Create an error object
*
* Note:
* caller should release the object with jerry_api_release_object, just when the value becomes unnecessary.
*
* @return pointer to created error object
*/
jerry_api_object_t*
jerry_api_create_error_sz (jerry_api_error_t error_type, /**< type of error */
const jerry_api_char_t *message_p, /**< value of 'message' property
* of constructed error object */
jerry_api_size_t message_size) /**< size of the message in bytes */
{
jerry_assert_api_available ();
@@ -473,7 +526,8 @@ jerry_api_create_error (jerry_api_error_t error_type, /**< type of error */
}
else
{
ecma_string_t* message_string_p = ecma_new_ecma_string ((const ecma_char_t*) message_p);
ecma_string_t* message_string_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) message_p,
(lit_utf8_size_t) message_size);
ecma_object_t* error_object_p = ecma_new_standard_error_with_message (standard_error_type, message_string_p);
@@ -632,7 +686,8 @@ jerry_api_is_constructor (const jerry_api_object_t* object_p) /**< an object */
*/
bool
jerry_api_add_object_field (jerry_api_object_t *object_p, /**< object to add field at */
const char *field_name_p, /**< name of the field */
const jerry_api_char_t *field_name_p, /**< name of the field */
jerry_api_size_t field_name_size, /**< size of field name in bytes */
const jerry_api_value_t *field_value_p, /**< value of the field */
bool is_writable) /**< flag indicating whether the created field should be writable */
{
@@ -642,7 +697,8 @@ jerry_api_add_object_field (jerry_api_object_t *object_p, /**< object to add fie
if (ecma_get_object_extensible (object_p))
{
ecma_string_t* field_name_str_p = ecma_new_ecma_string ((const ecma_char_t*) field_name_p);
ecma_string_t* field_name_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) field_name_p,
(lit_utf8_size_t) field_name_size);
ecma_property_t *prop_p = ecma_op_object_get_own_property (object_p, field_name_str_p);
@@ -678,13 +734,15 @@ jerry_api_add_object_field (jerry_api_object_t *object_p, /**< object to add fie
*/
bool
jerry_api_delete_object_field (jerry_api_object_t *object_p, /**< object to delete field at */
const char *field_name_p) /**< name of the field */
const jerry_api_char_t *field_name_p, /**< name of the field */
jerry_api_size_t field_name_size) /**< size of the field name in bytes */
{
jerry_assert_api_available ();
bool is_successful = true;
ecma_string_t* field_name_str_p = ecma_new_ecma_string ((const ecma_char_t*) field_name_p);
ecma_string_t* field_name_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) field_name_p,
(lit_utf8_size_t) field_name_size);
ecma_completion_value_t delete_completion = ecma_op_object_delete (object_p,
field_name_str_p,
@@ -704,6 +762,27 @@ jerry_api_delete_object_field (jerry_api_object_t *object_p, /**< object to dele
return is_successful;
} /* jerry_api_delete_object_field */
/**
* Get value of field in the specified object
*
* Note:
* if value was retrieved successfully, it should be freed
* with jerry_api_release_value just when it becomes unnecessary.
*
* @return true, if field value was retrieved successfully, i.e. upon the call:
* - there is field with specified name in the object;
* false - otherwise.
*/
bool jerry_api_get_object_field_value (jerry_api_object_t *object_p,
const jerry_api_char_t *field_name_p,
jerry_api_value_t *field_value_p)
{
return jerry_api_get_object_field_value_sz (object_p,
field_name_p,
lit_zt_utf8_string_size (field_name_p),
field_value_p);
}
/**
* Get value of field in the specified object
*
@@ -716,15 +795,18 @@ jerry_api_delete_object_field (jerry_api_object_t *object_p, /**< object to dele
* false - otherwise.
*/
bool
jerry_api_get_object_field_value (jerry_api_object_t *object_p, /**< object */
const char *field_name_p, /**< name of the field */
jerry_api_value_t *field_value_p) /**< out: field value, if retrieved successfully */
jerry_api_get_object_field_value_sz (jerry_api_object_t *object_p, /**< object */
const jerry_api_char_t *field_name_p, /**< name of the field */
jerry_api_size_t field_name_size, /**< size of field name in bytes */
jerry_api_value_t *field_value_p) /**< out: field value, if retrieved
* successfully */
{
jerry_assert_api_available ();
bool is_successful = true;
ecma_string_t* field_name_str_p = ecma_new_ecma_string ((const ecma_char_t*) field_name_p);
ecma_string_t* field_name_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) field_name_p,
(lit_utf8_size_t) field_name_size);
ecma_completion_value_t get_completion = ecma_op_object_get (object_p,
field_name_str_p);
@@ -758,14 +840,34 @@ jerry_api_get_object_field_value (jerry_api_object_t *object_p, /**< object */
*/
bool
jerry_api_set_object_field_value (jerry_api_object_t *object_p, /**< object */
const char *field_name_p, /**< name of the field */
const jerry_api_char_t *field_name_p, /**< name of the field */
const jerry_api_value_t *field_value_p) /**< field value to set */
{
return jerry_api_set_object_field_value_sz (object_p,
field_name_p,
lit_zt_utf8_string_size (field_name_p),
field_value_p);
}
/**
* Set value of field in the specified object
*
* @return true, if field value was set successfully, i.e. upon the call:
* - field value is writable;
* false - otherwise.
*/
bool
jerry_api_set_object_field_value_sz (jerry_api_object_t *object_p, /**< object */
const jerry_api_char_t *field_name_p, /**< name of the field */
jerry_api_size_t field_name_size, /**< size of field name in bytes */
const jerry_api_value_t *field_value_p) /**< field value to set */
{
jerry_assert_api_available ();
bool is_successful = true;
ecma_string_t* field_name_str_p = ecma_new_ecma_string ((const ecma_char_t*) field_name_p);
ecma_string_t* field_name_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) field_name_p,
(lit_utf8_size_t) field_name_size);
ecma_value_t value_to_put;
jerry_api_convert_api_value_to_ecma_value (&value_to_put, field_value_p);
@@ -1081,7 +1183,7 @@ jerry_api_get_global (void)
* @return completion status
*/
jerry_completion_code_t
jerry_api_eval (const char *source_p, /**< source code */
jerry_api_eval (const jerry_api_char_t *source_p, /**< source code */
size_t source_size, /**< length of source code */
bool is_direct, /**< perform eval invocation in direct mode */
bool is_strict, /**< perform eval as it is called from strict mode code */
@@ -1091,7 +1193,7 @@ jerry_api_eval (const char *source_p, /**< source code */
jerry_completion_code_t status;
ecma_completion_value_t completion = ecma_op_eval_chars_buffer ((const ecma_char_t*) source_p,
ecma_completion_value_t completion = ecma_op_eval_chars_buffer ((const lit_utf8_byte_t *) source_p,
source_size,
is_direct,
is_strict);
@@ -1222,7 +1324,7 @@ jerry_reg_err_callback (jerry_error_callback_t callback) /**< pointer to callbac
* false - otherwise (SyntaxError was raised).
*/
bool
jerry_parse (const char* source_p, /**< script source */
jerry_parse (const jerry_api_char_t* source_p, /**< script source */
size_t source_size) /**< script source size */
{
jerry_assert_api_available ();
@@ -1276,7 +1378,7 @@ jerry_run (void)
* @return completion status
*/
jerry_completion_code_t
jerry_run_simple (const char *script_source, /**< script source */
jerry_run_simple (const jerry_api_char_t *script_source, /**< script source */
size_t script_source_size, /**< script source size */
jerry_flag_t flags) /**< combination of Jerry flags */
{
@@ -1363,5 +1465,5 @@ jerry_register_external_magic_strings (const jerry_api_char_ptr_t* ex_str_items,
uint32_t count, /**< number of the strings */
const jerry_api_length_t* str_lengths) /**< lengths of the strings */
{
lit_magic_strings_ex_set ((const ecma_char_ptr_t*)ex_str_items, count, (const ecma_length_t*)str_lengths);
lit_magic_strings_ex_set ((const lit_utf8_byte_t **) ex_str_items, count, (const lit_utf8_size_t *) str_lengths);
} /* jerry_register_external_magic_strings */
+2 -2
View File
@@ -83,11 +83,11 @@ extern EXTERN_C void jerry_cleanup (void);
extern EXTERN_C void jerry_get_memory_limits (size_t *out_data_bss_brk_limit_p, size_t *out_stack_limit_p);
extern EXTERN_C void jerry_reg_err_callback (jerry_error_callback_t callback);
extern EXTERN_C bool jerry_parse (const char* source_p, size_t source_size);
extern EXTERN_C bool jerry_parse (const jerry_api_char_t * source_p, size_t source_size);
extern EXTERN_C jerry_completion_code_t jerry_run (void);
extern EXTERN_C jerry_completion_code_t
jerry_run_simple (const char *script_source,
jerry_run_simple (const jerry_api_char_t *script_source,
size_t script_source_size,
jerry_flag_t flags);
+76 -13
View File
@@ -18,25 +18,63 @@
#include "jrt.h"
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
/**
* Description of an ecma-character
* ECMAScript standard defines terms "code unit" and "character" as 16-bit unsigned value
* used to represent 16-bit unit of text, this is the same as code unit in UTF-16 (See ECMA-262 5.1 Chapter 6).
*
* The term "code point" or "Unicode character" is used to refer a single Unicode scalar value (may be longer
* than 16 bits: 0x0 - 0x10FFFFF). One code point could be represented with one ore two 16-bit code units.
*
* According to the standard all strings and source text are assumed to be a sequence of code units.
* Length of a string equals to number of code units in the string, which is not the same as number of Unicode
* characters in a string.
*
* Internally JerryScript engine uses UTF-8 representation of strings to reduce memory overhead. Unicode character
* occupies from one to four bytes in UTF-8 representation.
*
* Unicode scalar value | Bytes in UTF-8 | Bytes in UTF-16
* | (internal representation) |
* ----------------------------------------------------------------------
* 0x0 - 0x7F | 1 byte | 2 bytes
* 0x80 - 0x7FF | 2 bytes | 2 bytes
* 0x800 - 0xFFFF | 3 bytes | 2 bytes
* 0x10000 - 0x10FFFF | 4 bytes | 4 bytes
*
* Scalar values from 0xD800 to 0xDFFF are permanently reserved by Unicode standard to encode high and low
* surrogates in UTF-16 (Code points 0x10000 - 0x10FFFF are encoded via pair of surrogates in UTF-16).
* Despite that the official Unicode standard says that no UTF forms can encode these code points, we allow
* them to be encoded inside strings. The reason for that is compatibility with ECMA standard.
*
* For example, assume a string which consists one Unicode character: 0x1D700 (Mathematical Italic Small Epsilon).
* It has the following representation in UTF-16: 0xD835 0xDF00.
*
* ECMA standard allows extracting a substring from this string:
* > var str = String.fromCharCode (0xD835, 0xDF00); // Create a string containing one character: 0x1D700
* > str.length; // 2
* > var str1 = str.substring (0, 1);
* > str1.length; // 1
* > str1.charCodeAt (0); // 55349 (this equals to 0xD835)
*
* Internally original string would be represented in UTF-8 as the following byte sequence: 0xF0 0x9D 0x9C 0x80.
* After substring extraction high surrogate 0xD835 should be encoded via UTF-8: 0xED 0xA0 0xB5.
*
* Pair of low and high surrogates encoded separately should never occur in internal string representation,
* it should be encoded as any code point and occupy 4 bytes. So, when constructing a string from two surrogates,
* it should be processed gracefully;
* > var str1 = String.fromCharCode (0xD835); // 0xED 0xA0 0xB5 - internal representation
* > var str2 = String.fromCharCode (0xDF00); // 0xED 0xBC 0x80 - internal representation
* > var str = str1 + str2; // 0xF0 0x9D 0x9C 0x80 - internal representation,
* // !!! not 0xED 0xA0 0xB5 0xED 0xBC 0x80
*/
typedef uint8_t ecma_char_t;
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
/**
* Description of an ecma-character
* Description of an ecma-character, which represents 16-bit code unit,
* which is equal to UTF-16 character (see Chapter 6 from ECMA-262 5.1)
*/
typedef uint16_t ecma_char_t;
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
/**
* Description of an ecma-character pointer
*/
typedef ecma_char_t *ecma_char_ptr_t;
/**
* Null character (zt-string end marker)
* Null character
*/
#define ECMA_CHAR_NULL ((ecma_char_t) '\0')
@@ -45,13 +83,38 @@ typedef ecma_char_t *ecma_char_ptr_t;
*/
typedef uint32_t ecma_length_t;
/**
* Description of an ecma-character pointer
*/
typedef ecma_char_t *ecma_char_ptr_t;
/**
* Max bytes needed to represent a code unit (utf-16 char) via utf-8 encoding
*/
#define LIT_UTF8_MAX_BYTES_IN_CODE_UNIT (3)
/**
* A byte of utf-8 string
*/
typedef uint8_t lit_utf8_byte_t;
/**
* Size of a utf-8 string in bytes
*/
typedef uint32_t lit_utf8_size_t;
/**
* Unicode code point
*/
typedef uint32_t lit_code_point_t;
/**
* ECMA string hash
*/
typedef uint8_t lit_string_hash_t;
/**
* Length of string hash, in bits
* ECMA string hash value length, in bits
*/
#define LIT_STRING_HASH_BITS (sizeof (lit_string_hash_t) * JERRY_BITSINBYTE)
+51 -60
View File
@@ -16,6 +16,7 @@
#include "lit-literal-storage.h"
#include "ecma-helpers.h"
#include "lit-literal.h"
#include "lit-magic-strings.h"
/**
* Literal storage
@@ -57,18 +58,18 @@ lit_charset_record_t::set_prev (rcs_record_t *prev_rec_p) /**< pointer to the re
* Set the charset of the record
*/
void
lit_charset_record_t::set_charset (const ecma_char_t *str, /**< buffer containing characters to set */
size_t size) /**< size of the buffer in bytes */
lit_charset_record_t::set_charset (const lit_utf8_byte_t *str, /**< buffer containing characters to set */
lit_utf8_size_t size) /**< size of the buffer in bytes */
{
JERRY_ASSERT (header_size () + size == get_size () - get_alignment_bytes_count ());
rcs_record_iterator_t it ((rcs_recordset_t *)&lit_storage, (rcs_record_t *)this);
it.skip (header_size ());
for (size_t i = 0; i < get_length (); ++i)
for (lit_utf8_size_t i = 0; i < get_length (); ++i)
{
it.write<ecma_char_t> (str[i]);
it.skip<ecma_char_t> ();
it.write<lit_utf8_byte_t> (str[i]);
it.skip<lit_utf8_byte_t> ();
}
} /* lit_charset_record_t::set_charset */
@@ -77,38 +78,39 @@ lit_charset_record_t::set_charset (const ecma_char_t *str, /**< buffer containin
*
* @return number of code units written to the buffer
*/
ecma_length_t
lit_charset_record_t::get_charset (ecma_char_t *buff, /**< output buffer */
lit_utf8_size_t
lit_charset_record_t::get_charset (lit_utf8_byte_t *buff, /**< output buffer */
size_t size) /**< size of the output buffer in bytes */
{
JERRY_ASSERT (buff && size >= sizeof (ecma_char_t));
JERRY_ASSERT (buff && size >= sizeof (lit_utf8_byte_t));
rcs_record_iterator_t it ((rcs_recordset_t *)&lit_storage, (rcs_record_t *)this);
it.skip (header_size ());
ecma_length_t len = get_length ();
size_t i;
lit_utf8_size_t len = get_length ();
lit_utf8_size_t i;
for (i = 0; i < len && size > sizeof (ecma_char_t); ++i)
for (i = 0; i < len && size > 0; ++i)
{
buff[i] = it.read<ecma_char_t> ();
it.skip<ecma_char_t> ();
size -= sizeof (ecma_char_t);
buff[i] = it.read<lit_utf8_byte_t> ();
it.skip<lit_utf8_byte_t> ();
size -= sizeof (lit_utf8_byte_t);
}
return (ecma_length_t) i;
return i;
} /* lit_charset_record_t::get_charset */
/**
* Compares characters from the record to the string
*
* @return 0 if strings are equal
* -1 if str2 is greater
* 1 if str2 is less
* -1 if str_to_compare_with is greater
* 1 if str_to_compare_with is less
*/
int
lit_charset_record_t::compare_zt (const ecma_char_t *str_to_compare_with, /**< buffer with string to compare */
size_t length) /**< length of the string in buffer str2 */
lit_charset_record_t::compare_utf8 (const lit_utf8_byte_t *str_to_compare_with, /**< buffer with string to compare */
lit_utf8_size_t str_size) /**< size of the string */
{
TODO ("Support utf-8 in comparison.");
size_t i;
if (get_length () == 0)
@@ -132,9 +134,9 @@ lit_charset_record_t::compare_zt (const ecma_char_t *str_to_compare_with, /**< b
it_this.skip (header_size ());
for (i = 0; i < get_length () && i < length; i++)
for (i = 0; i < get_length () && i < str_size; i++)
{
ecma_char_t chr = it_this.read<ecma_char_t> ();
lit_utf8_byte_t chr = it_this.read<lit_utf8_byte_t> ();
if (chr > str_to_compare_with[i])
{
@@ -145,10 +147,10 @@ lit_charset_record_t::compare_zt (const ecma_char_t *str_to_compare_with, /**< b
return -1;
}
it_this.skip<ecma_char_t> ();
it_this.skip<lit_utf8_byte_t> ();
}
if (i < length)
if (i < str_size)
{
return -1;
}
@@ -163,7 +165,7 @@ lit_charset_record_t::compare_zt (const ecma_char_t *str_to_compare_with, /**< b
* false otherwise
*/
bool
lit_charset_record_t::equal (lit_charset_record_t *rec) /**< charset record to compare with */
lit_charset_record_t::is_equal (lit_charset_record_t *rec) /**< charset record to compare with */
{
if (get_length () != rec->get_length ())
{
@@ -176,31 +178,19 @@ lit_charset_record_t::equal (lit_charset_record_t *rec) /**< charset record to c
it_this.skip (header_size ());
it_record.skip (rec->header_size ());
for (ecma_length_t i = 0; i < get_length (); i++)
for (lit_utf8_size_t i = 0; i < get_length (); i++)
{
if (it_this.read<ecma_char_t> () != it_record.read<ecma_char_t> ())
if (it_this.read<lit_utf8_byte_t> () != it_record.read<lit_utf8_byte_t> ())
{
return false;
}
it_this.skip<ecma_char_t> ();
it_record.skip<ecma_char_t> ();
it_this.skip<lit_utf8_byte_t> ();
it_record.skip<lit_utf8_byte_t> ();
}
return true;
} /* lit_charset_record_t::equal */
/**
* Compares this lit_charset_record_t records with zero-terminated string for equality
*
* @return true if compared instances are equal
* false otherwise
*/
bool
lit_charset_record_t::equal_zt (const ecma_char_t *str) /**< zero-terminated string */
{
return equal_non_zt (str, ecma_zt_string_length (str));
} /* lit_charset_record_t::equal_zt */
} /* lit_charset_record_t::is_equal */
/**
* Compare this lit_charset_record_t record with string (which could contain '\0' characters) for equality
@@ -209,24 +199,24 @@ lit_charset_record_t::equal_zt (const ecma_char_t *str) /**< zero-terminated str
* false otherwise
*/
bool
lit_charset_record_t::equal_non_zt (const ecma_char_t *str, /**< string to compare with */
ecma_length_t len) /**< length of the string */
lit_charset_record_t::is_equal_utf8_string (const lit_utf8_byte_t *str, /**< string to compare with */
lit_utf8_size_t str_size) /**< length of the string */
{
rcs_record_iterator_t it_this (&lit_storage, this);
it_this.skip (header_size ());
for (ecma_length_t i = 0; i < get_length () && i < len; i++)
for (lit_utf8_size_t i = 0; i < get_length () && i < str_size; i++)
{
if (it_this.read<ecma_char_t> () != str[i])
if (it_this.read<lit_utf8_byte_t> () != str[i])
{
return false;
}
it_this.skip<ecma_char_t> ();
it_this.skip<lit_utf8_byte_t> ();
}
return get_length () == len;
return get_length () == str_size;
} /* lit_charset_record_t::equal_non_zt */
/**
@@ -235,9 +225,9 @@ lit_charset_record_t::equal_non_zt (const ecma_char_t *str, /**< string to compa
* @return pointer to the created record
*/
lit_charset_record_t *
lit_literal_storage_t::create_charset_record (const ecma_char_t *str, /**< string to be placed in the record */
size_t buf_size) /**< size in bytes of the buffer which holds the
* string */
lit_literal_storage_t::create_charset_record (const lit_utf8_byte_t *str, /**< string to be placed in the record */
lit_utf8_size_t buf_size) /**< size in bytes of the buffer which holds the
* string */
{
const size_t alignment = lit_charset_record_t::size (buf_size) - (lit_charset_record_t::header_size () + buf_size);
@@ -245,7 +235,7 @@ lit_literal_storage_t::create_charset_record (const ecma_char_t *str, /**< strin
ret->set_alignment_bytes_count (alignment);
ret->set_charset (str, buf_size);
ret->set_hash (ecma_chars_buffer_calc_hash_last_chars (str, ret->get_length ()));
ret->set_hash (lit_utf8_string_calc_hash_last_bytes (str, ret->get_length ()));
return ret;
} /* lit_literal_storage_t::create_charset_record */
@@ -319,8 +309,9 @@ lit_literal_storage_t::dump ()
for (size_t i = 0; i < lit_p->get_length (); ++i)
{
printf ("%c", it_this.read<ecma_char_t> ());
it_this.skip<ecma_char_t> ();
FIXME ("Support proper printing of characters which occupy more than one byte.")
printf ("%c", it_this.read<lit_utf8_byte_t> ());
it_this.skip<lit_utf8_byte_t> ();
}
printf (" : STRING");
@@ -330,7 +321,7 @@ lit_literal_storage_t::dump ()
case LIT_MAGIC_STR:
{
lit_magic_string_id_t id = lit_magic_record_get_magic_str_id (rec_p);
printf ("%s : MAGIC STRING", lit_get_magic_string_zt (id));
printf ("%s : MAGIC STRING", lit_get_magic_string_utf8 (id));
printf (" [id=%d] ", id);
break;
@@ -338,7 +329,7 @@ lit_literal_storage_t::dump ()
case LIT_MAGIC_STR_EX:
{
lit_magic_string_ex_id_t id = lit_magic_record_ex_get_magic_str_id (rec_p);
printf ("%s : EXT MAGIC STRING", lit_get_magic_string_ex_zt (id));
printf ("%s : EXT MAGIC STRING", lit_get_magic_string_ex_utf8 (id));
printf (" [id=%d] ", id);
break;
@@ -353,8 +344,8 @@ lit_literal_storage_t::dump ()
}
else
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_zt_string (lit_p->get_number (), buff, ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_utf8_string (lit_p->get_number (), buff, sizeof (buff));
printf ("%s : NUMBER", buff);
}
@@ -465,12 +456,12 @@ lit_literal_storage_t::get_record_size (rcs_record_t* rec_p) /**< pointer to a r
}
} /* lit_literal_storage_t::get_record_size */
template void rcs_record_iterator_t::skip<ecma_char_t> ();
template void rcs_record_iterator_t::skip<uint8_t> ();
template void rcs_record_iterator_t::skip<uint16_t> ();
template void rcs_record_iterator_t::skip<uint32_t> ();
template void rcs_record_iterator_t::write<ecma_char_t> (ecma_char_t);
template ecma_char_t rcs_record_iterator_t::read<ecma_char_t> ();
template void rcs_record_iterator_t::write<uint8_t> (uint8_t);
template uint8_t rcs_record_iterator_t::read<uint8_t> ();
template void rcs_record_iterator_t::write<ecma_number_t> (ecma_number_t);
template ecma_number_t rcs_record_iterator_t::read<ecma_number_t> ();
+11 -12
View File
@@ -106,12 +106,12 @@ public:
/**
* Get the length of the string, which is contained inside the record
*
* @return length of the string (count of the ecma_char_t characters inside the charset)
* @return length of the string (bytes count)
*/
ecma_length_t
lit_utf8_size_t
get_length () const
{
return (ecma_length_t) ((get_size () - header_size () - get_alignment_bytes_count ()) / sizeof (ecma_char_t));
return (lit_utf8_size_t) (get_size () - header_size () - get_alignment_bytes_count ());
} /* get_length */
/**
@@ -127,12 +127,11 @@ public:
rcs_record_t *get_prev () const;
ecma_length_t get_charset (ecma_char_t *buff, size_t size);
lit_utf8_size_t get_charset (lit_utf8_byte_t *, size_t);
int compare_zt (const ecma_char_t *, size_t);
bool equal (lit_charset_record_t *);
bool equal_zt (const ecma_char_t *);
bool equal_non_zt (const ecma_char_t *, ecma_length_t);
int compare_utf8 (const lit_utf8_byte_t *, lit_utf8_size_t);
bool is_equal (lit_charset_record_t *);
bool is_equal_utf8_string (const lit_utf8_byte_t *, lit_utf8_size_t);
private:
/**
@@ -157,7 +156,7 @@ private:
void set_prev (rcs_record_t *);
void set_charset (const ecma_char_t *, size_t);
void set_charset (const lit_utf8_byte_t *, lit_utf8_size_t);
/**
* Offset and length of 'alignment' field, in bits
@@ -242,7 +241,6 @@ public:
magic_string_id_t get_magic_str_id () const
{
uint32_t id = get_field (magic_field_pos, magic_field_width);
// JERRY_ASSERT (id < LIT_MAGIC_STRING__COUNT);
return (magic_string_id_t) id;
} /* get_magic_str_id */
@@ -303,9 +301,10 @@ private:
* Layout:
* ------- header -----------------------
* type (4 bits)
* magic string id (12 bits)
* padding (12 bits)
* pointer to prev (16 bits)
* --------------------------------------
* ecma_number_t
*/
class lit_number_record_t : public rcs_record_t
{
@@ -417,7 +416,7 @@ public:
LIT_NUMBER
};
lit_charset_record_t *create_charset_record (const ecma_char_t *, size_t);
lit_charset_record_t *create_charset_record (const lit_utf8_byte_t *, lit_utf8_size_t);
lit_magic_record_t *create_magic_record (lit_magic_string_id_t);
lit_magic_record_t *create_magic_record_ex (lit_magic_string_ex_id_t);
lit_number_record_t *create_number_record (ecma_number_t);
+137 -82
View File
@@ -14,7 +14,9 @@
*/
#include "lit-literal.h"
#include "ecma-helpers.h"
#include "lit-magic-strings.h"
/**
* Initialize literal storage
@@ -54,43 +56,43 @@ lit_dump_literals ()
* @return pointer to created record
*/
literal_t
lit_create_literal_from_charset (const ecma_char_t *str, /**< string to initialize the record,
* could be non-zero-terminated */
ecma_length_t len) /**< length of the string */
lit_create_literal_from_utf8_string (const lit_utf8_byte_t *str_p, /**< string to initialize the record,
* could be non-zero-terminated */
lit_utf8_size_t str_size) /**< length of the string */
{
JERRY_ASSERT (str || !len);
JERRY_ASSERT (str_p || !str_size);
for (lit_magic_string_id_t msi = (lit_magic_string_id_t) 0;
msi < LIT_MAGIC_STRING__COUNT;
msi = (lit_magic_string_id_t) (msi + 1))
{
if (ecma_zt_string_length (lit_get_magic_string_zt (msi)) != len)
if (lit_get_magic_string_size (msi) != str_size)
{
continue;
}
if (!strncmp ((const char *) str, (const char *) lit_get_magic_string_zt (msi), len))
if (!strncmp ((const char *) str_p, (const char *) lit_get_magic_string_utf8 (msi), str_size))
{
return lit_storage.create_magic_record (msi);
}
}
for (lit_magic_string_ex_id_t msi = (lit_magic_string_ex_id_t) 0;
msi < ecma_get_magic_string_ex_count ();
msi < lit_get_magic_string_ex_count ();
msi = (lit_magic_string_ex_id_t) (msi + 1))
{
if (ecma_zt_string_length (lit_get_magic_string_ex_zt (msi)) != len)
if (lit_get_magic_string_ex_size (msi) != str_size)
{
continue;
}
if (!strncmp ((const char *) str, (const char *) lit_get_magic_string_ex_zt (msi), len))
if (!strncmp ((const char *) str_p, (const char *) lit_get_magic_string_ex_utf8 (msi), str_size))
{
return lit_storage.create_magic_record_ex (msi);
}
}
return lit_storage.create_charset_record (str, len * sizeof (ecma_char_t));
} /* lit_create_literal_from_charset */
return lit_storage.create_charset_record (str_p, str_size);
} /* lit_create_literal_from_utf8_string */
/**
* Find a literal in literal storage.
@@ -99,22 +101,22 @@ lit_create_literal_from_charset (const ecma_char_t *str, /**< string to initiali
* @return pointer to a literal or NULL if no corresponding literal exists
*/
literal_t
lit_find_literal_by_charset (const ecma_char_t *str, /**< a string to search for */
ecma_length_t len) /**< length of the string */
lit_find_literal_by_utf8_string (const lit_utf8_byte_t *str_p, /**< a string to search for */
lit_utf8_size_t str_size) /**< length of the string */
{
JERRY_ASSERT (str || !len);
JERRY_ASSERT (str_p || !str_size);
for (literal_t lit = lit_storage.get_first (); lit != NULL; lit = lit_storage.get_next (lit))
{
rcs_record_t::type_t type = lit->get_type ();
if (type == LIT_STR_T)
{
if (static_cast<lit_charset_record_t *>(lit)->get_length () != len)
if (static_cast<lit_charset_record_t *>(lit)->get_length () != str_size)
{
continue;
}
if (!static_cast<lit_charset_record_t *>(lit)->compare_zt (str, len))
if (!static_cast<lit_charset_record_t *>(lit)->compare_utf8 (str_p, str_size))
{
return lit;
}
@@ -122,14 +124,14 @@ lit_find_literal_by_charset (const ecma_char_t *str, /**< a string to search for
else if (type == LIT_MAGIC_STR_T)
{
lit_magic_string_id_t magic_id = lit_magic_record_get_magic_str_id (lit);
const char *magic_str = (const char *) lit_get_magic_string_zt (magic_id);
const lit_utf8_byte_t *magic_str_p = lit_get_magic_string_utf8 (magic_id);
if (strlen (magic_str) != len)
if (lit_zt_utf8_string_size (magic_str_p) != str_size)
{
continue;
}
if (!strncmp (magic_str, (const char *) str, strlen (magic_str)))
if (!strncmp ((const char *) magic_str_p, (const char *) str_p, str_size))
{
return lit;
}
@@ -137,14 +139,14 @@ lit_find_literal_by_charset (const ecma_char_t *str, /**< a string to search for
else if (type == LIT_MAGIC_STR_EX_T)
{
lit_magic_string_ex_id_t magic_id = lit_magic_record_ex_get_magic_str_id (lit);
const char *magic_str = (const char *) lit_get_magic_string_ex_zt (magic_id);
const lit_utf8_byte_t *magic_str_p = lit_get_magic_string_ex_utf8 (magic_id);
if (strlen (magic_str) != len)
if (lit_zt_utf8_string_size (magic_str_p) != str_size)
{
continue;
}
if (!strncmp (magic_str, (const char *) str, strlen (magic_str)))
if (!strncmp ((const char *) magic_str_p, (const char *) str_p, str_size))
{
return lit;
}
@@ -152,7 +154,7 @@ lit_find_literal_by_charset (const ecma_char_t *str, /**< a string to search for
}
return NULL;
} /* lit_find_literal_by_charset */
} /* lit_find_literal_by_utf8_string */
/**
* Check if a literal which holds the passed string exists.
@@ -161,18 +163,18 @@ lit_find_literal_by_charset (const ecma_char_t *str, /**< a string to search for
* @return pointer to existing or newly created record
*/
literal_t
lit_find_or_create_literal_from_charset (const ecma_char_t *str, /**< string, could be non-zero-terminated */
ecma_length_t len) /**< length of the string */
lit_find_or_create_literal_from_utf8_string (const lit_utf8_byte_t *str_p, /**< string, could be non-zero-terminated */
lit_utf8_size_t str_size) /**< length of the string */
{
literal_t lit = lit_find_literal_by_charset (str, len);
literal_t lit = lit_find_literal_by_utf8_string (str_p, str_size);
if (lit == NULL)
{
lit = lit_create_literal_from_charset (str, len);
lit = lit_create_literal_from_utf8_string (str_p, str_size);
}
return lit;
} /* lit_find_or_create_literal_from_s */
} /* lit_find_or_create_literal_from_utf8_string */
/**
@@ -235,7 +237,7 @@ lit_find_literal_by_num (ecma_number_t num) /**< a number to search for */
/**
* Check if literal equals to charset record
*
* @return true if equal
* @return true if is_equal
* false otherwise
*/
static bool
@@ -246,24 +248,28 @@ lit_literal_equal_charset_rec (literal_t lit, /**< literal to com
{
case LIT_STR_T:
{
return static_cast<lit_charset_record_t *>(lit)->equal (record);
return static_cast<lit_charset_record_t *>(lit)->is_equal (record);
}
case LIT_MAGIC_STR_T:
{
return record->equal_zt (lit_get_magic_string_zt (lit_magic_record_get_magic_str_id (lit)));
lit_magic_string_id_t magic_string_id = lit_magic_record_get_magic_str_id (lit);
return record->is_equal_utf8_string (lit_get_magic_string_utf8 (magic_string_id),
lit_get_magic_string_size (magic_string_id));
}
case LIT_MAGIC_STR_EX_T:
{
return record->equal_zt (lit_get_magic_string_ex_zt (lit_magic_record_ex_get_magic_str_id (lit)));
lit_magic_string_ex_id_t magic_string_id = lit_magic_record_ex_get_magic_str_id (lit);
return record->is_equal_utf8_string (lit_get_magic_string_ex_utf8 (magic_string_id),
lit_get_magic_string_ex_size (magic_string_id));
}
case LIT_NUMBER_T:
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_zt_string (static_cast<lit_number_record_t *>(lit)->get_number (),
buff,
ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
lit_utf8_size_t copied = ecma_number_to_utf8_string (static_cast<lit_number_record_t *>(lit)->get_number (),
buff,
sizeof (buff));
return record->equal_zt (buff);
return record->is_equal_utf8_string (buff, copied);
}
default:
{
@@ -273,46 +279,47 @@ lit_literal_equal_charset_rec (literal_t lit, /**< literal to com
} /* lit_literal_equal_charset_rec */
/**
* Check if literal equals to zero-terminated string
* Check if literal equals to utf-8 string
*
* @return true if equal
* false otherwise
*/
bool
lit_literal_equal_zt (literal_t lit, /**< literal to compare */
const ecma_char_t *str) /**< zero-terminated string to compare */
lit_literal_equal_utf8 (literal_t lit, /**< literal to compare */
const lit_utf8_byte_t *str_p, /**< utf-8 string to compare */
lit_utf8_size_t str_size) /**< string size in bytes */
{
switch (lit->get_type ())
{
case LIT_STR_T:
{
return static_cast<lit_charset_record_t *>(lit)->equal_zt (str);
return static_cast<lit_charset_record_t *>(lit)->is_equal_utf8_string (str_p, str_size);
}
case LIT_MAGIC_STR_T:
{
lit_magic_string_id_t magic_id = lit_magic_record_get_magic_str_id (lit);
return ecma_compare_zt_strings (str, lit_get_magic_string_zt (magic_id));
return lit_compare_utf8_string_and_magic_string (str_p, str_size, magic_id);
}
case LIT_MAGIC_STR_EX_T:
{
lit_magic_string_ex_id_t magic_id = lit_magic_record_ex_get_magic_str_id (lit);
return ecma_compare_zt_strings (str, lit_get_magic_string_ex_zt (magic_id));
return lit_compare_utf8_string_and_magic_string_ex (str_p, str_size, magic_id);
}
case LIT_NUMBER_T:
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_zt_string (static_cast<lit_number_record_t *>(lit)->get_number (),
buff,
ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
lit_utf8_byte_t num_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
lit_utf8_size_t num_size = ecma_number_to_utf8_string (static_cast<lit_number_record_t *>(lit)->get_number (),
num_buf,
sizeof (num_buf));
return ecma_compare_zt_strings (str, buff);
return lit_compare_utf8_strings (str_p, str_size, num_buf, num_size);
}
default:
{
JERRY_UNREACHABLE ();
}
}
} /* lit_literal_equal_zt */
} /* lit_literal_equal_utf8 */
/**
* Check if literal contains the string equal to the passed number
@@ -324,10 +331,10 @@ bool
lit_literal_equal_num (literal_t lit, /**< literal to check */
ecma_number_t num) /**< number to compare with */
{
ecma_char_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
ecma_number_to_zt_string (num, buff, ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
lit_utf8_size_t copied = ecma_number_to_utf8_string (num, buff, sizeof (buff));
return lit_literal_equal_zt (lit, buff);
return lit_literal_equal_utf8 (lit, buff, copied);
} /* lit_literal_equal_num */
/**
@@ -348,11 +355,17 @@ lit_literal_equal (literal_t lit1, /**< first literal */
}
case lit_literal_storage_t::LIT_MAGIC_STR:
{
return lit_literal_equal_zt (lit1, lit_get_magic_string_zt (lit_magic_record_get_magic_str_id (lit2)));
lit_magic_string_id_t magic_str_id = lit_magic_record_get_magic_str_id (lit2);
return lit_literal_equal_utf8 (lit1,
lit_get_magic_string_utf8 (magic_str_id),
lit_get_magic_string_size (magic_str_id));
}
case lit_literal_storage_t::LIT_MAGIC_STR_EX:
{
return lit_literal_equal_zt (lit1, lit_get_magic_string_ex_zt (lit_magic_record_ex_get_magic_str_id (lit2)));
lit_magic_string_ex_id_t magic_str_ex_id = lit_magic_record_ex_get_magic_str_id (lit2);
return lit_literal_equal_utf8 (lit1,
lit_get_magic_string_ex_utf8 (magic_str_ex_id),
lit_get_magic_string_ex_size (magic_str_ex_id));
}
case lit_literal_storage_t::LIT_NUMBER:
{
@@ -366,15 +379,16 @@ lit_literal_equal (literal_t lit1, /**< first literal */
} /* lit_literal_equal */
/**
* Check if literal equals to zero-terminated string.
* Check if literal equals to utf-8 string.
* Check that literal is a string literal before performing detailed comparison.
*
* @return true if equal
* false otherwise
*/
bool
lit_literal_equal_type_zt (literal_t lit, /**< literal to compare */
const ecma_char_t *str) /**< zero-terminated string */
lit_literal_equal_type_utf8 (literal_t lit, /**< literal to compare */
const lit_utf8_byte_t *str_p, /**< utf-8 string */
lit_utf8_size_t str_size) /**< string size */
{
if (lit->get_type () != LIT_STR_T
&& lit->get_type () != LIT_MAGIC_STR_T
@@ -383,8 +397,22 @@ lit_literal_equal_type_zt (literal_t lit, /**< literal to compare */
return false;
}
return lit_literal_equal_zt (lit, str);
} /* lit_literal_equal_type_zt */
return lit_literal_equal_utf8 (lit, str_p, str_size);
} /* lit_literal_equal_type_utf8 */
/**
* Check if literal equals to C string.
* Check that literal is a string literal before performing detailed comparison.
*
* @return true if equal
* false otherwise
*/
bool
lit_literal_equal_type_cstr (literal_t lit, /**< literal to compare */
const char *c_str_p) /**< zero-terminated C-string */
{
return lit_literal_equal_type_utf8 (lit, (const lit_utf8_byte_t *) c_str_p, (lit_utf8_size_t) strlen (c_str_p));
} /* lit_literal_equal_type_cstr */
/**
* Check if literal contains the string equal to the passed number.
@@ -432,12 +460,12 @@ lit_literal_equal_type (literal_t lit1, /**< first literal */
*
* @return pointer to the zero-terminated string.
*/
const ecma_char_t *
lit_literal_to_charset (literal_t lit, /**< literal to be processed */
ecma_char_t *buff, /**< buffer to use as a string storage */
size_t size) /**< size of the buffer */
const lit_utf8_byte_t *
lit_literal_to_utf8_string (literal_t lit, /**< literal to be processed */
lit_utf8_byte_t *buff_p, /**< buffer to use as a string storage */
size_t size) /**< size of the buffer */
{
JERRY_ASSERT (buff != NULL && size > sizeof (ecma_char_t));
JERRY_ASSERT (buff_p != NULL && size > 0);
rcs_record_t::type_t type = lit->get_type ();
switch (type)
@@ -445,35 +473,28 @@ lit_literal_to_charset (literal_t lit, /**< literal to be processed */
case LIT_STR_T:
{
lit_charset_record_t *ch_rec_p = static_cast<lit_charset_record_t *> (lit);
ecma_length_t index = ch_rec_p->get_charset (buff, size);
if (index != 0 && ((size_t)index + 1) * sizeof (ecma_char_t) > size)
{
index--;
}
buff[index] = '\0';
return buff;
ch_rec_p->get_charset (buff_p, size);
return buff_p;
}
case LIT_MAGIC_STR_T:
{
return lit_get_magic_string_zt (lit_magic_record_get_magic_str_id (lit));
return lit_get_magic_string_utf8 (lit_magic_record_get_magic_str_id (lit));
}
case LIT_MAGIC_STR_EX_T:
{
return lit_get_magic_string_ex_zt (lit_magic_record_ex_get_magic_str_id (lit));
return lit_get_magic_string_ex_utf8 (lit_magic_record_ex_get_magic_str_id (lit));
}
case LIT_NUMBER_T:
{
ecma_number_to_zt_string (static_cast<lit_number_record_t *> (lit)->get_number (), buff, (ssize_t)size);
ecma_number_to_utf8_string (static_cast<lit_number_record_t *> (lit)->get_number (), buff_p, (ssize_t)size);
return buff;
return buff_p;
}
default: JERRY_UNREACHABLE ();
}
JERRY_UNREACHABLE ();
} /* lit_literal_to_charset */
} /* lit_literal_to_utf8_string */
/**
* Get the contents of the literal as a C string.
@@ -484,10 +505,10 @@ lit_literal_to_charset (literal_t lit, /**< literal to be processed */
const char *
lit_literal_to_str_internal_buf (literal_t lit) /**< literal */
{
const ecma_length_t buff_size = ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER;
static ecma_char_t buff[buff_size];
static lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1];
memset (buff, 0, sizeof (buff));
return (const char *)lit_literal_to_charset (lit, buff, buff_size);
return (const char *) lit_literal_to_utf8_string (lit, buff, sizeof (buff) - 1);
} /* lit_literal_to_str_internal_buf */
@@ -544,10 +565,44 @@ lit_magic_record_ex_get_magic_str_id (literal_t lit) /**< literal */
return static_cast<lit_magic_record_t *> (lit)->get_magic_str_id<lit_magic_string_ex_id_t> ();
} /* lit_magic_record_ex_get_magic_str_id */
lit_utf8_size_t
lit_charset_record_get_size (literal_t lit) /**< literal */
{
return static_cast<lit_charset_record_t *> (lit)->get_length ();
} /* lit_charset_record_get_size */
/**
* Get length of the literal
*
* @return code units count
*/
ecma_length_t
lit_charset_record_get_length (literal_t lit) /**< literal */
{
return static_cast<lit_charset_record_t *> (lit)->get_length ();;
TODO ("Add special case for literals which doesn't contain long characters");
lit_charset_record_t *charset_record_p = static_cast<lit_charset_record_t *> (lit);
rcs_record_iterator_t lit_iter (&lit_storage, lit);
lit_iter.skip (lit_charset_record_t::header_size ());
lit_utf8_size_t lit_utf8_str_size = charset_record_p->get_length ();
ecma_length_t length = 0;
for (lit_utf8_size_t i = 0; i < lit_utf8_str_size;)
{
lit_utf8_byte_t byte = lit_iter.read <lit_utf8_byte_t> ();
lit_utf8_size_t bytes_to_skip = lit_get_unicode_char_size_by_utf8_first_byte (byte);
lit_iter.skip (bytes_to_skip);
i += bytes_to_skip;
length++;
}
#ifndef JERRY_NDEBUG
lit_iter.skip (charset_record_p->get_alignment_bytes_count ());
JERRY_ASSERT (lit_iter.finished ());
#endif
return length;
} /* lit_charset_record_get_length */
ecma_number_t
+10 -8
View File
@@ -16,8 +16,9 @@
#ifndef LIT_LITERAL_H
#define LIT_LITERAL_H
#include "ecma-globals.h"
#include "lit-globals.h"
#include "lit-literal-storage.h"
#include "lit-magic-strings.h"
#define LITERAL_TO_REWRITE (INVALID_VALUE - 1)
@@ -25,30 +26,31 @@ void lit_init ();
void lit_finalize ();
void lit_dump_literals ();
literal_t lit_create_literal_from_charset (const ecma_char_t *, ecma_length_t);
literal_t lit_find_literal_by_charset (const ecma_char_t *, ecma_length_t);
literal_t lit_find_or_create_literal_from_charset (const ecma_char_t *, ecma_length_t);
literal_t lit_create_literal_from_utf8_string (const lit_utf8_byte_t *, lit_utf8_size_t);
literal_t lit_find_literal_by_utf8_string (const lit_utf8_byte_t *, lit_utf8_size_t);
literal_t lit_find_or_create_literal_from_utf8_string (const lit_utf8_byte_t *, lit_utf8_size_t);
literal_t lit_create_literal_from_num (ecma_number_t);
literal_t lit_find_literal_by_num (ecma_number_t);
literal_t lit_find_or_create_literal_from_num (ecma_number_t);
bool lit_literal_equal_zt (literal_t, const ecma_char_t *);
bool lit_literal_equal_utf8 (literal_t, const lit_utf8_byte_t *, lit_utf8_size_t);
bool lit_literal_equal_num (literal_t, ecma_number_t);
bool lit_literal_equal (literal_t, literal_t);
bool lit_literal_equal_type_zt (literal_t, const ecma_char_t *);
bool lit_literal_equal_type_utf8 (literal_t, const lit_utf8_byte_t *, lit_utf8_size_t);
bool lit_literal_equal_type_cstr (literal_t, const char *);
bool lit_literal_equal_type_num (literal_t, ecma_number_t);
bool lit_literal_equal_type (literal_t, literal_t);
const ecma_char_t *lit_literal_to_charset (literal_t, ecma_char_t *, size_t);
const lit_utf8_byte_t *lit_literal_to_utf8_string (literal_t, lit_utf8_byte_t *, size_t);
const char *lit_literal_to_str_internal_buf (literal_t);
literal_t lit_get_literal_by_cp (lit_cpointer_t);
lit_string_hash_t lit_charset_literal_get_hash (literal_t);
ecma_number_t lit_charset_literal_get_number (literal_t);
lit_utf8_size_t lit_charset_record_get_size (literal_t);
ecma_length_t lit_charset_record_get_length (literal_t);
lit_magic_string_id_t lit_magic_record_get_magic_str_id (literal_t);
+150 -86
View File
@@ -15,26 +15,26 @@
#include "lit-magic-strings.h"
#include "ecma-helpers.h"
#include "lit-strings.h"
/**
* Lengths of magic strings
*/
static ecma_length_t lit_magic_string_lengths[LIT_MAGIC_STRING__COUNT];
static lit_utf8_size_t lit_magic_string_sizes[LIT_MAGIC_STRING__COUNT];
/**
* External magic strings data array, count and lengths
*/
static const ecma_char_ptr_t *lit_magic_string_ex_array = NULL;
static const lit_utf8_byte_t **lit_magic_string_ex_array = NULL;
static uint32_t lit_magic_string_ex_count = 0;
static const ecma_length_t *lit_magic_string_ex_lengths = NULL;
static const lit_utf8_size_t *lit_magic_string_ex_sizes = NULL;
#ifndef JERRY_NDEBUG
/**
* Maximum length among lengths of magic strings
*/
static ecma_length_t lit_magic_string_max_length;
#endif /* !JERRY_NDEBUG */
static ecma_length_t ecma_magic_string_max_length;
#endif /* JERRY_NDEBUG */
/**
* Initialize data for string helpers
@@ -45,22 +45,22 @@ lit_magic_strings_init (void)
/* Initializing magic strings information */
#ifndef JERRY_NDEBUG
lit_magic_string_max_length = 0;
ecma_magic_string_max_length = 0;
#endif /* !JERRY_NDEBUG */
for (lit_magic_string_id_t id = (lit_magic_string_id_t) 0;
id < LIT_MAGIC_STRING__COUNT;
id = (lit_magic_string_id_t) (id + 1))
{
lit_magic_string_lengths[id] = ecma_zt_string_length (lit_get_magic_string_zt (id));
lit_magic_string_sizes[id] = lit_zt_utf8_string_size (lit_get_magic_string_utf8 (id));
#ifndef JERRY_NDEBUG
lit_magic_string_max_length = JERRY_MAX (lit_magic_string_max_length, lit_magic_string_lengths[id]);
ecma_magic_string_max_length = JERRY_MAX (ecma_magic_string_max_length, lit_magic_string_sizes[id]);
JERRY_ASSERT (lit_magic_string_max_length <= LIT_MAGIC_STRING_LENGTH_LIMIT);
JERRY_ASSERT (ecma_magic_string_max_length <= LIT_MAGIC_STRING_LENGTH_LIMIT);
#endif /* !JERRY_NDEBUG */
}
} /* ecma_strings_init */
} /* lit_magic_strings_init */
/**
* Initialize external magic strings
@@ -70,44 +70,8 @@ lit_magic_strings_ex_init (void)
{
lit_magic_string_ex_array = NULL;
lit_magic_string_ex_count = 0;
lit_magic_string_ex_lengths = NULL;
} /* ecma_strings_ex_init */
/**
* Register external magic strings
*/
void
lit_magic_strings_ex_set (const ecma_char_ptr_t* ex_str_items, /**< character arrays, representing
* external magic strings' contents */
uint32_t count, /**< number of the strings */
const ecma_length_t* ex_str_lengths) /**< lengths of the strings */
{
JERRY_ASSERT (ex_str_items != NULL);
JERRY_ASSERT (count > 0);
JERRY_ASSERT (ex_str_lengths != NULL);
JERRY_ASSERT (lit_magic_string_ex_array == NULL);
JERRY_ASSERT (lit_magic_string_ex_count == 0);
JERRY_ASSERT (lit_magic_string_ex_lengths == NULL);
/* Set external magic strings information */
lit_magic_string_ex_array = ex_str_items;
lit_magic_string_ex_count = count;
lit_magic_string_ex_lengths = ex_str_lengths;
#ifndef JERRY_NDEBUG
for (lit_magic_string_ex_id_t id = (lit_magic_string_ex_id_t) 0;
id < lit_magic_string_ex_count;
id = (lit_magic_string_ex_id_t) (id + 1))
{
JERRY_ASSERT (lit_magic_string_ex_lengths[id] == ecma_zt_string_length (lit_get_magic_string_ex_zt (id)));
lit_magic_string_max_length = JERRY_MAX (lit_magic_string_max_length, lit_magic_string_ex_lengths[id]);
JERRY_ASSERT (lit_magic_string_max_length <= LIT_MAGIC_STRING_LENGTH_LIMIT);
}
#endif /* !JERRY_NDEBUG */
} /* ecma_strings_ex_init */
lit_magic_string_ex_sizes = NULL;
} /* lit_magic_strings_ex_init */
/**
* Get number of external magic strings
@@ -116,25 +80,23 @@ lit_magic_strings_ex_set (const ecma_char_ptr_t* ex_str_items, /**< character ar
* zero - otherwise.
*/
uint32_t
ecma_get_magic_string_ex_count (void)
lit_get_magic_string_ex_count (void)
{
return lit_magic_string_ex_count;
} /* ecma_get_magic_string_ex_count */
} /* lit_get_magic_string_ex_count */
/**
* Get specified magic string as zero-terminated string
*
* @return pointer to zero-terminated magic string
*/
const ecma_char_t *
lit_get_magic_string_zt (lit_magic_string_id_t id) /**< magic string id */
const lit_utf8_byte_t *
lit_get_magic_string_utf8 (lit_magic_string_id_t id) /**< magic string id */
{
TODO (Support UTF-16);
switch (id)
{
#define LIT_MAGIC_STRING_DEF(id, ascii_zt_string) \
case id: return (ecma_char_t*) ascii_zt_string;
#define LIT_MAGIC_STRING_DEF(id, utf8_string) \
case id: return (lit_utf8_byte_t*) utf8_string;
#include "lit-magic-strings.inc.h"
#undef LIT_MAGIC_STRING_DEF
@@ -142,58 +104,94 @@ lit_get_magic_string_zt (lit_magic_string_id_t id) /**< magic string id */
}
JERRY_UNREACHABLE ();
} /* lit_get_magic_string_zt */
} /* lit_get_magic_string_utf8 */
/**
* Get length of specified magic string
* Get size of specified magic string
*
* @return length
* @return size in bytes
*/
ecma_length_t
lit_get_magic_string_length (lit_magic_string_id_t id) /**< magic string id */
lit_utf8_size_t
lit_get_magic_string_size (lit_magic_string_id_t id) /**< magic string id */
{
return lit_magic_string_lengths[id];
} /* ecma_get_magic_string_size */
return lit_magic_string_sizes[id];
} /* lit_get_magic_string_size */
/**
* Get specified magic string as zero-terminated string from external table
*
* @return pointer to zero-terminated magic string
*/
const ecma_char_t*
lit_get_magic_string_ex_zt (lit_magic_string_ex_id_t id) /**< extern magic string id */
const lit_utf8_byte_t *
lit_get_magic_string_ex_utf8 (lit_magic_string_ex_id_t id) /**< extern magic string id */
{
TODO (Support UTF-16);
if (lit_magic_string_ex_array && id < lit_magic_string_ex_count)
{
return lit_magic_string_ex_array[id];
}
JERRY_UNREACHABLE ();
} /* lit_get_magic_string_ex_zt */
} /* lit_get_magic_string_ex_utf8 */
/**
* Get length of specified external magic string
* Get size of specified external magic string
*
* @return length
* @return size in bytes
*/
ecma_length_t
lit_get_magic_string_ex_length (lit_magic_string_ex_id_t id) /**< external magic string id */
lit_utf8_size_t
lit_get_magic_string_ex_size (lit_magic_string_ex_id_t id) /**< external magic string id */
{
return lit_magic_string_ex_lengths[id];
} /* lit_get_magic_string_ex_length */
return lit_magic_string_ex_sizes[id];
} /* lit_get_magic_string_ex_size */
/**
* Check if passed zt-string equals to one of magic strings
* Register external magic strings
*/
void
lit_magic_strings_ex_set (const lit_utf8_byte_t **ex_str_items, /**< character arrays, representing
* external magic strings' contents */
uint32_t count, /**< number of the strings */
const lit_utf8_size_t *ex_str_sizes) /**< sizes of the strings */
{
JERRY_ASSERT (ex_str_items != NULL);
JERRY_ASSERT (count > 0);
JERRY_ASSERT (ex_str_sizes != NULL);
JERRY_ASSERT (lit_magic_string_ex_array == NULL);
JERRY_ASSERT (lit_magic_string_ex_count == 0);
JERRY_ASSERT (lit_magic_string_ex_sizes == NULL);
/* Set external magic strings information */
lit_magic_string_ex_array = ex_str_items;
lit_magic_string_ex_count = count;
lit_magic_string_ex_sizes = ex_str_sizes;
#ifndef JERRY_NDEBUG
for (lit_magic_string_ex_id_t id = (lit_magic_string_ex_id_t) 0;
id < lit_magic_string_ex_count;
id = (lit_magic_string_ex_id_t) (id + 1))
{
JERRY_ASSERT (lit_magic_string_ex_sizes[id] == lit_zt_utf8_string_size (lit_get_magic_string_ex_utf8 (id)));
ecma_magic_string_max_length = JERRY_MAX (ecma_magic_string_max_length, lit_magic_string_ex_sizes[id]);
JERRY_ASSERT (ecma_magic_string_max_length <= LIT_MAGIC_STRING_LENGTH_LIMIT);
}
#endif /* !JERRY_NDEBUG */
} /* lit_magic_strings_ex_set */
/**
* Check if passed utf-8 string equals to one of magic strings
* and if equal magic string was found, return it's id in 'out_id_p' argument.
*
* @return true - if magic string equal to passed string was found,
* false - otherwise.
*/
bool
lit_is_zt_string_magic (const ecma_char_t *zt_string_p, /**< zero-terminated string */
lit_magic_string_id_t *out_id_p) /**< out: magic string's id */
lit_is_utf8_string_magic (const lit_utf8_byte_t *string_p, /**< utf-8 string */
lit_utf8_size_t string_size, /**< string size in bytes */
lit_magic_string_id_t *out_id_p) /**< out: magic string's id */
{
TODO (Improve performance of search);
@@ -201,7 +199,7 @@ lit_is_zt_string_magic (const ecma_char_t *zt_string_p, /**< zero-terminated str
id < LIT_MAGIC_STRING__COUNT;
id = (lit_magic_string_id_t) (id + 1))
{
if (ecma_compare_zt_strings (zt_string_p, lit_get_magic_string_zt (id)))
if (lit_compare_utf8_string_and_magic_string (string_p, string_size, id))
{
*out_id_p = id;
@@ -212,18 +210,18 @@ lit_is_zt_string_magic (const ecma_char_t *zt_string_p, /**< zero-terminated str
*out_id_p = LIT_MAGIC_STRING__COUNT;
return false;
} /* lit_is_zt_string_magic */
} /* lit_is_utf8_string_magic */
/**
* Check if passed zt-string equals to one of external magic strings
* Check if passed utf-8 string equals to one of external magic strings
* and if equal magic string was found, return it's id in 'out_id_p' argument.
*
* @return true - if external magic string equal to passed string was found,
* false - otherwise.
*/
bool
lit_is_zt_ex_string_magic (const ecma_char_t *zt_string_p, /**< zero-terminated string */
lit_magic_string_ex_id_t *out_id_p) /**< out: external magic string's id */
bool lit_is_ex_utf8_string_magic (const lit_utf8_byte_t *string_p, /**< utf-8 string */
lit_utf8_size_t string_size, /**< string size in bytes */
lit_magic_string_ex_id_t *out_id_p) /**< out: magic string's id */
{
TODO (Improve performance of search);
@@ -231,7 +229,7 @@ lit_is_zt_ex_string_magic (const ecma_char_t *zt_string_p, /**< zero-terminated
id < lit_magic_string_ex_count;
id = (lit_magic_string_ex_id_t) (id + 1))
{
if (ecma_compare_zt_strings (zt_string_p, lit_get_magic_string_ex_zt (id)))
if (lit_compare_utf8_string_and_magic_string_ex (string_p, string_size, id))
{
*out_id_p = id;
@@ -242,4 +240,70 @@ lit_is_zt_ex_string_magic (const ecma_char_t *zt_string_p, /**< zero-terminated
*out_id_p = lit_magic_string_ex_count;
return false;
} /* lit_is_zt_ex_string_magic */
} /* lit_is_ex_utf8_string_magic */
/**
* Compare utf-8 string and magic string for equality
*
* @return true if strings are equal
* false otherwise
*/
bool
lit_compare_utf8_string_and_magic_string (const lit_utf8_byte_t *string_p, /**< utf-8 string */
lit_utf8_size_t string_size, /**< string size in bytes */
lit_magic_string_id_t magic_string_id) /**< magic string's id */
{
return lit_compare_utf8_strings (string_p,
string_size,
lit_get_magic_string_utf8 (magic_string_id),
lit_get_magic_string_size (magic_string_id));
} /* lit_compare_utf8_string_and_magic_string */
/**
* Compare utf-8 string and external magic string for equality
*
* @return true if strings are equal
* false otherwise
*/
bool
lit_compare_utf8_string_and_magic_string_ex (const lit_utf8_byte_t *string_p, /**< utf-8 string */
lit_utf8_size_t string_size, /**< string size in bytes */
lit_magic_string_ex_id_t magic_string_ex_id) /**< external magic string's
* id */
{
return lit_compare_utf8_strings (string_p,
string_size,
lit_get_magic_string_ex_utf8 (magic_string_ex_id),
lit_get_magic_string_ex_size (magic_string_ex_id));
} /* lit_compare_utf8_string_and_magic_string_ex */
/**
* Copy magic string to buffer
*
* Warning:
* the routine requires that buffer size is enough
*
* @return pointer to the byte next to the last copied in the buffer
*/
extern lit_utf8_byte_t *
lit_copy_magic_string_to_buffer (lit_magic_string_id_t id, /**< magic string id */
lit_utf8_byte_t *buffer_p, /**< destination buffer */
ssize_t buffer_size) /**< size of buffer */
{
const lit_utf8_byte_t *magic_string_bytes_p = lit_get_magic_string_utf8 (id);
lit_utf8_size_t magic_string_bytes_count = lit_get_magic_string_size (id);
const lit_utf8_byte_t *str_iter_p = magic_string_bytes_p;
lit_utf8_byte_t *buf_iter_p = buffer_p;
ssize_t bytes_copied = 0;
while (magic_string_bytes_count--)
{
bytes_copied ++;
JERRY_ASSERT (bytes_copied <= buffer_size);
*buf_iter_p++ = *str_iter_p++;
}
return buf_iter_p;
} /* lit_copy_magic_string_to_buffer */
+27 -10
View File
@@ -44,18 +44,35 @@ typedef uint32_t lit_magic_string_ex_id_t;
extern void lit_magic_strings_init (void);
extern void lit_magic_strings_ex_init (void);
extern void lit_magic_strings_ex_set (const ecma_char_ptr_t *,
uint32_t,
const ecma_length_t *);
extern uint32_t ecma_get_magic_string_ex_count (void);
extern uint32_t lit_get_magic_string_ex_count (void);
extern const ecma_char_t *lit_get_magic_string_zt (lit_magic_string_id_t);
extern ecma_length_t lit_get_magic_string_length (lit_magic_string_id_t);
extern const lit_utf8_byte_t *lit_get_magic_string_utf8 (lit_magic_string_id_t);
extern lit_utf8_size_t lit_get_magic_string_size (lit_magic_string_id_t);
extern const ecma_char_t *lit_get_magic_string_ex_zt (lit_magic_string_ex_id_t);
extern ecma_length_t lit_get_magic_string_ex_length (lit_magic_string_ex_id_t);
extern const lit_utf8_byte_t *lit_get_magic_string_ex_utf8 (lit_magic_string_ex_id_t);
extern lit_utf8_size_t lit_get_magic_string_ex_size (lit_magic_string_ex_id_t);
extern bool lit_is_zt_string_magic (const ecma_char_t *, lit_magic_string_id_t *);
extern bool lit_is_zt_ex_string_magic (const ecma_char_t *, lit_magic_string_ex_id_t *);
extern void lit_magic_strings_ex_set (const lit_utf8_byte_t **,
uint32_t count,
const lit_utf8_size_t *);
extern bool lit_is_utf8_string_magic (const lit_utf8_byte_t *,
lit_utf8_size_t,
lit_magic_string_id_t *);
extern bool lit_is_ex_utf8_string_magic (const lit_utf8_byte_t *,
lit_utf8_size_t,
lit_magic_string_ex_id_t *);
extern bool lit_compare_utf8_string_and_magic_string (const lit_utf8_byte_t *,
lit_utf8_size_t,
lit_magic_string_id_t);
extern bool lit_compare_utf8_string_and_magic_string_ex (const lit_utf8_byte_t *,
lit_utf8_size_t,
lit_magic_string_ex_id_t);
extern lit_utf8_byte_t *lit_copy_magic_string_to_buffer (lit_magic_string_id_t,
lit_utf8_byte_t *buffer_p,
ssize_t buffer_size);
#endif /* LIT_MAGIC_STRINGS_H */
+579
View File
@@ -0,0 +1,579 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* 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.
*/
#include "lit-strings.h"
#include "jrt-libc-includes.h"
/**
* For the formal definition of Unicode transformation formats (UTF) see Section 3.9, Unicode Encoding Forms in The
* Unicode Standard (http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G7404, tables 3-6, 3-7).
*/
#define LIT_UNICODE_CODE_POINT_NULL (0x0)
#define LIT_UNICODE_CODE_POINT_MAX (0x10FFFF)
#define LIT_UTF16_CODE_UNIT_MAX (0xFFFF)
#define LIT_UTF16_FIRST_SURROGATE_CODE_POINT (0x10000)
#define LIT_UTF16_LOW_SURROGATE_MARKER (0xDC00)
#define LIT_UTF16_HIGH_SURROGATE_MARKER (0xD800)
#define LIT_UTF16_HIGH_SURROGATE_MIN (0xD800)
#define LIT_UTF16_HIGH_SURROGATE_MAX (0xDBFF)
#define LIT_UTF16_LOW_SURROGATE_MIN (0xDC00)
#define LIT_UTF16_LOW_SURROGATE_MAX (0xDFFF)
#define LIT_UTF16_BITS_IN_SURROGATE (10)
#define LIT_UTF16_LAST_10_BITS_MASK (0x3FF)
#define LIT_UTF8_1_BYTE_MARKER (0x00)
#define LIT_UTF8_2_BYTE_MARKER (0xC0)
#define LIT_UTF8_3_BYTE_MARKER (0xE0)
#define LIT_UTF8_4_BYTE_MARKER (0xF0)
#define LIT_UTF8_EXTRA_BYTE_MARKER (0x80)
#define LIT_UTF8_1_BYTE_MASK (0x80)
#define LIT_UTF8_2_BYTE_MASK (0xE0)
#define LIT_UTF8_3_BYTE_MASK (0xF0)
#define LIT_UTF8_4_BYTE_MASK (0xF8)
#define LIT_UTF8_EXTRA_BYTE_MASK (0xC0)
#define LIT_UTF8_LAST_7_BITS_MASK (0x7F)
#define LIT_UTF8_LAST_6_BITS_MASK (0x3F)
#define LIT_UTF8_LAST_5_BITS_MASK (0x1F)
#define LIT_UTF8_LAST_4_BITS_MASK (0x0F)
#define LIT_UTF8_LAST_3_BITS_MASK (0x07)
#define LIT_UTF8_LAST_2_BITS_MASK (0x03)
#define LIT_UTF8_LAST_1_BIT_MASK (0x01)
#define LIT_UTF8_BITS_IN_EXTRA_BYTES (6)
#define LIT_UTF8_1_BYTE_CODE_POINT_MAX (0x7F)
#define LIT_UTF8_2_BYTE_CODE_POINT_MIN (0x80)
#define LIT_UTF8_2_BYTE_CODE_POINT_MAX (0x7FF)
#define LIT_UTF8_3_BYTE_CODE_POINT_MIN (0x800)
#define LIT_UTF8_3_BYTE_CODE_POINT_MAX (LIT_UTF16_CODE_UNIT_MAX)
#define LIT_UTF8_4_BYTE_CODE_POINT_MIN (0x1000)
#define LIT_UTF8_4_BYTE_CODE_POINT_MAX (LIT_UNICODE_CODE_POINT_MAX)
/**
* Validate utf-8 string
*
* NOTE:
* Isolated surrogates are allowed.
* Correct pair of surrogates is not allowed, it should be represented as 4-byte utf-8 character.
*
* @return true if utf-8 string is well-formed
* false otherwise
*/
bool
lit_is_utf8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */
lit_utf8_size_t buf_size) /**< string size */
{
lit_utf8_size_t idx = 0;
bool is_prev_code_point_high_surrogate = false;
while (idx < buf_size)
{
lit_utf8_byte_t c = utf8_buf_p[idx++];
if ((c & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER)
{
continue;
}
lit_code_point_t code_point = 0;
lit_code_point_t min_code_point = 0;
lit_utf8_size_t extra_bytes_count;
if ((c & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER)
{
extra_bytes_count = 1;
min_code_point = LIT_UTF8_2_BYTE_CODE_POINT_MIN;
code_point = ((uint32_t) (c & LIT_UTF8_LAST_5_BITS_MASK));
}
else if ((c & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER)
{
extra_bytes_count = 2;
min_code_point = LIT_UTF8_3_BYTE_CODE_POINT_MIN;
code_point = ((uint32_t) (c & LIT_UTF8_LAST_4_BITS_MASK));
}
else if ((c & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER)
{
extra_bytes_count = 3;
min_code_point = LIT_UTF8_4_BYTE_CODE_POINT_MIN;
code_point = ((uint32_t) (c & LIT_UTF8_LAST_3_BITS_MASK));
}
else
{
/* utf-8 string could not contain 5- and 6-byte sequences. */
return false;
}
if (idx + extra_bytes_count > buf_size)
{
/* utf-8 string breaks in the middle */
return false;
}
for (lit_utf8_size_t offset = 0; offset < extra_bytes_count; ++offset)
{
c = utf8_buf_p[idx + offset];
if ((c & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER)
{
/* invalid continuation byte */
return false;
}
code_point <<= LIT_UTF8_BITS_IN_EXTRA_BYTES;
code_point |= (c & LIT_UTF8_LAST_6_BITS_MASK);
}
if (code_point < min_code_point
|| code_point > LIT_UNICODE_CODE_POINT_MAX)
{
/* utf-8 string doesn't encode valid unicode code point */
return false;
}
if (code_point >= LIT_UTF16_HIGH_SURROGATE_MIN
&& code_point <= LIT_UTF16_HIGH_SURROGATE_MAX)
{
is_prev_code_point_high_surrogate = true;
}
else if (code_point >= LIT_UTF16_LOW_SURROGATE_MIN
&& code_point <= LIT_UTF16_LOW_SURROGATE_MAX
&& is_prev_code_point_high_surrogate)
{
/* sequence of high and low surrogate is not allowed */
return false;
}
else
{
is_prev_code_point_high_surrogate = false;
}
idx += extra_bytes_count;
}
return true;
} /* lit_is_utf8_string_valid */
/**
* Initialize iterator for traversing utf-8 string as a string of code units
*
* @return iterator
*/
lit_utf8_iterator_t
lit_utf8_iterator_create (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */
lit_utf8_size_t buf_size) /**< string size */
{
JERRY_ASSERT (utf8_buf_p || !buf_size);
lit_utf8_iterator_t buf_iter =
{
0,
buf_size,
utf8_buf_p,
0,
};
return buf_iter;
} /* lit_utf8_iterator_create */
/**
* Represents code point (>0xFFFF) as surrogate pair and returns its lower part
*
* @return lower code_unit of the surrogate pair
*/
static ecma_char_t
convert_code_point_to_low_surrogate (lit_code_point_t code_point) /**< code point, should be > 0xFFFF */
{
JERRY_ASSERT (code_point > LIT_UTF16_CODE_UNIT_MAX);
ecma_char_t code_unit_bits;
code_unit_bits = (ecma_char_t) (code_point & LIT_UTF16_LAST_10_BITS_MASK);
return (ecma_char_t) (LIT_UTF16_LOW_SURROGATE_MARKER | code_unit_bits);
} /* convert_code_point_to_low_surrogate */
/**
* Represents code point (>0xFFFF) as surrogate pair and returns its higher part
*
* @return higher code_unit of the surrogate pair
*/
static ecma_char_t
convert_code_point_to_high_surrogate (lit_code_point_t code_point) /**< code point, should be > 0xFFFF */
{
JERRY_ASSERT (code_point > LIT_UTF16_CODE_UNIT_MAX);
JERRY_ASSERT (code_point <= LIT_UNICODE_CODE_POINT_MAX);
ecma_char_t code_unit_bits;
code_unit_bits = (ecma_char_t) ((code_point - LIT_UTF16_FIRST_SURROGATE_CODE_POINT) >> LIT_UTF16_BITS_IN_SURROGATE);
return (LIT_UTF16_HIGH_SURROGATE_MARKER | code_unit_bits);
} /* convert_code_point_to_low_surrogate */
/**
* Get next code unit form the iterated string and increment iterator to point to next code unit
*
* @return next code unit
*/
ecma_char_t
lit_utf8_iterator_read_code_unit_and_increment (lit_utf8_iterator_t *buf_iter_p) /**< @in-out: utf-8 string iterator */
{
JERRY_ASSERT (!lit_utf8_iterator_reached_buffer_end (buf_iter_p));
if (buf_iter_p->code_point)
{
ecma_char_t code_unit = convert_code_point_to_low_surrogate (buf_iter_p->code_point);
buf_iter_p->code_point = 0;
return code_unit;
}
lit_code_point_t code_point;
buf_iter_p->buf_offset += lit_read_code_point_from_utf8 (buf_iter_p->buf_p + buf_iter_p->buf_offset,
buf_iter_p->buf_size - buf_iter_p->buf_offset,
&code_point);
if (code_point <= LIT_UTF16_CODE_UNIT_MAX)
{
return (ecma_char_t) code_point;
}
else
{
buf_iter_p->code_point = code_point;
return convert_code_point_to_high_surrogate (code_point);
}
JERRY_ASSERT (false);
return ECMA_CHAR_NULL;
} /* lit_utf8_iterator_read_code_unit_and_increment */
/**
* Checks iterator reached end of the string
*
* @return true - the whole string was iterated
* false - otherwise
*/
bool
lit_utf8_iterator_reached_buffer_end (const lit_utf8_iterator_t *buf_iter_p) /**< utf-8 string iterator */
{
JERRY_ASSERT (buf_iter_p->buf_offset <= buf_iter_p->buf_size);
if (buf_iter_p->code_point == LIT_UNICODE_CODE_POINT_NULL && buf_iter_p->buf_offset == buf_iter_p->buf_size)
{
return true;
}
return false;
} /* lit_utf8_iterator_reached_buffer_end */
/**
* Calculate size of a zero-terminated utf-8 string
*
* NOTE:
* string should not contain zero characters in the middel
*
* @return size of a string
*/
lit_utf8_size_t
lit_zt_utf8_string_size (const lit_utf8_byte_t *utf8_str_p) /**< zero-terminated utf-8 string */
{
return (lit_utf8_size_t) strlen ((const char *) utf8_str_p);
} /* lit_zt_utf8_string_size */
/**
* Calculate length of a utf-8 string
*
* @return UTF-16 code units count
*/
ecma_length_t
lit_utf8_string_length (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */
lit_utf8_size_t utf8_buf_size) /**< string size */
{
ecma_length_t length = 0;
lit_utf8_iterator_t buf_iter = lit_utf8_iterator_create (utf8_buf_p, utf8_buf_size);
while (!lit_utf8_iterator_reached_buffer_end (&buf_iter))
{
lit_utf8_iterator_read_code_unit_and_increment (&buf_iter);
length++;
}
JERRY_ASSERT (lit_utf8_iterator_reached_buffer_end (&buf_iter));
return length;
} /* lit_utf8_string_length */
/**
* Decodes a unicode code point from non-empty utf-8-encoded buffer
*
* @return number of bytes occupied by code point in the string
*/
lit_utf8_size_t
lit_read_code_point_from_utf8 (const lit_utf8_byte_t *buf_p, /**< buffer with characters */
lit_utf8_size_t buf_size, /**< size of the buffer in bytes */
lit_code_point_t *code_point) /**< @out: code point */
{
JERRY_ASSERT (buf_p && buf_size);
lit_utf8_byte_t c = (uint8_t) buf_p[0];
if ((c & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER)
{
*code_point = (uint32_t) (c & LIT_UTF8_LAST_7_BITS_MASK);
return 1;
}
lit_code_point_t ret = LIT_UNICODE_CODE_POINT_NULL;
ecma_length_t bytes_count = 0;
if ((c & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER)
{
bytes_count = 2;
ret = ((uint32_t) (c & LIT_UTF8_LAST_5_BITS_MASK));
}
else if ((c & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER)
{
bytes_count = 3;
ret = ((uint32_t) (c & LIT_UTF8_LAST_4_BITS_MASK));
}
else if ((c & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER)
{
bytes_count = 4;
ret = ((uint32_t) (c & LIT_UTF8_LAST_3_BITS_MASK));
}
else
{
JERRY_ASSERT (false);
}
JERRY_ASSERT (buf_size >= bytes_count);
for (uint32_t i = 1; i < bytes_count; ++i)
{
ret <<= LIT_UTF8_BITS_IN_EXTRA_BYTES;
ret |= (buf_p[i] & LIT_UTF8_LAST_6_BITS_MASK);
}
*code_point = ret;
return bytes_count;
} /* lit_read_code_point_from_utf8 */
/**
* Calculate hash from last LIT_STRING_HASH_LAST_BYTES_COUNT characters from the buffer.
*
* @return ecma-string's hash
*/
lit_string_hash_t
lit_utf8_string_calc_hash_last_bytes (const lit_utf8_byte_t *utf8_buf_p, /**< characters buffer */
lit_utf8_size_t utf8_buf_size) /**< number of characters in the buffer */
{
JERRY_ASSERT (utf8_buf_p != NULL);
lit_utf8_byte_t byte1 = (utf8_buf_size > 0) ? utf8_buf_p[utf8_buf_size - 1] : 0;
lit_utf8_byte_t byte2 = (utf8_buf_size > 1) ? utf8_buf_p[utf8_buf_size - 2] : 0;
uint32_t t1 = (uint32_t) byte1 + (uint32_t) byte2;
uint32_t t2 = t1 * 0x24418b66;
uint32_t t3 = (t2 >> 16) ^ (t2 & 0xffffu);
uint32_t t4 = (t3 >> 8) ^ (t3 & 0xffu);
return (lit_string_hash_t) t4;
} /* lit_utf8_string_calc_hash_last_bytes */
/**
* Return code unit at the specified position in string
*
* NOTE:
* code_unit_offset should be less then string's length
*
* @return code unit value
*/
ecma_char_t
lit_utf8_string_code_unit_at (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */
lit_utf8_size_t utf8_buf_size, /**< string size in bytes */
ecma_length_t code_unit_offset) /**< ofset of a code_unit */
{
lit_utf8_iterator_t iter = lit_utf8_iterator_create (utf8_buf_p, utf8_buf_size);
ecma_char_t code_unit;
do
{
JERRY_ASSERT (!lit_utf8_iterator_reached_buffer_end (&iter));
code_unit = lit_utf8_iterator_read_code_unit_and_increment (&iter);
}
while (code_unit_offset--);
return code_unit;
} /* lit_utf8_string_code_unit_at */
/**
* Return number of bytes occupied by a unicode character in utf-8 representation
*
* @return size of a unicode character in utf-8 format
*/
lit_utf8_size_t
lit_get_unicode_char_size_by_utf8_first_byte (lit_utf8_byte_t first_byte) /**< first byte of a utf-8 byte sequence */
{
if ((first_byte & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER)
{
return 1;
}
else if ((first_byte & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER)
{
return 2;
}
else if ((first_byte & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER)
{
return 3;
}
else
{
JERRY_ASSERT ((first_byte & LIT_UTF8_4_BYTE_MASK) == LIT_UTF8_4_BYTE_MARKER);
return 4;
}
} /* lit_get_unicode_char_size_by_utf8_first_byte */
/**
* Convert code_unit to utf-8 representation
*
* @return bytes count, stored required to represent specified code unit
*/
lit_utf8_size_t
lit_code_unit_to_utf8 (ecma_char_t code_unit, /**< code unit */
lit_utf8_byte_t *buf_p) /**< buffer where to store the result,
* its size should be at least MAX_BYTES_IN_CODE_UNIT */
{
return lit_code_point_to_utf8 (code_unit, buf_p);
} /* lit_code_unit_to_utf8 */
/**
* Convert code point to utf-8 representation
*
* @return bytes count, stored required to represent specified code unit
*/
lit_utf8_size_t
lit_code_point_to_utf8 (lit_code_point_t code_point, /**< code point */
lit_utf8_byte_t *buf) /**< buffer where to store the result,
* its size should be at least 4 bytes */
{
if (code_point <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
{
buf[0] = (lit_utf8_byte_t) code_point;
return 1;
}
else if (code_point <= LIT_UTF8_2_BYTE_CODE_POINT_MAX)
{
uint32_t code_point_bits = code_point;
lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK);
code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES;
lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_5_BITS_MASK);
JERRY_ASSERT (first_byte_bits == code_point_bits);
buf[0] = LIT_UTF8_2_BYTE_MARKER | first_byte_bits;
buf[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits;
return 2;
}
else if (code_point <= LIT_UTF8_3_BYTE_CODE_POINT_MAX)
{
uint32_t code_point_bits = code_point;
lit_utf8_byte_t third_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK);
code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES;
lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK);
code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES;
lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_4_BITS_MASK);
JERRY_ASSERT (first_byte_bits == code_point_bits);
buf[0] = LIT_UTF8_3_BYTE_MARKER | first_byte_bits;
buf[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits;
buf[2] = LIT_UTF8_EXTRA_BYTE_MARKER | third_byte_bits;
return 3;
}
else
{
JERRY_ASSERT (code_point <= LIT_UTF8_4_BYTE_CODE_POINT_MAX);
uint32_t code_point_bits = code_point;
lit_utf8_byte_t fourth_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK);
code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES;
lit_utf8_byte_t third_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK);
code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES;
lit_utf8_byte_t second_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_6_BITS_MASK);
code_point_bits >>= LIT_UTF8_BITS_IN_EXTRA_BYTES;
lit_utf8_byte_t first_byte_bits = (lit_utf8_byte_t) (code_point_bits & LIT_UTF8_LAST_3_BITS_MASK);
JERRY_ASSERT (first_byte_bits == code_point_bits);
buf[0] = LIT_UTF8_4_BYTE_MARKER | first_byte_bits;
buf[1] = LIT_UTF8_EXTRA_BYTE_MARKER | second_byte_bits;
buf[2] = LIT_UTF8_EXTRA_BYTE_MARKER | third_byte_bits;
buf[3] = LIT_UTF8_EXTRA_BYTE_MARKER | fourth_byte_bits;
return 4;
}
} /* lit_code_unit_to_utf8 */
/**
* Compare utf-8 string to utf-8 string
*
* @return true - if strings are equal;
* false - otherwise.
*/
bool
lit_compare_utf8_strings (const lit_utf8_byte_t *string1_p, /**< utf-8 string */
lit_utf8_size_t string1_size, /**< string size */
const lit_utf8_byte_t *string2_p, /**< utf-8 string */
lit_utf8_size_t string2_size) /**< string size */
{
if (string1_size != string2_size)
{
return false;
}
return memcmp (string1_p, string2_p, string1_size) == 0;
} /* lit_compare_utf8_strings */
/**
* Relational compare of utf-8 strings
*
* First string is less than second string if:
* - strings are not equal;
* - first string is prefix of second or is lexicographically less than second.
*
* @return true - if first string is less than second string,
* false - otherwise.
*/
bool lit_compare_utf8_strings_relational (const lit_utf8_byte_t *string1_p, /**< utf-8 string */
lit_utf8_size_t string1_size, /**< string size */
const lit_utf8_byte_t *string2_p, /**< utf-8 string */
lit_utf8_size_t string2_size) /**< string size */
{
lit_utf8_iterator_t iter1 = lit_utf8_iterator_create (string1_p, string1_size);
lit_utf8_iterator_t iter2 = lit_utf8_iterator_create (string2_p, string2_size);
while (!lit_utf8_iterator_reached_buffer_end (&iter1)
&& !lit_utf8_iterator_reached_buffer_end (&iter2))
{
ecma_char_t code_point1 = lit_utf8_iterator_read_code_unit_and_increment (&iter1);
ecma_char_t code_point2 = lit_utf8_iterator_read_code_unit_and_increment (&iter2);
if (code_point1 < code_point2)
{
return true;
}
else if (code_point1 > code_point2)
{
return false;
}
}
return (lit_utf8_iterator_reached_buffer_end (&iter1) && !lit_utf8_iterator_reached_buffer_end (&iter2));
} /* lit_compare_utf8_strings_relational */
+80
View File
@@ -0,0 +1,80 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* 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.
*/
#ifndef LIT_UNICODE_HELPERS_H
#define LIT_UNICODE_HELPERS_H
#include "jrt.h"
#include "lit-globals.h"
/**
* Null character (used in few cases as utf-8 string end marker)
*/
#define LIT_BYTE_NULL (0)
/**
* Represents an iterator over utf-8 buffer
*/
typedef struct
{
lit_utf8_size_t buf_offset; /* current offset in the buffer */
lit_utf8_size_t buf_size; /* buffer length */
const lit_utf8_byte_t *buf_p; /* buffer */
lit_code_point_t code_point; /* code point is saved here when processed Unicode character is higher than
* 0xFFFF */
} lit_utf8_iterator_t;
/* validation */
bool lit_is_utf8_string_valid (const lit_utf8_byte_t *, lit_utf8_size_t);
/* iteration */
lit_utf8_iterator_t lit_utf8_iterator_create (const lit_utf8_byte_t *, lit_utf8_size_t);
ecma_char_t lit_utf8_iterator_read_code_unit_and_increment (lit_utf8_iterator_t *);
bool lit_utf8_iterator_reached_buffer_end (const lit_utf8_iterator_t *);
/* size */
lit_utf8_size_t lit_zt_utf8_string_size (const lit_utf8_byte_t *);
/* length */
ecma_length_t lit_utf8_string_length (const lit_utf8_byte_t *, lit_utf8_size_t);
/* hash */
lit_string_hash_t lit_utf8_string_calc_hash_last_bytes (const lit_utf8_byte_t *, lit_utf8_size_t);
/* code unit access */
ecma_char_t lit_utf8_string_code_unit_at (const lit_utf8_byte_t *, lit_utf8_size_t, ecma_length_t);
lit_utf8_size_t lit_get_unicode_char_size_by_utf8_first_byte (lit_utf8_byte_t);
/* conversion */
lit_utf8_size_t lit_code_unit_to_utf8 (ecma_char_t, lit_utf8_byte_t *);
lit_utf8_size_t lit_code_point_to_utf8 (lit_code_point_t, lit_utf8_byte_t *);
/* comparison */
bool lit_compare_utf8_strings (const lit_utf8_byte_t *,
lit_utf8_size_t,
const lit_utf8_byte_t *,
lit_utf8_size_t);
bool lit_compare_utf8_strings_relational (const lit_utf8_byte_t *string1_p,
lit_utf8_size_t,
const lit_utf8_byte_t *string2_p,
lit_utf8_size_t);
/* read code point from buffer */
lit_utf8_size_t lit_read_code_point_from_utf8 (const lit_utf8_byte_t *,
lit_utf8_size_t,
lit_code_point_t *);
#endif /* LIT_UNICODE_HELPERS_H */
+57 -67
View File
@@ -15,14 +15,10 @@
*/
#include "ecma-helpers.h"
#include "ecma-exceptions.h"
#include "jrt-libc-includes.h"
#include "jsp-mm.h"
#include "lexer.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "parser.h"
#include "stack.h"
#include "lit-magic-strings.h"
#include "syntax-errors.h"
static token saved_token, prev_token, sent_token, empty_token;
@@ -31,9 +27,9 @@ static bool allow_dump_lines = false, strict_mode;
static size_t buffer_size = 0;
/* Represents the contents of a script. */
static const char *buffer_start = NULL;
static const char *buffer = NULL;
static const char *token_start;
static const jerry_api_char_t *buffer_start = NULL;
static const jerry_api_char_t *buffer = NULL;
static const jerry_api_char_t *token_start;
#define LA(I) (get_char (I))
@@ -56,7 +52,7 @@ current_locus (void)
}
}
static char
static ecma_char_t
get_char (size_t i)
{
if ((buffer + i) >= (buffer_start + buffer_size))
@@ -69,7 +65,7 @@ get_char (size_t i)
static void
dump_current_line (void)
{
const char *i;
const lit_utf8_byte_t *i;
if (!allow_dump_lines)
{
@@ -78,6 +74,7 @@ dump_current_line (void)
printf ("// ");
FIXME ("Unicode: properly process non-ascii characters.");
for (i = buffer; *i != '\n' && *i != 0; i++)
{
putchar (*i);
@@ -122,18 +119,18 @@ create_token (token_type type, /**< type of token */
*/
static token
convert_string_to_token (token_type tt, /**< token type */
const ecma_char_t *str_p, /**< characters buffer */
ecma_length_t length) /**< string's length */
const lit_utf8_byte_t *str_p, /**< characters buffer */
lit_utf8_size_t length) /**< string's length */
{
JERRY_ASSERT (str_p != NULL);
literal_t lit = lit_find_literal_by_charset (str_p, length);
literal_t lit = lit_find_literal_by_utf8_string (str_p, length);
if (lit != NULL)
{
return create_token_from_lit (tt, lit);
}
lit = lit_create_literal_from_charset (str_p, length);
lit = lit_create_literal_from_utf8_string (str_p, length);
JERRY_ASSERT (lit->get_type () == LIT_STR_T
|| lit->get_type () == LIT_MAGIC_STR_T
|| lit->get_type () == LIT_MAGIC_STR_EX_T);
@@ -150,8 +147,8 @@ convert_string_to_token (token_type tt, /**< token type */
* else - return empty_token.
*/
static token
decode_keyword (const ecma_char_t *str_p, /**< characters buffer */
size_t length) /**< string's length */
decode_keyword (const lit_utf8_byte_t *str_p, /**< characters buffer */
lit_utf8_size_t str_size) /**< string's length */
{
typedef struct
{
@@ -211,8 +208,10 @@ decode_keyword (const ecma_char_t *str_p, /**< characters buffer */
for (uint32_t i = 0; i < sizeof (keywords) / sizeof (kw_descr_t); i++)
{
if (strlen (keywords[i].keyword_p) == length
&& !strncmp (keywords[i].keyword_p, (const char *) str_p, length))
if (lit_compare_utf8_strings (str_p,
str_size,
(lit_utf8_byte_t *) keywords[i].keyword_p,
(lit_utf8_size_t) strlen (keywords[i].keyword_p)))
{
kw = keywords[i].keyword_id;
break;
@@ -233,7 +232,7 @@ decode_keyword (const ecma_char_t *str_p, /**< characters buffer */
case KW_STATIC:
case KW_YIELD:
{
return convert_string_to_token (TOK_NAME, str_p, (ecma_length_t) length);
return convert_string_to_token (TOK_NAME, str_p, (ecma_length_t) str_size);
}
default:
@@ -249,22 +248,15 @@ decode_keyword (const ecma_char_t *str_p, /**< characters buffer */
}
else
{
const ecma_char_t *false_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_FALSE);
const ecma_char_t *true_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_TRUE);
const ecma_char_t *null_p = lit_get_magic_string_zt (LIT_MAGIC_STRING_NULL);
if (strlen ((const char*) false_p) == length
&& !strncmp ((const char*) str_p, (const char*) false_p, length))
if (lit_compare_utf8_string_and_magic_string (str_p, str_size, LIT_MAGIC_STRING_FALSE))
{
return create_token (TOK_BOOL, false);
}
else if (strlen ((const char*) true_p) == length
&& !strncmp ((const char*) str_p, (const char*) true_p, length))
else if (lit_compare_utf8_string_and_magic_string (str_p, str_size, LIT_MAGIC_STRING_TRUE))
{
return create_token (TOK_BOOL, true);
}
else if (strlen ((const char*) null_p) == length
&& !strncmp ((const char*) str_p, (const char*) null_p, length))
else if (lit_compare_utf8_string_and_magic_string (str_p, str_size, LIT_MAGIC_STRING_NULL))
{
return create_token (TOK_NULL, 0);
}
@@ -432,8 +424,8 @@ convert_single_escape_character (ecma_char_t c, /**< character to decode */
*/
static token
convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of token to produce */
const char *source_str_p, /**< string to convert,
* located in source buffer */
const jerry_api_char_t *source_str_p, /**< string to convert,
* located in source buffer */
size_t source_str_size) /**< size of the string */
{
token ret;
@@ -441,7 +433,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
if (source_str_size == 0)
{
return convert_string_to_token (tok_type,
lit_get_magic_string_zt (LIT_MAGIC_STRING__EMPTY),
lit_get_magic_string_utf8 (LIT_MAGIC_STRING__EMPTY),
0);
}
else
@@ -449,10 +441,10 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
JERRY_ASSERT (source_str_p != NULL);
}
ecma_char_t *str_buf_p = (ecma_char_t*) jsp_mm_alloc (source_str_size * sizeof (ecma_char_t));
lit_utf8_byte_t *str_buf_p = (lit_utf8_byte_t*) jsp_mm_alloc (source_str_size);
const char *source_str_iter_p = source_str_p;
ecma_char_t *str_buf_iter_p = str_buf_p;
const lit_utf8_byte_t *source_str_iter_p = source_str_p;
lit_utf8_byte_t *str_buf_iter_p = str_buf_p;
bool is_correct_sequence = true;
bool every_char_islower = true;
@@ -464,7 +456,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
if (*source_str_iter_p != '\\')
{
converted_char = (ecma_char_t) *source_str_iter_p++;
converted_char = (lit_utf8_byte_t) *source_str_iter_p++;
JERRY_ASSERT (str_buf_iter_p <= str_buf_p + source_str_size);
JERRY_ASSERT (source_str_iter_p <= source_str_p + source_str_size);
@@ -473,7 +465,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
{
source_str_iter_p++;
const ecma_char_t escape_character = (ecma_char_t) *source_str_iter_p++;
const lit_utf8_byte_t escape_character = (lit_utf8_byte_t) *source_str_iter_p++;
JERRY_ASSERT (source_str_iter_p <= source_str_p + source_str_size);
if (isdigit (escape_character))
@@ -505,9 +497,9 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
for (uint32_t i = 0; i < hex_chars_num; i++)
{
const char nc = *source_str_iter_p++;
const lit_utf8_byte_t byte = (lit_utf8_byte_t) *source_str_iter_p++;
if (!isxdigit (nc))
if (!isxdigit (byte))
{
chars_are_hex = false;
break;
@@ -520,7 +512,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
JERRY_ASSERT ((char_code & 0xF000u) == 0);
char_code = (uint16_t) (char_code << 4u);
char_code = (uint16_t) (char_code + ecma_char_hex_to_int ((ecma_char_t) nc));
char_code = (uint16_t) (char_code + ecma_char_hex_to_int (byte));
}
}
@@ -544,10 +536,10 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
{
if (source_str_iter_p + 1 <= source_str_p + source_str_size)
{
char nc = *source_str_iter_p;
lit_utf8_byte_t byte = *source_str_iter_p;
if (escape_character == '\x0D'
&& nc == '\x0A')
&& byte == '\x0A')
{
source_str_iter_p++;
}
@@ -561,7 +553,8 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
}
}
*str_buf_iter_p++ = converted_char;
TODO ("Support surrogate paris.")
str_buf_iter_p += lit_code_unit_to_utf8 (converted_char, str_buf_iter_p);
JERRY_ASSERT (str_buf_iter_p <= str_buf_p + source_str_size);
if (!islower (converted_char))
@@ -580,7 +573,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of
if (is_correct_sequence)
{
ecma_length_t length = (ecma_length_t) (str_buf_iter_p - str_buf_p);
lit_utf8_size_t length = (lit_utf8_size_t) (str_buf_iter_p - str_buf_p);
ret = empty_token;
if (tok_type == TOK_NAME)
@@ -683,7 +676,7 @@ parse_name (void)
static token
parse_number (void)
{
char c = LA (0);
ecma_char_t c = LA (0);
bool is_hex = false;
bool is_fp = false;
bool is_exp = false;
@@ -736,11 +729,11 @@ parse_number (void)
{
if (!is_overflow)
{
res = (res << 4) + ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
res = (res << 4) + ecma_char_hex_to_int (token_start[i]);
}
else
{
fp_res = fp_res * 16 + (ecma_number_t) ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
fp_res = fp_res * 16 + (ecma_number_t) ecma_char_hex_to_int (token_start[i]);
}
if (res > 255)
@@ -830,15 +823,11 @@ parse_number (void)
consume_char ();
}
tok_length = (size_t) (buffer - token_start);;
tok_length = (size_t) (buffer - token_start);
if (is_fp || is_exp)
{
ecma_char_t *temp = (ecma_char_t*) jsp_mm_alloc ((size_t) (tok_length + 1) * sizeof (ecma_char_t));
strncpy ((char *) temp, token_start, (size_t) (tok_length));
temp[tok_length] = '\0';
ecma_number_t res = ecma_zt_string_to_number (temp);
ecma_number_t res = ecma_utf8_string_to_number (token_start, (jerry_api_size_t) tok_length);
JERRY_ASSERT (!ecma_number_is_nan (res));
jsp_mm_free (temp);
known_token = convert_seen_num_to_token (res);
token_start = NULL;
return known_token;
@@ -854,11 +843,11 @@ parse_number (void)
{
if (!is_overflow)
{
res = res * 8 + ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
res = res * 8 + ecma_char_hex_to_int (token_start[i]);
}
else
{
fp_res = fp_res * 8 + (ecma_number_t) ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
fp_res = fp_res * 8 + (ecma_number_t) ecma_char_hex_to_int (token_start[i]);
}
if (res > 255)
{
@@ -874,11 +863,11 @@ parse_number (void)
{
if (!is_overflow)
{
res = res * 10 + ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
res = res * 10 + ecma_char_hex_to_int (token_start[i]);
}
else
{
fp_res = fp_res * 10 + (ecma_number_t) ecma_char_hex_to_int ((ecma_char_t) token_start[i]);
fp_res = fp_res * 10 + (ecma_number_t) ecma_char_hex_to_int (token_start[i]);
}
if (res > 255)
{
@@ -1029,7 +1018,7 @@ parse_regexp (void)
}
result = convert_string_to_token (TOK_REGEXP,
(const ecma_char_t*) token_start,
(const lit_utf8_byte_t *) token_start,
static_cast<ecma_length_t> (buffer - token_start));
token_start = NULL;
@@ -1039,7 +1028,7 @@ parse_regexp (void)
static void
grobble_whitespaces (void)
{
char c = LA (0);
ecma_char_t c = LA (0);
while ((isspace (c) && c != '\n'))
{
@@ -1049,7 +1038,7 @@ grobble_whitespaces (void)
}
static void
lexer_set_source (const char * source)
lexer_set_source (const jerry_api_char_t * source)
{
buffer_start = source;
buffer = buffer_start;
@@ -1058,7 +1047,7 @@ lexer_set_source (const char * source)
static bool
replace_comment_by_newline (void)
{
char c = LA (0);
ecma_char_t c = LA (0);
bool multiline;
bool was_newlines = false;
@@ -1106,7 +1095,7 @@ replace_comment_by_newline (void)
static token
lexer_next_token_private (void)
{
char c = LA (0);
ecma_char_t c = LA (0);
JERRY_ASSERT (token_start == NULL);
@@ -1295,6 +1284,7 @@ lexer_next_token (void)
prev_token = sent_token;
sent_token = lexer_next_token_private ();
if (sent_token.type == TOK_NEWLINE)
{
dump_current_line ();
@@ -1331,7 +1321,7 @@ void
lexer_locus_to_line_and_column (size_t locus, size_t *line, size_t *column)
{
JERRY_ASSERT (locus <= buffer_size);
const char *buf;
const jerry_api_char_t *buf;
size_t l = 0, c = 0;
for (buf = buffer_start; (size_t) (buf - buffer_start) < locus; buf++)
{
@@ -1358,7 +1348,7 @@ void
lexer_dump_line (size_t line)
{
size_t l = 0;
for (const char *buf = buffer_start; *buf != '\0'; buf++)
for (const lit_utf8_byte_t *buf = buffer_start; *buf != '\0'; buf++)
{
if (l == line)
{
@@ -1538,11 +1528,11 @@ lexer_are_tokens_with_same_identifier (token id1, /**< identifier token (TOK_NAM
} /* lexer_are_tokens_with_same_identifier */
/**
* Intitialize lexer
* Initialize lexer to start parsing of a new source
*/
void
lexer_init (const char *source, /**< script source */
size_t source_size /**< script source size in bytes */,
lexer_init (const jerry_api_char_t *source, /**< script source */
size_t source_size, /**< script source size in bytes */
bool show_opcodes) /**< flag indicating if to dump opcodes */
{
empty_token.type = TOK_EMPTY;
+1 -4
View File
@@ -170,10 +170,7 @@ typedef struct
*/
#define TOKEN_EMPTY_INITIALIZER {0, TOK_EMPTY, 0}
void lexer_init (const char *, size_t, bool);
void lexer_init_source (const char *, size_t);
void lexer_free (void);
void lexer_init (const jerry_api_char_t *, size_t, bool);
token lexer_next_token (void);
void lexer_save_token (token);
+7 -9
View File
@@ -230,27 +230,27 @@ name_to_native_call_id (operand obj)
{
return OPCODE_NATIVE_CALL__COUNT;
}
if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDToggle"))
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.data.lit_id), "LEDToggle"))
{
return OPCODE_NATIVE_CALL_LED_TOGGLE;
}
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDOn"))
else if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.data.lit_id), "LEDOn"))
{
return OPCODE_NATIVE_CALL_LED_ON;
}
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDOff"))
else if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.data.lit_id), "LEDOff"))
{
return OPCODE_NATIVE_CALL_LED_OFF;
}
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "LEDOnce"))
else if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.data.lit_id), "LEDOnce"))
{
return OPCODE_NATIVE_CALL_LED_ONCE;
}
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "wait"))
else if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.data.lit_id), "wait"))
{
return OPCODE_NATIVE_CALL_WAIT;
}
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id), (const ecma_char_t *) "print"))
else if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.data.lit_id), "print"))
{
return OPCODE_NATIVE_CALL_PRINT;
}
@@ -803,10 +803,8 @@ dumper_is_eval_literal (operand obj) /**< byte-code operand */
/*
* FIXME: Switch to corresponding magic string
*/
const ecma_char_t *eval_string_p = (const ecma_char_t *) "eval";
bool is_eval_lit = (obj.type == OPERAND_LITERAL
&& lit_literal_equal_type_zt (lit_get_literal_by_cp (obj.data.lit_id),
eval_string_p));
&& lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.data.lit_id), "eval"));
return is_eval_lit;
} /* dumper_is_eval_literal */
+18 -16
View File
@@ -309,7 +309,8 @@ parse_property_name (void)
case TOK_KEYWORD:
{
const char *s = lexer_keyword_to_string ((keyword) token_data ());
literal_t lit = lit_find_or_create_literal_from_charset ((const ecma_char_t *) s, (ecma_length_t) strlen (s));
literal_t lit = lit_find_or_create_literal_from_utf8_string ((const lit_utf8_byte_t *) s,
(lit_utf8_size_t)strlen (s));
return literal_operand (lit_cpointer_t::compress (lit));
}
default:
@@ -345,11 +346,11 @@ parse_property_assignment (void)
{
bool is_setter;
if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()), (const ecma_char_t *) "get"))
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "get"))
{
is_setter = false;
}
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()), (const ecma_char_t *) "set"))
else if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "set"))
{
is_setter = true;
}
@@ -874,7 +875,8 @@ parse_member_expression (operand *this_arg, operand *prop_gl)
else if (token_is (TOK_KEYWORD))
{
const char *s = lexer_keyword_to_string ((keyword) token_data ());
literal_t lit = lit_find_or_create_literal_from_charset ((const ecma_char_t *) s, (ecma_length_t) strlen (s));
literal_t lit = lit_find_or_create_literal_from_utf8_string ((lit_utf8_byte_t *) s,
(lit_utf8_size_t) strlen (s));
if (lit == NULL)
{
EMIT_ERROR ("Expected identifier");
@@ -2848,8 +2850,8 @@ preparse_scope (bool is_global)
bool is_ref_eval_identifier = false;
bool is_use_strict = false;
if (token_is (TOK_STRING) && lit_literal_equal_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()),
(const ecma_char_t *) "use strict"))
if (token_is (TOK_STRING) && lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()),
"use strict"))
{
scopes_tree_set_strict_mode (STACK_TOP (scopes), true);
is_use_strict = true;
@@ -2866,13 +2868,11 @@ preparse_scope (bool is_global)
{
if (token_is (TOK_NAME))
{
if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()),
(const ecma_char_t *) "arguments"))
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "arguments"))
{
is_ref_arguments_identifier = true;
}
else if (lit_literal_equal_type_zt (lit_get_literal_by_cp (token_data_as_lit_cp ()),
(const ecma_char_t *) "eval"))
else if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "eval"))
{
is_ref_eval_identifier = true;
}
@@ -3032,7 +3032,7 @@ parse_source_element_list (bool is_global) /**< flag indicating if we are parsin
* false - otherwise.
*/
static bool
parser_parse_program (const char *source_p, /**< source code buffer */
parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer */
size_t source_size, /**< source code size in bytes */
bool in_function, /**< flag indicating if we are parsing body of a function */
bool in_eval, /**< flag indicating if we are parsing body of eval code */
@@ -3137,7 +3137,7 @@ parser_parse_program (const char *source_p, /**< source code buffer */
* false - otherwise.
*/
bool
parser_parse_script (const char *source, /**< source script */
parser_parse_script (const jerry_api_char_t *source, /**< source script */
size_t source_size, /**< source script size it bytes */
const opcode_t **opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
@@ -3152,7 +3152,7 @@ parser_parse_script (const char *source, /**< source script */
* false - otherwise.
*/
bool
parser_parse_eval (const char *source, /**< string passed to eval() */
parser_parse_eval (const jerry_api_char_t *source, /**< string passed to eval() */
size_t source_size, /**< string size in bytes */
bool is_strict, /**< flag, indicating whether eval is called
* from strict code in direct mode */
@@ -3173,7 +3173,9 @@ parser_parse_eval (const char *source, /**< string passed to eval() */
* false - otherwise.
*/
bool
parser_parse_new_function (const char **params, /**< array of arguments of new Function (p1, p2, ..., pn, body) call */
parser_parse_new_function (const jerry_api_char_t **params, /**< array of arguments of new Function (p1, p2, ..., pn,
* body) call */
const size_t *params_size, /**< sizes of arguments strings */
size_t params_count, /**< total number of arguments passed to new Function (...) */
const opcode_t **out_opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
@@ -3183,10 +3185,10 @@ parser_parse_new_function (const char **params, /**< array of arguments of new F
for (size_t i = 0; i < params_count - 1; ++i)
{
FIXME ("check parameter's name for syntax errors");
lit_find_or_create_literal_from_charset ((ecma_char_t *) params[i], (ecma_length_t) strlen (params[i]));
lit_find_or_create_literal_from_utf8_string ((lit_utf8_byte_t *) params[i], (lit_utf8_size_t) params_size[i]);
}
return parser_parse_program (params[params_count - 1],
strlen (params[params_count - 1]),
params_size[params_count - 1],
true,
false,
false,
+3 -3
View File
@@ -19,8 +19,8 @@
#include "jrt.h"
void parser_set_show_opcodes (bool);
bool parser_parse_script (const char *, size_t, const opcode_t **);
bool parser_parse_eval (const char *, size_t, bool, const opcode_t **);
bool parser_parse_new_function (const char **, size_t, const opcode_t **);
bool parser_parse_script (const jerry_api_char_t *, size_t, const opcode_t **);
bool parser_parse_eval (const jerry_api_char_t *, size_t, bool, const opcode_t **);
bool parser_parse_new_function (const jerry_api_char_t **, const size_t *, size_t, const opcode_t **);
#endif /* PARSER_H */
+7 -4
View File
@@ -19,6 +19,7 @@
#include "parser.h"
#include "jrt-libc-includes.h"
#include "ecma-helpers.h"
#include "lit-magic-strings.h"
/**
* SyntaxError longjmp label, used to finish parse upon a SyntaxError is raised
@@ -177,10 +178,12 @@ emit_error_on_eval_and_arguments (operand op, locus loc __attr_unused___)
{
if (op.type == OPERAND_LITERAL)
{
if (lit_literal_equal_type_zt (lit_get_literal_by_cp (op.data.lit_id),
lit_get_magic_string_zt (LIT_MAGIC_STRING_ARGUMENTS))
|| lit_literal_equal_type_zt (lit_get_literal_by_cp (op.data.lit_id),
lit_get_magic_string_zt (LIT_MAGIC_STRING_EVAL)))
if (lit_literal_equal_type_utf8 (lit_get_literal_by_cp (op.data.lit_id),
lit_get_magic_string_utf8 (LIT_MAGIC_STRING_ARGUMENTS),
lit_get_magic_string_size (LIT_MAGIC_STRING_ARGUMENTS))
|| lit_literal_equal_type_utf8 (lit_get_literal_by_cp (op.data.lit_id),
lit_get_magic_string_utf8 (LIT_MAGIC_STRING_EVAL),
lit_get_magic_string_size (LIT_MAGIC_STRING_EVAL)))
{
PARSE_ERROR ("'eval' and 'arguments' are not allowed here in strict mode", loc);
}
+14 -11
View File
@@ -20,6 +20,7 @@
#include "jrt-libc-includes.h"
#include "mem-heap.h"
#include "re-compiler.h"
#include "re-parser.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
@@ -382,7 +383,7 @@ parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */
if (re_ctx_p->recursion_depth >= RE_COMPILE_RECURSION_LIMIT)
{
ret_value = ecma_raise_range_error ((const ecma_char_t *) "RegExp compiler recursion limit is exceeded.");
ret_value = ecma_raise_range_error ("RegExp compiler recursion limit is exceeded.");
return ret_value;
}
re_ctx_p->recursion_depth++;
@@ -575,7 +576,7 @@ parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */
if (expect_eof)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Unexpected end of paren.");
ret_value = ecma_raise_syntax_error ("Unexpected end of paren.");
}
else
{
@@ -589,7 +590,7 @@ parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */
{
if (!expect_eof)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Unexpected end of pattern.");
ret_value = ecma_raise_syntax_error ("Unexpected end of pattern.");
}
else
{
@@ -601,7 +602,7 @@ parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */
}
default:
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Unexpected RegExp token.");
ret_value = ecma_raise_syntax_error ("Unexpected RegExp token.");
return ret_value;
}
}
@@ -619,8 +620,8 @@ parse_alternative (re_compiler_ctx_t *re_ctx_p, /**< RegExp compiler context */
*/
ecma_completion_value_t
re_compile_bytecode (ecma_property_t *bytecode_p, /**< bytecode */
ecma_string_t *pattern_str_p, /**< pattern */
uint8_t flags) /**< flags */
ecma_string_t *pattern_str_p, /**< pattern */
uint8_t flags) /**< flags */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
re_compiler_ctx_t re_ctx;
@@ -636,10 +637,12 @@ re_compile_bytecode (ecma_property_t *bytecode_p, /**< bytecode */
re_ctx.bytecode_ctx_p = &bc_ctx;
ecma_length_t pattern_str_len = ecma_string_get_length (pattern_str_p);
MEM_DEFINE_LOCAL_ARRAY (pattern_start_p, pattern_str_len + 1, ecma_char_t);
ssize_t zt_str_size = (ssize_t) (sizeof (ecma_char_t) * (pattern_str_len + 1));
ecma_string_to_zt_string (pattern_str_p, pattern_start_p, zt_str_size);
lit_utf8_size_t pattern_str_size = ecma_string_get_size (pattern_str_p);
MEM_DEFINE_LOCAL_ARRAY (pattern_start_p, pattern_str_size + 1, lit_utf8_byte_t);
ecma_string_to_utf8_string (pattern_str_p, pattern_start_p, (ssize_t) pattern_str_size);
FIXME ("Update regexp compiler so that zero symbol is not needed.");
pattern_start_p[pattern_str_size] = LIT_BYTE_NULL;
re_parser_ctx_t parser_ctx;
parser_ctx.pattern_start_p = pattern_start_p;
@@ -656,7 +659,7 @@ re_compile_bytecode (ecma_property_t *bytecode_p, /**< bytecode */
/* 2. Check for invalid backreference */
if (re_ctx.highest_backref >= re_ctx.num_of_captures)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "Invalid backreference.\n");
ret_value = ecma_raise_syntax_error ("Invalid backreference.\n");
}
else
{
+21 -21
View File
@@ -25,13 +25,13 @@
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
/* FIXME: change it, when unicode support would be implemented */
#define RE_LOOKUP(str_p, lookup) (ecma_zt_string_length (str_p) > lookup ? str_p[lookup] : '\0')
#define RE_LOOKUP(str_p, lookup) (lit_zt_utf8_string_size (str_p) > (lookup) ? str_p[lookup] : '\0')
/* FIXME: change it, when unicode support would be implemented */
#define RE_ADVANCE(str_p, advance) do { str_p += advance; } while (0)
static ecma_char_t
get_ecma_char (ecma_char_t** char_p)
get_ecma_char (lit_utf8_byte_t **char_p)
{
/* FIXME: change to string iterator with unicode support, when it would be implemented */
ecma_char_t ch = **char_p;
@@ -46,7 +46,7 @@ get_ecma_char (ecma_char_t** char_p)
* Returned value must be freed with ecma_free_completion_value
*/
static ecma_completion_value_t
parse_re_iterator (ecma_char_t *pattern_p, /**< RegExp pattern */
parse_re_iterator (lit_utf8_byte_t *pattern_p, /**< RegExp pattern */
re_token_t *re_token_p, /**< output token */
uint32_t lookup, /**< size of lookup */
uint32_t *advance_p) /**< output length of current advance */
@@ -120,7 +120,7 @@ parse_re_iterator (ecma_char_t *pattern_p, /**< RegExp pattern */
{
if (digits >= ECMA_NUMBER_MAX_DIGITS)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "RegExp quantifier error: too many digits.");
ret_value = ecma_raise_syntax_error ("RegExp quantifier error: too many digits.");
return ret_value;
}
digits++;
@@ -130,14 +130,14 @@ parse_re_iterator (ecma_char_t *pattern_p, /**< RegExp pattern */
{
if (qmax != RE_ITERATOR_INFINITE)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "RegExp quantifier error: double comma.");
ret_value = ecma_raise_syntax_error ("RegExp quantifier error: double comma.");
return ret_value;
}
if ((RE_LOOKUP (pattern_p, lookup + *advance_p + 1)) == '}')
{
if (digits == 0)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "RegExp quantifier error: missing digits.");
ret_value = ecma_raise_syntax_error ("RegExp quantifier error: missing digits.");
return ret_value;
}
@@ -154,7 +154,7 @@ parse_re_iterator (ecma_char_t *pattern_p, /**< RegExp pattern */
{
if (digits == 0)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "RegExp quantifier error: missing digits.");
ret_value = ecma_raise_syntax_error ("RegExp quantifier error: missing digits.");
return ret_value;
}
@@ -174,7 +174,7 @@ parse_re_iterator (ecma_char_t *pattern_p, /**< RegExp pattern */
}
else
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "RegExp quantifier error: unknown char.");
ret_value = ecma_raise_syntax_error ("RegExp quantifier error: unknown char.");
return ret_value;
}
}
@@ -206,7 +206,7 @@ parse_re_iterator (ecma_char_t *pattern_p, /**< RegExp pattern */
if (re_token_p->qmin > re_token_p->qmax)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "RegExp quantifier error: qmin > qmax.");
ret_value = ecma_raise_syntax_error ("RegExp quantifier error: qmin > qmax.");
}
return ret_value;
@@ -218,13 +218,13 @@ parse_re_iterator (ecma_char_t *pattern_p, /**< RegExp pattern */
static void
re_count_num_of_groups (re_parser_ctx_t *parser_ctx_p) /**< RegExp parser context */
{
ecma_char_t *pattern_p = parser_ctx_p->pattern_start_p;
lit_utf8_byte_t *pattern_p = parser_ctx_p->pattern_start_p;
ecma_char_t ch1;
int char_class_in = 0;
parser_ctx_p->num_of_groups = 0;
ch1 = get_ecma_char (&pattern_p);
while (ch1 != '\0')
while (ch1 != ECMA_CHAR_NULL)
{
ecma_char_t ch0 = ch1;
ch1 = get_ecma_char (&pattern_p);
@@ -275,7 +275,7 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
re_token_t *out_token_p) /**< output token */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_char_t **pattern_p = &(parser_ctx_p->current_char_p);
lit_utf8_byte_t **pattern_p = &(parser_ctx_p->current_char_p);
out_token_p->qmax = out_token_p->qmin = 1;
ecma_char_t start = RE_CHAR_UNDEF;
@@ -338,7 +338,7 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
}
else
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "invalid regexp control escape");
ret_value = ecma_raise_syntax_error ("invalid regexp control escape");
return ret_value;
}
}
@@ -433,7 +433,7 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
{
if (is_range)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "invalid character class range");
ret_value = ecma_raise_syntax_error ("invalid character class range");
return ret_value;
}
else
@@ -451,7 +451,7 @@ re_parse_char_class (re_parser_ctx_t *parser_ctx_p, /**< number of classes */
{
if (start > ch)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "invalid character class range");
ret_value = ecma_raise_syntax_error ("invalid character class range");
return ret_value;
}
else
@@ -500,8 +500,8 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
uint32_t advance = 0;
ecma_char_t ch0 = *(parser_ctx_p->current_char_p);
ecma_char_t ch0 = *(parser_ctx_p->current_char_p);
switch (ch0)
{
case '|':
@@ -580,7 +580,7 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
}
else
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "invalid regexp control escape");
ret_value = ecma_raise_syntax_error ("invalid regexp control escape");
break;
}
}
@@ -640,7 +640,7 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
{
if (isdigit (RE_LOOKUP (parser_ctx_p->current_char_p, 2)))
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *) "RegExp escape pattern error.");
ret_value = ecma_raise_syntax_error ("RegExp escape pattern error.");
break;
}
@@ -664,13 +664,13 @@ re_parse_next_token (re_parser_ctx_t *parser_ctx_p, /**< RegExp parser context *
{
if (index >= RE_MAX_RE_DECESC_DIGITS)
{
ret_value = ecma_raise_syntax_error ((const ecma_char_t *)
"RegExp escape pattern error: decimal escape too long.");
ret_value = ecma_raise_syntax_error ("RegExp escape pattern error: decimal escape too long.");
return ret_value;
}
advance++;
ecma_char_t digit = RE_LOOKUP (parser_ctx_p->current_char_p, advance);
ecma_char_t digit = RE_LOOKUP (parser_ctx_p->current_char_p,
advance);
if (!isdigit (digit))
{
break;
+2 -2
View File
@@ -71,8 +71,8 @@ typedef struct
typedef struct
{
ecma_char_t *pattern_start_p;
ecma_char_t *current_char_p;
lit_utf8_byte_t *pattern_start_p;
lit_utf8_byte_t *current_char_p;
int num_of_groups;
uint32_t num_of_classes;
} re_parser_ctx_t;
+4 -1
View File
@@ -311,7 +311,10 @@ public:
*/
void skip (size_t size) /**< number of bytes to skip */
{
access (ACCESS_SKIP, NULL, size);
if (size)
{
access (ACCESS_SKIP, NULL, size);
}
} /* skip */
/**
+11 -13
View File
@@ -79,32 +79,30 @@ opfunc_native_call (opcode_t opdata, /**< operation data */
ecma_string_t *str_p = ecma_get_string_from_value (str_value);
ecma_length_t chars = ecma_string_get_length (str_p);
lit_utf8_size_t bytes = ecma_string_get_size (str_p);
ssize_t zt_str_size = (ssize_t) (sizeof (ecma_char_t) * (chars + 1));
ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size,
MEM_HEAP_ALLOC_SHORT_TERM);
if (zt_str_p == NULL)
ssize_t utf8_str_size = (ssize_t) (bytes + 1);
lit_utf8_byte_t *utf8_str_p = (lit_utf8_byte_t*) mem_heap_alloc_block ((size_t) utf8_str_size,
MEM_HEAP_ALLOC_SHORT_TERM);
if (utf8_str_p == NULL)
{
jerry_fatal (ERR_OUT_OF_MEMORY);
}
ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size);
ecma_string_to_utf8_string (str_p, utf8_str_p, utf8_str_size);
utf8_str_p[utf8_str_size - 1] = 0;
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
FIXME ("Support unicode in printf.");
if (arg_index < args_read - 1)
{
printf ("%s ", (char*) zt_str_p);
printf ("%s ", (char*) utf8_str_p);
}
else
{
printf ("%s", (char*) zt_str_p);
printf ("%s", (char*) utf8_str_p);
}
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented.");
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
mem_heap_free_block (zt_str_p);
mem_heap_free_block (utf8_str_p);
ret_value = set_variable_value (int_data, lit_oc, dst_var_idx,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
+14 -13
View File
@@ -175,15 +175,14 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
int_data->pos);
ecma_string_t *string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
ecma_length_t re_str_len = ecma_string_get_length (string_p);
MEM_DEFINE_LOCAL_ARRAY (re_str_p, re_str_len + 1, ecma_char_t);
lit_utf8_size_t re_utf8_buffer_size = ecma_string_get_size (string_p);
MEM_DEFINE_LOCAL_ARRAY (re_utf8_buffer_p, re_utf8_buffer_size, lit_utf8_byte_t);
ssize_t zt_str_size = (ssize_t) (sizeof (ecma_char_t) * (re_str_len + 1));
ecma_string_to_zt_string (string_p, re_str_p, zt_str_size);
ecma_string_to_utf8_string (string_p, re_utf8_buffer_p, (ssize_t) re_utf8_buffer_size);
ecma_char_t *ch_p = re_str_p;
ecma_char_t *last_slash_p = NULL;
while (*ch_p)
lit_utf8_byte_t *ch_p = re_utf8_buffer_p;
lit_utf8_byte_t *last_slash_p = NULL;
while (ch_p < re_utf8_buffer_p + re_utf8_buffer_size)
{
if (*ch_p == '/')
{
@@ -193,14 +192,16 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
}
JERRY_ASSERT (last_slash_p != NULL);
JERRY_ASSERT ((re_str_p < last_slash_p) && (last_slash_p < ch_p));
JERRY_ASSERT ((last_slash_p - re_str_p) > 0);
ecma_string_t *pattern_p = ecma_new_ecma_string (re_str_p, (ecma_length_t) (last_slash_p - re_str_p));
JERRY_ASSERT ((re_utf8_buffer_p < last_slash_p) && (last_slash_p < ch_p));
JERRY_ASSERT ((last_slash_p - re_utf8_buffer_p) > 0);
ecma_string_t *pattern_p = ecma_new_ecma_string_from_utf8 (re_utf8_buffer_p,
(lit_utf8_size_t) (last_slash_p - re_utf8_buffer_p));
ecma_string_t *flags_p = NULL;
if ((ch_p - last_slash_p) > 1)
{
flags_p = ecma_new_ecma_string (last_slash_p + 1, (ecma_length_t) ((ch_p - last_slash_p - 1)));
flags_p = ecma_new_ecma_string_from_utf8 (last_slash_p + 1,
(lit_utf8_size_t) ((ch_p - last_slash_p - 1)));
}
ECMA_TRY_CATCH (regexp_obj_value,
@@ -220,7 +221,7 @@ opfunc_assignment (opcode_t opdata, /**< operation data */
ecma_deref_ecma_string (flags_p);
}
MEM_FINALIZE_LOCAL_ARRAY (re_str_p)
MEM_FINALIZE_LOCAL_ARRAY (re_utf8_buffer_p)
ecma_deref_ecma_string (string_p);
#else
JERRY_UNIMPLEMENTED ("Regular Expressions are not supported in compact profile!");
@@ -564,7 +565,7 @@ opfunc_func_decl_n (opcode_t opdata, /**< operation data */
int_data->pos++;
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_completion_value_t ret_value;
MEM_DEFINE_LOCAL_ARRAY (params_names, params_number, ecma_string_t*);
+6 -4
View File
@@ -38,7 +38,7 @@
static uint8_t source_buffer[ JERRY_SOURCE_BUFFER_SIZE ];
static const char*
static const jerry_api_char_t *
read_sources (const char *script_file_names[],
int files_count,
size_t *out_source_size_p)
@@ -103,7 +103,7 @@ read_sources (const char *script_file_names[],
*out_source_size_p = source_size;
return (const char*)source_buffer;
return (const jerry_api_char_t *) source_buffer;
}
}
@@ -233,7 +233,7 @@ main (int argc,
else
{
size_t source_size;
const char *source_p = read_sources (file_names, files_counter, &source_size);
const jerry_api_char_t *source_p = read_sources (file_names, files_counter, &source_size);
if (source_p == NULL)
{
@@ -265,7 +265,9 @@ main (int argc,
assert_value.type = JERRY_API_DATA_TYPE_OBJECT;
assert_value.v_object = assert_func_p;
bool is_assert_added = jerry_api_set_object_field_value (global_obj_p, "assert", &assert_value);
bool is_assert_added = jerry_api_set_object_field_value (global_obj_p,
(jerry_api_char_t *) "assert",
&assert_value);
jerry_api_release_value (&assert_value);
jerry_api_release_object (global_obj_p);
+3 -1
View File
@@ -22,6 +22,8 @@
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
#include JERRY_MCU_SCRIPT_HEADER
#include "jerry-core/jerry-api.h"
static const char generated_source[] = JERRY_MCU_SCRIPT;
int
@@ -30,7 +32,7 @@ main (void)
const char *source_p = generated_source;
const size_t source_size = sizeof (generated_source);
jerry_completion_code_t ret_code = jerry_run_simple (source_p, source_size, JERRY_FLAG_EMPTY);
jerry_completion_code_t ret_code = jerry_run_simple ((jerry_api_char_t *) source_p, source_size, JERRY_FLAG_EMPTY);
if (ret_code == JERRY_COMPLETION_CODE_OK)
{
+2 -1
View File
@@ -17,6 +17,7 @@
#include <string.h>
#include "jerry.h"
#include "jerry-core/jerry-api.h"
/**
* The module interface routine
@@ -195,7 +196,7 @@ int jerry_main (int argc, char *argv[])
{
printf ("Source:\n------------\n%s\n------------\n", source_p);
jerry_completion_code_t ret_code = jerry_run_simple (source_p, source_size, flags);
jerry_completion_code_t ret_code = jerry_run_simple ((jerry_api_char_t *) source_p, source_size, flags);
if (ret_code == JERRY_COMPLETION_CODE_OK)
{
+28 -27
View File
@@ -88,7 +88,7 @@ test_api_init_api_value_string (jerry_api_value_t *out_value_p, /**< out: API va
const char* v) /**< string value to initialize with */
{
out_value_p->type = JERRY_API_DATA_TYPE_STRING;
out_value_p->v_string = jerry_api_create_string (v);
out_value_p->v_string = jerry_api_create_string ((jerry_api_char_t *) v);
} /* test_api_init_api_value_string */
/**
@@ -121,7 +121,7 @@ handler (const jerry_api_object_t *function_obj_p,
JERRY_ASSERT (args_p[0].type == JERRY_API_DATA_TYPE_STRING);
sz = jerry_api_string_to_char_buffer (args_p[0].v_string, NULL, 0);
JERRY_ASSERT (sz == -2);
sz = jerry_api_string_to_char_buffer (args_p[0].v_string, buffer, -sz);
sz = jerry_api_string_to_char_buffer (args_p[0].v_string, (jerry_api_char_t *) buffer, -sz);
JERRY_ASSERT (sz == 2);
JERRY_ASSERT (!strcmp (buffer, "1"));
@@ -142,7 +142,8 @@ handler_throw_test (const jerry_api_object_t *function_obj_p,
{
printf ("ok %p %p %p %d %p\n", function_obj_p, this_p, args_p, args_cnt, ret_val_p);
jerry_api_object_t* error_p = jerry_api_create_error (JERRY_API_ERROR_TYPE, "error");
jerry_api_object_t* error_p = jerry_api_create_error (JERRY_API_ERROR_TYPE,
(jerry_api_char_t *) "error");
test_api_init_api_value_object (ret_val_p, error_p);
@@ -176,7 +177,7 @@ handler_construct (const jerry_api_object_t *function_obj_p,
JERRY_ASSERT (args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN);
JERRY_ASSERT (args_p[0].v_bool == true);
jerry_api_set_object_field_value (this_p->v_object, "value_field", &args_p[0]);
jerry_api_set_object_field_value (this_p->v_object, (jerry_api_char_t *) "value_field", &args_p[0]);
jerry_api_set_object_native_handle (this_p->v_object,
(uintptr_t) 0x0012345678abcdefull,
@@ -240,7 +241,7 @@ main (void)
jerry_api_value_t res, args[2];
char buffer[32];
is_ok = jerry_parse (test_source, strlen (test_source));
is_ok = jerry_parse ((jerry_api_char_t *)test_source, strlen (test_source));
JERRY_ASSERT (is_ok);
is_ok = (jerry_run () == JERRY_COMPLETION_CODE_OK);
@@ -249,14 +250,14 @@ main (void)
global_obj_p = jerry_api_get_global ();
// Get global.t
is_ok = jerry_api_get_object_field_value (global_obj_p, "t", &val_t);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *)"t", &val_t);
JERRY_ASSERT (is_ok
&& val_t.type == JERRY_API_DATA_TYPE_FLOAT64
&& val_t.v_float64 == 1.0);
jerry_api_release_value (&val_t);
// Get global.foo
is_ok = jerry_api_get_object_field_value (global_obj_p, "foo", &val_foo);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *)"foo", &val_foo);
JERRY_ASSERT (is_ok
&& val_foo.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -270,7 +271,7 @@ main (void)
jerry_api_release_value (&res);
// Get global.bar
is_ok = jerry_api_get_object_field_value (global_obj_p, "bar", &val_bar);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *)"bar", &val_bar);
JERRY_ASSERT (is_ok
&& val_bar.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -285,7 +286,7 @@ main (void)
// Set global.t = "abcd"
test_api_init_api_value_string (&args[0], "abcd");
is_ok = jerry_api_set_object_field_value (global_obj_p,
"t",
(jerry_api_char_t *)"t",
&args[0]);
JERRY_ASSERT (is_ok);
jerry_api_release_value (&args[0]);
@@ -296,13 +297,13 @@ main (void)
&& res.type == JERRY_API_DATA_TYPE_STRING);
sz = jerry_api_string_to_char_buffer (res.v_string, NULL, 0);
JERRY_ASSERT (sz == -5);
sz = jerry_api_string_to_char_buffer (res.v_string, buffer, -sz);
sz = jerry_api_string_to_char_buffer (res.v_string, (jerry_api_char_t *) buffer, -sz);
JERRY_ASSERT (sz == 5);
jerry_api_release_value (&res);
JERRY_ASSERT (!strcmp (buffer, "abcd"));
// Get global.A
is_ok = jerry_api_get_object_field_value (global_obj_p, "A", &val_A);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *)"A", &val_A);
JERRY_ASSERT (is_ok
&& val_A.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -310,7 +311,7 @@ main (void)
is_ok = jerry_api_is_constructor (val_A.v_object);
JERRY_ASSERT (is_ok);
is_ok = jerry_api_get_object_field_value (val_A.v_object,
"prototype",
(jerry_api_char_t *) "prototype",
&val_A_prototype);
JERRY_ASSERT (is_ok
&& val_A_prototype.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -318,26 +319,26 @@ main (void)
// Set A.prototype.foo = global.foo
is_ok = jerry_api_set_object_field_value (val_A_prototype.v_object,
"foo",
(jerry_api_char_t *) "foo",
&val_foo);
JERRY_ASSERT (is_ok);
jerry_api_release_value (&val_A_prototype);
jerry_api_release_value (&val_foo);
// Get global.a
is_ok = jerry_api_get_object_field_value (global_obj_p, "a", &val_a);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *) "a", &val_a);
JERRY_ASSERT (is_ok
&& val_a.type == JERRY_API_DATA_TYPE_OBJECT);
// Get a.t
is_ok = jerry_api_get_object_field_value (val_a.v_object, "t", &res);
is_ok = jerry_api_get_object_field_value (val_a.v_object, (jerry_api_char_t *) "t", &res);
JERRY_ASSERT (is_ok
&& res.type == JERRY_API_DATA_TYPE_FLOAT64
&& res.v_float64 == 12.0);
jerry_api_release_value (&res);
// Get a.foo
is_ok = jerry_api_get_object_field_value (val_a.v_object, "foo", &val_a_foo);
is_ok = jerry_api_get_object_field_value (val_a.v_object, (jerry_api_char_t *) "foo", &val_a_foo);
JERRY_ASSERT (is_ok
&& val_a_foo.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -359,14 +360,14 @@ main (void)
test_api_init_api_value_object (&val_external, external_func_p);
is_ok = jerry_api_set_object_field_value (global_obj_p,
"external",
(jerry_api_char_t *) "external",
&val_external);
JERRY_ASSERT (is_ok);
jerry_api_release_value (&val_external);
jerry_api_release_object (external_func_p);
// Call 'call_external' function that should call external function created above
is_ok = jerry_api_get_object_field_value (global_obj_p, "call_external", &val_call_external);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *) "call_external", &val_call_external);
JERRY_ASSERT (is_ok
&& val_call_external.type == JERRY_API_DATA_TYPE_OBJECT);
is_ok = jerry_api_call_function (val_call_external.v_object,
@@ -378,7 +379,7 @@ main (void)
&& res.type == JERRY_API_DATA_TYPE_STRING);
sz = jerry_api_string_to_char_buffer (res.v_string, NULL, 0);
JERRY_ASSERT (sz == -20);
sz = jerry_api_string_to_char_buffer (res.v_string, buffer, -sz);
sz = jerry_api_string_to_char_buffer (res.v_string, (jerry_api_char_t *) buffer, -sz);
JERRY_ASSERT (sz == 20);
jerry_api_release_value (&res);
JERRY_ASSERT (!strcmp (buffer, "string from handler"));
@@ -391,7 +392,7 @@ main (void)
test_api_init_api_value_object (&val_external_construct, external_construct_p);
is_ok = jerry_api_set_object_field_value (global_obj_p,
"external_construct",
(jerry_api_char_t *) "external_construct",
&val_external_construct);
JERRY_ASSERT (is_ok);
jerry_api_release_value (&val_external_construct);
@@ -403,7 +404,7 @@ main (void)
JERRY_ASSERT (is_ok
&& res.type == JERRY_API_DATA_TYPE_OBJECT);
is_ok = jerry_api_get_object_field_value (res.v_object,
"value_field",
(jerry_api_char_t *)"value_field",
&val_value_field);
// Get 'value_field' of constructed object
@@ -427,13 +428,13 @@ main (void)
test_api_init_api_value_object (&val_t, throw_test_handler_p);
is_ok = jerry_api_set_object_field_value (global_obj_p,
"throw_test",
(jerry_api_char_t *) "throw_test",
&val_t);
JERRY_ASSERT (is_ok);
jerry_api_release_value (&val_t);
jerry_api_release_object (throw_test_handler_p);
is_ok = jerry_api_get_object_field_value (global_obj_p, "call_throw_test", &val_t);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *) "call_throw_test", &val_t);
JERRY_ASSERT (is_ok
&& val_t.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -446,7 +447,7 @@ main (void)
jerry_api_release_value (&res);
// Test: Unhandled exception in called function
is_ok = jerry_api_get_object_field_value (global_obj_p, "throw_reference_error", &val_t);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *) "throw_reference_error", &val_t);
JERRY_ASSERT (is_ok
&& val_t.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -479,7 +480,7 @@ main (void)
jerry_api_release_object (obj_p);
// Test: Unhandled exception in function called, as constructor
is_ok = jerry_api_get_object_field_value (global_obj_p, "throw_reference_error", &val_t);
is_ok = jerry_api_get_object_field_value (global_obj_p, (jerry_api_char_t *) "throw_reference_error", &val_t);
JERRY_ASSERT (is_ok
&& val_t.type == JERRY_API_DATA_TYPE_OBJECT);
@@ -511,7 +512,7 @@ main (void)
// Test: eval
const char *eval_code_src_p = "(function () { return 123; })";
jerry_completion_code_t status = jerry_api_eval (eval_code_src_p,
jerry_completion_code_t status = jerry_api_eval ((jerry_api_char_t *) eval_code_src_p,
strlen (eval_code_src_p),
false,
true,
@@ -547,7 +548,7 @@ main (void)
magic_string_lengths);
const char *ms_code_src_p = "var global = {}; var console = [1]; var process = 1;";
is_ok = jerry_parse (ms_code_src_p, strlen (ms_code_src_p));
is_ok = jerry_parse ((jerry_api_char_t *) ms_code_src_p, strlen (ms_code_src_p));
JERRY_ASSERT (is_ok);
is_ok = (jerry_run () == JERRY_COMPLETION_CODE_OK);
+23 -23
View File
@@ -15,7 +15,7 @@
#include "ecma-helpers.h"
#include "lit-literal.h"
#include "lit-magic-strings.h"
#include "test-common.h"
// Iterations count
@@ -28,13 +28,13 @@
#define max_characters_in_string 256
static void
generate_string (ecma_char_t *str, ecma_length_t len)
generate_string (lit_utf8_byte_t *str, lit_utf8_size_t len)
{
static const ecma_char_t characters[] = "!@#$%^&*()_+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
static const ecma_length_t length = (ecma_length_t) (sizeof (characters) / sizeof (ecma_char_t) - 1);
for (ecma_length_t i = 0; i < len; ++i)
static const lit_utf8_byte_t bytes[] = "!@#$%^&*()_+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
static const lit_utf8_size_t length = (lit_utf8_size_t) (sizeof (bytes) - 1);
for (lit_utf8_size_t i = 0; i < len; ++i)
{
str[i] = characters[(unsigned long) rand () % length];
str[i] = bytes[(unsigned long) rand () % length];
}
}
@@ -60,10 +60,10 @@ main (int __attr_unused___ argc,
{
TEST_INIT ();
const ecma_char_t *ptrs[test_sub_iters];
const lit_utf8_byte_t *ptrs[test_sub_iters];
ecma_number_t numbers[test_sub_iters];
ecma_char_t strings[test_sub_iters][max_characters_in_string + 1];
ecma_length_t lengths[test_sub_iters];
lit_utf8_byte_t strings[test_sub_iters][max_characters_in_string + 1];
lit_utf8_size_t lengths[test_sub_iters];
mem_init ();
lit_init ();
@@ -72,17 +72,17 @@ main (int __attr_unused___ argc,
for (uint32_t i = 0; i < test_iters; i++)
{
memset (numbers, 0, sizeof (ecma_number_t) * test_sub_iters);
memset (lengths, 0, sizeof (ecma_length_t) * test_sub_iters);
memset (ptrs, 0, sizeof (ecma_char_t *) * test_sub_iters);
memset (lengths, 0, sizeof (lit_utf8_size_t) * test_sub_iters);
memset (ptrs, 0, sizeof (lit_utf8_byte_t *) * test_sub_iters);
for (uint32_t j = 0; j < test_sub_iters; j++)
{
int type = rand () % 3;
if (type == 0)
{
lengths[j] = (ecma_length_t) (rand () % max_characters_in_string + 1);
lengths[j] = (lit_utf8_size_t) (rand () % max_characters_in_string + 1);
generate_string (strings[j], lengths[j]);
lit_create_literal_from_charset (strings[j], lengths[j]);
lit_create_literal_from_utf8_string (strings[j], lengths[j]);
strings[j][lengths[j]] = '\0';
ptrs[j] = strings[j];
JERRY_ASSERT (ptrs[j]);
@@ -90,21 +90,21 @@ main (int __attr_unused___ argc,
else if (type == 1)
{
lit_magic_string_id_t msi = (lit_magic_string_id_t) (rand () % LIT_MAGIC_STRING__COUNT);
ptrs[j] = lit_get_magic_string_zt (msi);
ptrs[j] = lit_get_magic_string_utf8 (msi);
JERRY_ASSERT (ptrs[j]);
lengths[j] = (ecma_length_t) ecma_zt_string_length (ptrs[j]);
lit_create_literal_from_charset (ptrs[j], lengths[j]);
lengths[j] = (lit_utf8_size_t) lit_zt_utf8_string_size (ptrs[j]);
lit_create_literal_from_utf8_string (ptrs[j], lengths[j]);
}
else
{
ecma_number_t num = generate_number ();
lengths[j] = ecma_number_to_zt_string (num, strings[j], max_characters_in_string);
lengths[j] = ecma_number_to_utf8_string (num, strings[j], max_characters_in_string);
lit_create_literal_from_num (num);
}
}
// Add empty string
lit_create_literal_from_charset (NULL, 0);
lit_create_literal_from_utf8_string (NULL, 0);
for (uint32_t j = 0; j < test_sub_iters; j++)
{
@@ -112,10 +112,10 @@ main (int __attr_unused___ argc,
literal_t lit2;
if (ptrs[j])
{
lit1 = lit_find_or_create_literal_from_charset (ptrs[j], lengths[j]);
lit2 = lit_find_literal_by_charset (ptrs[j], lengths[j]);
JERRY_ASSERT (lit_literal_equal_zt (lit1, ptrs[j]));
JERRY_ASSERT (lit_literal_equal_type_zt (lit2, ptrs[j]));
lit1 = lit_find_or_create_literal_from_utf8_string (ptrs[j], lengths[j]);
lit2 = lit_find_literal_by_utf8_string (ptrs[j], lengths[j]);
JERRY_ASSERT (lit_literal_equal_utf8 (lit1, ptrs[j], lengths[j]));
JERRY_ASSERT (lit_literal_equal_type_utf8 (lit2, ptrs[j], lengths[j]));
}
else
{
@@ -131,7 +131,7 @@ main (int __attr_unused___ argc,
}
// Check empty string exists
JERRY_ASSERT (lit_find_literal_by_charset (NULL, 0));
JERRY_ASSERT (lit_find_literal_by_utf8_string (NULL, 0));
lit_storage.cleanup ();
JERRY_ASSERT (lit_storage.get_first () == NULL);
+15 -15
View File
@@ -27,19 +27,19 @@ main (int __attr_unused___ argc,
{
TEST_INIT ();
const ecma_char_t* zt_strings[] =
const lit_utf8_byte_t *strings[] =
{
(const ecma_char_t*) "1",
(const ecma_char_t*) "0.5",
(const ecma_char_t*) "12345",
(const ecma_char_t*) "12345.123",
(const ecma_char_t*) "1e-45",
(const ecma_char_t*) "-2.5e+38",
(const ecma_char_t*) "NaN",
(const ecma_char_t*) "Infinity",
(const ecma_char_t*) "-Infinity",
(const ecma_char_t*) "0",
(const ecma_char_t*) "0",
(const lit_utf8_byte_t *) "1",
(const lit_utf8_byte_t *) "0.5",
(const lit_utf8_byte_t *) "12345",
(const lit_utf8_byte_t *) "12345.123",
(const lit_utf8_byte_t *) "1e-45",
(const lit_utf8_byte_t *) "-2.5e+38",
(const lit_utf8_byte_t *) "NaN",
(const lit_utf8_byte_t *) "Infinity",
(const lit_utf8_byte_t *) "-Infinity",
(const lit_utf8_byte_t *) "0",
(const lit_utf8_byte_t *) "0",
};
const ecma_number_t nums[] =
@@ -61,11 +61,11 @@ main (int __attr_unused___ argc,
i < sizeof (nums) / sizeof (nums[0]);
i++)
{
ecma_char_t zt_str[64];
lit_utf8_byte_t str[64];
ecma_number_to_zt_string (nums[i], zt_str, sizeof (zt_str));
lit_utf8_size_t str_size = ecma_number_to_utf8_string (nums[i], str, sizeof (str));
if (strcmp ((char*)zt_str, (char*)zt_strings[i]) != 0)
if (strncmp ((char *) str, (char *) strings[i], str_size) != 0)
{
return 1;
}
+2 -2
View File
@@ -81,7 +81,7 @@ main (int __attr_unused___ argc,
serializer_init ();
parser_set_show_opcodes (true);
is_syntax_correct = parser_parse_script (program1, strlen (program1), &opcodes_p);
is_syntax_correct = parser_parse_script ((jerry_api_char_t *) program1, strlen (program1), &opcodes_p);
JERRY_ASSERT (is_syntax_correct && opcodes_p != NULL);
@@ -107,7 +107,7 @@ main (int __attr_unused___ argc,
serializer_init ();
parser_set_show_opcodes (true);
is_syntax_correct = parser_parse_script (program2, strlen (program2), &opcodes_p);
is_syntax_correct = parser_parse_script ((jerry_api_char_t *) program2, strlen (program2), &opcodes_p);
JERRY_ASSERT (!is_syntax_correct && opcodes_p == NULL);
+20 -20
View File
@@ -27,26 +27,26 @@ main (int __attr_unused___ argc,
{
TEST_INIT ();
const ecma_char_t* zt_strings[] =
const jerry_api_char_t *strings[] =
{
(const ecma_char_t*) "1",
(const ecma_char_t*) "0.5",
(const ecma_char_t*) "12345",
(const ecma_char_t*) "1e-45",
(const ecma_char_t*) "-2.5e+38",
(const ecma_char_t*) "-2.5e38",
(const ecma_char_t*) "- 2.5e+38",
(const ecma_char_t*) "-2 .5e+38",
(const ecma_char_t*) "-2. 5e+38",
(const ecma_char_t*) "-2.5e+ 38",
(const ecma_char_t*) "-2.5 e+38",
(const ecma_char_t*) "-2.5e +38",
(const ecma_char_t*) "NaN",
(const ecma_char_t*) "abc",
(const ecma_char_t*) " Infinity ",
(const ecma_char_t*) "-Infinity",
(const ecma_char_t*) "0",
(const ecma_char_t*) "0",
(const jerry_api_char_t *) "1",
(const jerry_api_char_t *) "0.5",
(const jerry_api_char_t *) "12345",
(const jerry_api_char_t *) "1e-45",
(const jerry_api_char_t *) "-2.5e+38",
(const jerry_api_char_t *) "-2.5e38",
(const jerry_api_char_t *) "- 2.5e+38",
(const jerry_api_char_t *) "-2 .5e+38",
(const jerry_api_char_t *) "-2. 5e+38",
(const jerry_api_char_t *) "-2.5e+ 38",
(const jerry_api_char_t *) "-2.5 e+38",
(const jerry_api_char_t *) "-2.5e +38",
(const jerry_api_char_t *) "NaN",
(const jerry_api_char_t *) "abc",
(const jerry_api_char_t *) " Infinity ",
(const jerry_api_char_t *) "-Infinity",
(const jerry_api_char_t *) "0",
(const jerry_api_char_t *) "0",
};
const ecma_number_t nums[] =
@@ -75,7 +75,7 @@ main (int __attr_unused___ argc,
i < sizeof (nums) / sizeof (nums[0]);
i++)
{
ecma_number_t num = ecma_zt_string_to_number (zt_strings[i]);
ecma_number_t num = ecma_utf8_string_to_number (strings[i], lit_zt_utf8_string_size (strings[i]));
if (num != nums[i]
&& (!ecma_number_is_nan (num)
+94
View File
@@ -0,0 +1,94 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* 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.
*/
#include "ecma-helpers.h"
#include "lit-strings.h"
#include "test-common.h"
// Iterations count
#define test_iters 64
// Subiterations count
#define test_sub_iters 64
int
main (int __attr_unused___ argc,
char __attr_unused___ **argv)
{
TEST_INIT ();
mem_init ();
/* test lit_is_utf8_string_valid */
/* Overlong-encoded code point */
lit_utf8_byte_t invalid_utf8_string_1[] = {0xC0, 0x82};
JERRY_ASSERT (!lit_is_utf8_string_valid (invalid_utf8_string_1, sizeof (invalid_utf8_string_1)));
/* Overlong-encoded code point */
lit_utf8_byte_t invalid_utf8_string_2[] = {0xE0, 0x80, 0x81};
JERRY_ASSERT (!lit_is_utf8_string_valid (invalid_utf8_string_2, sizeof (invalid_utf8_string_2)));
/* Pair of surrogates: 0xD901 0xDFF0 which encode Unicode character 0x507F0 */
lit_utf8_byte_t invalid_utf8_string_3[] = {0xED, 0xA4, 0x81, 0xED, 0xBF, 0xB0};
JERRY_ASSERT (!lit_is_utf8_string_valid (invalid_utf8_string_3, sizeof (invalid_utf8_string_3)));
/* Isolated high surrogate 0xD901 */
lit_utf8_byte_t valid_utf8_string_1[] = {0xED, 0xA4, 0x81};
JERRY_ASSERT (lit_is_utf8_string_valid (valid_utf8_string_1, sizeof (valid_utf8_string_1)));
/* 4-byte long utf-8 character - Unicode character 0x507F0 */
lit_utf8_byte_t valid_utf8_string_2[] = {0xF1, 0x90, 0x9F, 0xB0};
JERRY_ASSERT (lit_is_utf8_string_valid (valid_utf8_string_2, sizeof (valid_utf8_string_2)));
/* test lit_read_code_point_from_utf8 */
lit_utf8_byte_t buf[] = {0xF0, 0x90, 0x8D, 0x88};
lit_code_point_t code_point;
lit_utf8_size_t bytes_count = lit_read_code_point_from_utf8 (buf, sizeof (buf), &code_point);
JERRY_ASSERT (bytes_count == 4);
JERRY_ASSERT (code_point == 0x10348);
/* test lit_code_unit_to_utf8 */
lit_utf8_byte_t res_buf[3];
lit_utf8_size_t res_size;
res_size = lit_code_unit_to_utf8 (0x73, res_buf);
JERRY_ASSERT (res_size == 1);
JERRY_ASSERT (res_buf[0] == 0x73);
res_size = lit_code_unit_to_utf8 (0x41A, res_buf);
JERRY_ASSERT (res_size == 2);
JERRY_ASSERT (res_buf[0] == 0xD0);
JERRY_ASSERT (res_buf[1] == 0x9A);
res_size = lit_code_unit_to_utf8 (0xD7FF, res_buf);
JERRY_ASSERT (res_size == 3);
JERRY_ASSERT (res_buf[0] == 0xED);
JERRY_ASSERT (res_buf[1] == 0x9F);
JERRY_ASSERT (res_buf[2] == 0xBF);
/* test lit_utf8_iterator */
lit_utf8_byte_t bytes[] = {0xF0, 0x90, 0x8D, 0x88};
lit_utf8_iterator_t iter = lit_utf8_iterator_create (bytes, sizeof (bytes));
ecma_char_t code_unit = lit_utf8_iterator_read_code_unit_and_increment (&iter);
JERRY_ASSERT (!lit_utf8_iterator_reached_buffer_end (&iter));
JERRY_ASSERT (code_unit == 0xD800);
code_unit = lit_utf8_iterator_read_code_unit_and_increment (&iter);
JERRY_ASSERT (lit_utf8_iterator_reached_buffer_end (&iter));
JERRY_ASSERT (code_unit == 0xDF48);
mem_finalize (true);
return 0;
}