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:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user